Fix antipatern of create/write in loop
issue3516 review6891002
This commit is contained in:
1 parent
a6225e3fc6
commit
82be44e56e
3 files changed
+14
-7
No files matched your search
+4
-2
@@ -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):
|
||||
|
||||
+5
-3
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user