From fb5ad2fa18c2f565b98d0083ac67e5c4848df78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Thu, 11 Aug 2011 16:34:36 +0200 Subject: [PATCH] Use function name in workflow instead of python code --- inventory.py | 14 +++-- inventory.xml | 9 ++-- shipment.py | 141 ++++++++++++++++++++------------------------------ shipment.xml | 84 +++++++++++------------------- 4 files changed, 96 insertions(+), 152 deletions(-) diff --git a/inventory.py b/inventory.py index 0af41ca73a..80d02bf754 100644 --- a/inventory.py +++ b/inventory.py @@ -78,27 +78,25 @@ class Inventory(ModelWorkflow, ModelSQL, ModelView): return location_ids[0] return False - def set_state_draft(self, inventory_id): - self.write(inventory_id, { + def wkf_draft(self, inventory): + self.write(inventory.id, { 'state': 'draft', }) - def set_state_cancel(self, inventory_id): + def wkf_cancel(self, inventory): line_obj = Pool().get("stock.inventory.line") - inventory = self.browse(inventory_id) line_obj.cancel_move(inventory.lines) - self.write(inventory_id, { + self.write(inventory.id, { 'state': 'cancel', }) - def set_state_done(self, inventory_id): + def wkf_done(self, inventory): date_obj = Pool().get('ir.date') line_obj = Pool().get('stock.inventory.line') - inventory = self.browse(inventory_id) for line in inventory.lines: line_obj.create_move(line) - self.write(inventory_id, { + self.write(inventory.id, { 'state': 'done', }) diff --git a/inventory.xml b/inventory.xml index 5c11017de0..d119153a5c 100644 --- a/inventory.xml +++ b/inventory.xml @@ -157,23 +157,20 @@ this repository contains the full copyright notices and license terms. --> True - function - set_state_draft() + wkf_draft Draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done diff --git a/shipment.py b/shipment.py index 87c5e1efdd..ea56bebc1e 100644 --- a/shipment.py +++ b/shipment.py @@ -250,53 +250,50 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView): 'moves': value, }) - def set_state_done(self, shipment_id): + def wkf_done(self, shipment): move_obj = Pool().get('stock.move') date_obj = Pool().get('ir.date') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.inventory_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id,{ + self.write(shipment.id,{ 'state': 'done', 'effective_date': date_obj.today(), }) - def set_state_cancel(self, shipment_id): + def wkf_cancel(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves if m.state != 'cancel'] + [m.id for m in shipment.inventory_moves if m.state != 'cancel'], { 'state': 'cancel', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'cancel', }) - def set_state_received(self, shipment_id): + def wkf_received(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'received' }) + self.create_inventory_moves(shipment.id) - def set_state_draft(self, shipment_id): + def wkf_draft(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves if m.state != 'draft'], { 'state': 'draft', }) move_obj.delete([m.id for m in shipment.inventory_moves]) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'draft', }) @@ -450,67 +447,61 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView): config.shipment_in_return_sequence.id) return super(ShipmentInReturn, self).create(values) - def set_state_draft(self, shipment_id): + def wkf_draft(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'draft', }) move_obj.write([m.id for m in shipment.moves if m.state != 'draft'], { 'state': 'draft', }) - def set_state_waiting(self, shipment_id): + def wkf_waiting(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves if m.state not in ('cancel', 'draft')], { 'state': 'draft', 'planned_date': shipment.planned_date, }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'waiting', }) - def set_state_assigned(self, shipment_id): - self.write(shipment_id, { + def wkf_assigned(self, shipment): + self.write(shipment.id, { 'state': 'assigned', }) - def set_state_done(self, shipment_id): + def wkf_done(self, shipment): move_obj = Pool().get('stock.move') date_obj = Pool().get('ir.date') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'done', 'effective_date': date_obj.today(), }) - def set_state_cancel(self, shipment_id): + def wkf_cancel(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves if m.state != 'cancel'], { 'state': 'cancel', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'cancel', }) - def assign_try(self, shipment_id): + def wkf_assign_try(self, shipment): pool = Pool() product_obj = pool.get('product.product') uom_obj = pool.get('product.uom') date_obj = pool.get('ir.date') move_obj = pool.get('stock.move') - shipment = self.browse(shipment_id) - Transaction().cursor.lock(move_obj._table) location_ids = [m.from_location.id for m in shipment.moves] @@ -539,8 +530,7 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView): }) return True - def assign_force(self, shipment_id): - shipment = self.browse(shipment_id) + def wkf_assign_force(self, shipment): move_obj = Pool().get('stock.move') move_obj.write([m.id for m in shipment.moves], { 'state': 'assigned', @@ -779,15 +769,14 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): 'moves': value, }) - def set_state_assigned(self, shipment_id): - self.write(shipment_id, { + def wkf_assigned(self, shipment): + self.write(shipment.id, { 'state': 'assigned', }) - def set_state_draft(self, shipment_id): + def wkf_draft(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'draft', }) move_obj.write([m.id for m in @@ -796,29 +785,27 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): 'state': 'draft', }) - def set_state_done(self, shipment_id): + def wkf_done(self, shipment): move_obj = Pool().get('stock.move') date_obj = Pool().get('ir.date') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.outgoing_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'done', 'effective_date': date_obj.today(), }) - def set_state_packed(self, shipment_id): + def wkf_packed(self, shipment): move_obj = Pool().get('stock.move') uom_obj = Pool().get('product.uom') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.inventory_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'packed', }) # Sum all outgoing quantities @@ -866,7 +853,6 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): }) #Re-read the shipment and remove exceeding quantities - shipment = self.browse(shipment_id) for move in shipment.outgoing_moves: if move.state == 'cancel': continue if outgoing_qty.get(move.product.id, 0.0) > 0.0: @@ -885,27 +871,25 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): 'state': 'assigned', }) - def set_state_cancel(self, shipment_id): + def wkf_cancel(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.outgoing_moves + shipment.inventory_moves if m.state != 'cancel'], { 'state': 'cancel', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'cancel', }) - def set_state_waiting(self, shipment_id): + def wkf_waiting(self, shipment): """ Complete inventory moves to match the products and quantities that are in the outgoing moves. """ move_obj = Pool().get('stock.move') uom_obj = Pool().get('product.uom') - shipment = self.browse(shipment_id) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'waiting', }) @@ -916,7 +900,7 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): move_obj.delete([x.id for x in shipment.inventory_moves]) # Re-Browse because moves have been deleted - shipment = self.browse(shipment_id) + shipment = self.browse(shipment.id) for move in shipment.outgoing_moves: if move.state in ('cancel', 'done'): @@ -966,13 +950,11 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView): uom_index[target_uom]) return res - def assign_try(self, shipment_id): + def wkf_assign_try(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) return move_obj.assign_try(shipment.inventory_moves) - def assign_force(self, shipment_id): - shipment = self.browse(shipment_id) + def wkf_assign_force(self, shipment): move_obj = Pool().get('stock.move') move_obj.write([m.id for m in shipment.inventory_moves], { 'state': 'assigned', @@ -1233,52 +1215,49 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView): def button_draft(self, ids): self.workflow_trigger_create(ids) - def set_state_done(self, shipment_id): + def wkf_done(self, shipment): move_obj = Pool().get('stock.move') date_obj = Pool().get('ir.date') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.inventory_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id,{ + self.write(shipment.id,{ 'state': 'done', 'effective_date': date_obj.today(), }) - def set_state_cancel(self, shipment_id): + def wkf_cancel(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves + shipment.inventory_moves if m.state != 'cancel'], { 'state': 'cancel', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'cancel', }) - def set_state_received(self, shipment_id): + def wkf_received(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves if m.state not in ('done', 'cancel')], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'received' }) + self.create_inventory_moves(shipment.id) - def set_state_draft(self, shipment_id): + def wkf_draft(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.incoming_moves if m.state != 'draft'], { 'state': 'draft', }) move_obj.delete([m.id for m in shipment.inventory_moves]) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'draft', }) @@ -1505,64 +1484,58 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView): config.shipment_internal_sequence.id) return super(ShipmentInternal, self).create(values) - def set_state_draft(self, shipment_id): + def wkf_draft(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'draft', }) move_obj.write([m.id for m in shipment.moves], { 'state': 'draft', }) - def set_state_waiting(self, shipment_id): + def wkf_waiting(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves], { 'from_location': shipment.from_location.id, 'to_location': shipment.to_location.id, 'state': 'draft', 'planned_date': shipment.planned_date, }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'waiting', }) - def set_state_assigned(self, shipment_id): - self.write(shipment_id, { + def wkf_assigned(self, shipment): + self.write(shipment.id, { 'state': 'assigned', }) - def set_state_done(self, shipment_id): + def wkf_done(self, shipment): move_obj = Pool().get('stock.move') date_obj = Pool().get('ir.date') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves], { 'state': 'done', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'done', 'effective_date': date_obj.today(), }) - def set_state_cancel(self, shipment_id): + def wkf_cancel(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) move_obj.write([m.id for m in shipment.moves], { 'state': 'cancel', }) - self.write(shipment_id, { + self.write(shipment.id, { 'state': 'cancel', }) - def assign_try(self, shipment_id): + def wkf_assign_try(self, shipment): move_obj = Pool().get('stock.move') - shipment = self.browse(shipment_id) return move_obj.assign_try(shipment.moves) - def assign_force(self, shipment_id): - shipment = self.browse(shipment_id) + def wkf_assign_force(self, shipment): move_obj = Pool().get('stock.move') move_obj.write([m.id for m in shipment.moves], { 'state': 'assigned', diff --git a/shipment.xml b/shipment.xml index 6b9f97f8ad..722a1f0bb0 100644 --- a/shipment.xml +++ b/shipment.xml @@ -753,29 +753,25 @@ this repository contains the full copyright notices and license terms. --> True - function - set_state_draft() + wkf_draft Draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done Received - function - set_state_received() create_inventory_moves() + wkf_received True Draft - function - set_state_draft() + wkf_draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done Waiting - function - set_state_waiting() + wkf_waiting Assigned - function - set_state_assigned() + wkf_assigned Packed - function - set_state_packed() + wkf_packed assign - assign_try() + wkf_assign_try @@ -887,7 +877,7 @@ this repository contains the full copyright notices and license terms. --> force_assign - assign_force() + wkf_assign_force @@ -1026,35 +1016,30 @@ this repository contains the full copyright notices and license terms. --> True - function - set_state_draft() + wkf_draft Draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done Waiting - function - set_state_waiting() + wkf_waiting Assigned - function - set_state_assigned() + wkf_assigned assign - assign_try() + wkf_assign_try @@ -1099,7 +1084,7 @@ this repository contains the full copyright notices and license terms. --> force_assign - assign_force() + wkf_assign_force @@ -1137,29 +1122,25 @@ this repository contains the full copyright notices and license terms. --> True - function - set_state_draft() + wkf_draft Draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done Received - function - set_state_received() create_inventory_moves() + wkf_received True - function - set_state_draft() + wkf_draft Draft True Canceled - function - set_state_cancel() + wkf_cancel True Done - function - set_state_done() + wkf_done Waiting - function - set_state_waiting() + wkf_waiting Assigned - function - set_state_assigned() + wkf_assigned assign - assign_try() + wkf_assign_try @@ -1271,7 +1247,7 @@ this repository contains the full copyright notices and license terms. --> force_assign - assign_force() + wkf_assign_force