From e2f5b9f05f38d0bf85337317f93cfaafacf36c2e Mon Sep 17 00:00:00 2001 From: Guillem Barba Date: Sun, 13 Dec 2015 15:13:10 +0100 Subject: [PATCH] Optimize ShipmentOut._set_move_planned_date to call once Move.write issue5156 review24631002 --- shipment.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/shipment.py b/shipment.py index 9a62f3ba80..79672e1e5a 100644 --- a/shipment.py +++ b/shipment.py @@ -1217,18 +1217,26 @@ class ShipmentOut(Workflow, ModelSQL, ModelView): Set planned date of moves for the shipments ''' Move = Pool().get('stock.move') + to_write = [] for shipment in shipments: outgoing_date, inventory_date = shipment._move_planned_date - Move.write([x for x in shipment.outgoing_moves + out_moves_to_write = [x for x in shipment.outgoing_moves if (x.state not in ('assigned', 'done', 'cancel') - and x.planned_date != outgoing_date)], { - 'planned_date': outgoing_date, - }) - Move.write([x for x in shipment.inventory_moves + and x.planned_date != outgoing_date)] + if out_moves_to_write: + to_write.extend((out_moves_to_write, { + 'planned_date': outgoing_date, + })) + + inv_moves_to_write = [x for x in shipment.inventory_moves if (x.state not in ('assigned', 'done', 'cancel') - and x.planned_date != inventory_date)], { - 'planned_date': inventory_date, - }) + and x.planned_date != inventory_date)] + if inv_moves_to_write: + to_write.extend((inv_moves_to_write, { + 'planned_date': inventory_date, + })) + if to_write: + Move.write(*to_write) @classmethod def create(cls, vlist):