From 69b67f1c0fbef67b0ac9a75c24a741f338a57734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 25 Mar 2012 00:18:12 +0100 Subject: [PATCH] Simplify workflow engine review256001 --- setup.py | 4 ++-- stock.py | 20 ++++++++++--------- tests/scenario_purchase_shipment_cost.rst | 8 +++----- ...chase_shipment_cost_with_account_stock.rst | 8 +++----- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/setup.py b/setup.py index 986600bd8d..45e255457e 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ minor_version = int(minor_version) requires = [] for dep in info.get('depends', []): - if not re.match(r'(ir|res|workflow|webdav)(\W|$)', dep): + if not re.match(r'(ir|res|webdav)(\W|$)', dep): requires.append('trytond_%s >= %s.%s, < %s.%s' % (dep, major_version, minor_version, major_version, minor_version + 1)) @@ -21,7 +21,7 @@ requires.append('trytond >= %s.%s, < %s.%s' % extras_require = {} for dep in info.get('extras_depend', []): - if not re.match(r'(ir|res|workflow|webdav)(\W|$)', dep): + if not re.match(r'(ir|res|webdav)(\W|$)', dep): extras_require[dep] = ('trytond_%s >= %s.%s, < %s.%s' % (dep, major_version, minor_version, major_version, minor_version + 1)) diff --git a/stock.py b/stock.py index a0a2982151..a64722b58d 100644 --- a/stock.py +++ b/stock.py @@ -4,7 +4,7 @@ import copy from decimal import Decimal, ROUND_DOWN, ROUND_HALF_EVEN from operator import itemgetter -from trytond.model import Model, fields +from trytond.model import Model, ModelView, Workflow, fields from trytond.pyson import Eval, Bool from trytond.pool import Pool from trytond.transaction import Transaction @@ -153,15 +153,17 @@ class ShipmentIn(Model): 'unit_shipment_cost': cost['unit_shipment_cost'], }) - def wkf_received(self, shipment): + @ModelView.button + @Workflow.transition('received') + def receive(self, ids): carrier_obj = Pool().get('carrier') - - if shipment.carrier: - allocation_method = shipment.carrier.carrier_cost_allocation_method - else: - allocation_method = carrier_obj.default_carrier_cost_method() - getattr(self, 'allocate_cost_by_%s' % allocation_method)(shipment) - super(ShipmentIn, self).wkf_received(shipment) + for shipment in self.browse(ids): + if shipment.carrier: + allocation_method = shipment.carrier.carrier_cost_allocation_method + else: + allocation_method = carrier_obj.default_carrier_cost_method() + getattr(self, 'allocate_cost_by_%s' % allocation_method)(shipment) + super(ShipmentIn, self).receive(ids) ShipmentIn() diff --git a/tests/scenario_purchase_shipment_cost.rst b/tests/scenario_purchase_shipment_cost.rst index 9b3d7dcece..26aab5a089 100644 --- a/tests/scenario_purchase_shipment_cost.rst +++ b/tests/scenario_purchase_shipment_cost.rst @@ -25,7 +25,7 @@ Install purchase_shipment_cost:: >>> modules = Module.find([ ... ('name', '=', 'purchase_shipment_cost'), ... ]) - >>> Module.button_install([x.id for x in modules], config.context) + >>> Module.install([x.id for x in modules], config.context) >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: @@ -122,8 +122,7 @@ Receive a single product line:: >>> shipment.cost_currency == currency True >>> shipment.save() - >>> ShipmentIn.workflow_trigger_validate(shipment.id, 'received', - ... config.context) + >>> ShipmentIn.receive([shipment.id], config.context) >>> shipment.reload() >>> shipment.state u'received' @@ -146,8 +145,7 @@ Receive many product lines:: >>> shipment.cost == Decimal('3') True >>> shipment.save() - >>> ShipmentIn.workflow_trigger_validate(shipment.id, 'received', - ... config.context) + >>> ShipmentIn.receive([shipment.id], config.context) >>> shipment.reload() >>> shipment.state u'received' diff --git a/tests/scenario_purchase_shipment_cost_with_account_stock.rst b/tests/scenario_purchase_shipment_cost_with_account_stock.rst index 57615d1156..3fafc763a7 100644 --- a/tests/scenario_purchase_shipment_cost_with_account_stock.rst +++ b/tests/scenario_purchase_shipment_cost_with_account_stock.rst @@ -26,7 +26,7 @@ Install purchase_shipment_cost:: ... ('name', 'in', ['purchase_shipment_cost', ... 'account_stock_continental']), ... ]) - >>> Module.button_install([x.id for x in modules], config.context) + >>> Module.install([x.id for x in modules], config.context) >>> Wizard('ir.module.module.install_upgrade').execute('upgrade') Create company:: @@ -201,8 +201,7 @@ Receive a single product line:: >>> shipment.cost_currency == currency True >>> shipment.save() - >>> ShipmentIn.workflow_trigger_validate(shipment.id, 'received', - ... config.context) + >>> ShipmentIn.receive([shipment.id], config.context) >>> shipment.reload() >>> shipment.state u'received' @@ -239,8 +238,7 @@ Receive many product lines:: >>> shipment.cost == Decimal('3') True >>> shipment.save() - >>> ShipmentIn.workflow_trigger_validate(shipment.id, 'received', - ... config.context) + >>> ShipmentIn.receive([shipment.id], config.context) >>> shipment.reload() >>> shipment.state u'received'