From 82be44e56e2e57c64e6495bc6e9b1dc375e30ab9 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 23 Jun 2016 09:40:00 +0200 Subject: [PATCH] Fix antipatern of create/write in loop issue3516 review6891002 --- inventory.py | 6 ++++-- location.py | 8 +++++--- move.py | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/inventory.py b/inventory.py index 222045f454..f1cb8eada0 100644 --- a/inventory.py +++ b/inventory.py @@ -201,7 +201,7 @@ class Inventory(Workflow, ModelSQL, ModelView): Product = pool.get('product.product') grouping = cls.grouping() - to_create = [] + to_create, to_write = [], [] for inventory in inventories: # Compute product quantities if fill: @@ -235,7 +235,7 @@ class Inventory(Workflow, ModelSQL, ModelView): quantity = 0.0 values = line.update_values4complete(quantity) if values: - Line.write([line], values) + to_write.extend(([line], values)) if not fill: continue @@ -254,6 +254,8 @@ class Inventory(Workflow, ModelSQL, ModelView): to_create.append(values) if to_create: Line.create(to_create) + if to_write: + Line.write(*to_write) class InventoryLine(ModelSQL, ModelView): diff --git a/location.py b/location.py index e24d2c5355..dac09c8eb7 100644 --- a/location.py +++ b/location.py @@ -296,6 +296,7 @@ class Location(ModelSQL, ModelView): Set the parent of child location of warehouse if not set ''' to_update = set() + to_save = [] for location in locations: if location.type == 'warehouse': if not location.input_location.parent: @@ -305,10 +306,11 @@ class Location(ModelSQL, ModelView): if not location.storage_location.parent: to_update.add(location.storage_location) if to_update: - cls.write(list(to_update), { - 'parent': location.id, - }) + for child_location in to_update: + child_location.parent = location + to_save.append(child_location) to_update.clear() + cls.save(to_save) @classmethod def create(cls, vlist): diff --git a/move.py b/move.py index 6dec253599..9b04840705 100644 --- a/move.py +++ b/move.py @@ -697,6 +697,7 @@ class Move(Workflow, ModelSQL, ModelView): super(Move, cls).write(*args) + to_write = [] actions = iter(args) for moves, values in zip(actions, actions): if any(f not in cls._allow_modify_closed_period for f in values): @@ -707,9 +708,11 @@ class Move(Workflow, ModelSQL, ModelView): if (internal_quantity != move.internal_quantity and internal_quantity != values.get('internal_quantity')): - cls.write([move], { + to_write.extend(([move], { 'internal_quantity': internal_quantity, - }) + })) + if to_write: + cls.write(*to_write) @classmethod def delete(cls, moves):