Adapt to latest patched version of stock module
This commit is contained in:
parent
19f177b653
commit
2dd1d89734
|
@ -1,2 +1,4 @@
|
||||||
|
* Adapt to latest patched version of stock module
|
||||||
|
|
||||||
Version 3.4.0 - 2015-06-08
|
Version 3.4.0 - 2015-06-08
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|
56
stock.py
56
stock.py
|
@ -412,9 +412,9 @@ class Inventory:
|
||||||
super(Inventory, cls).complete_lines(inventories)
|
super(Inventory, cls).complete_lines(inventories)
|
||||||
|
|
||||||
grouping = cls.grouping()
|
grouping = cls.grouping()
|
||||||
|
|
||||||
to_create = []
|
to_create = []
|
||||||
for inventory in inventories:
|
for inventory in inventories:
|
||||||
|
# Compute product second quantities
|
||||||
with Transaction().set_context(
|
with Transaction().set_context(
|
||||||
stock_date_end=inventory.date,
|
stock_date_end=inventory.date,
|
||||||
second_uom=True):
|
second_uom=True):
|
||||||
|
@ -422,50 +422,29 @@ class Inventory:
|
||||||
[inventory.location.id], grouping=grouping)
|
[inventory.location.id], grouping=grouping)
|
||||||
|
|
||||||
# Index some data
|
# Index some data
|
||||||
product2uom = {}
|
|
||||||
product2second_uom = {}
|
|
||||||
product2type = {}
|
product2type = {}
|
||||||
product2consumable = {}
|
product2consumable = {}
|
||||||
for product in Product.browse([line[1] for line in pbl]):
|
for product in Product.browse([line[1] for line in pbl]):
|
||||||
if not product.use_second_uom:
|
if not product.use_second_uom:
|
||||||
continue
|
continue
|
||||||
product2uom[product.id] = product.default_uom.id
|
|
||||||
product2second_uom[product.id] = product.second_uom.id
|
|
||||||
product2type[product.id] = product.type
|
product2type[product.id] = product.type
|
||||||
product2consumable[product.id] = product.consumable
|
product2consumable[product.id] = product.consumable
|
||||||
|
|
||||||
product_second_qty = {}
|
|
||||||
for key, second_qty in pbl.iteritems():
|
|
||||||
if key[1] not in product2second_uom:
|
|
||||||
continue
|
|
||||||
product_second_qty[tuple(key[1:])] = (
|
|
||||||
second_qty,
|
|
||||||
product2second_uom[key[1]],
|
|
||||||
product2uom[key[1]])
|
|
||||||
|
|
||||||
# Update existing lines
|
# Update existing lines
|
||||||
to_write = []
|
to_write = []
|
||||||
for line in inventory.lines:
|
for line in inventory.lines:
|
||||||
if not line.product.use_second_uom:
|
if not line.product.use_second_uom:
|
||||||
continue
|
continue
|
||||||
key = tuple([int(x) if x != None else x
|
key = (inventory.location.id,) + line.unique_key
|
||||||
for x in line.unique_key])
|
if key in pbl:
|
||||||
if key in product_second_qty:
|
second_qty = pbl.pop(key)
|
||||||
second_qty, second_uom_id, _ = (
|
|
||||||
product_second_qty.pop(key))
|
|
||||||
elif line.product.id in product2second_uom:
|
|
||||||
second_qty = 0.0
|
|
||||||
second_uom_id = product2second_uom[line.product.id]
|
|
||||||
else:
|
else:
|
||||||
second_qty = 0.0
|
second_qty = 0.0
|
||||||
second_uom_id = line.product.second_uom.id
|
if (line.second_quantity == line.second_expected_quantity
|
||||||
if ((line.second_quantity == line.second_expected_quantity
|
== second_qty):
|
||||||
== second_qty)
|
|
||||||
and line.second_uom.id == second_uom_id):
|
|
||||||
continue
|
continue
|
||||||
values = {
|
values = {
|
||||||
'second_expected_quantity': second_qty,
|
'second_expected_quantity': second_qty,
|
||||||
'second_uom': second_uom_id,
|
|
||||||
}
|
}
|
||||||
if line.second_quantity == line.second_expected_quantity:
|
if line.second_quantity == line.second_expected_quantity:
|
||||||
values['second_quantity'] = max(second_qty, 0.0)
|
values['second_quantity'] = max(second_qty, 0.0)
|
||||||
|
@ -474,20 +453,18 @@ class Inventory:
|
||||||
Line.write(*to_write)
|
Line.write(*to_write)
|
||||||
|
|
||||||
# Create lines if needed
|
# Create lines if needed
|
||||||
for key in product_second_qty:
|
for key, second_qty in pbl.iteritems():
|
||||||
product_id = key[0]
|
product_id = key[grouping.index('product') + 1]
|
||||||
|
if not second_qty:
|
||||||
|
continue
|
||||||
if (product2type[product_id] != 'goods'
|
if (product2type[product_id] != 'goods'
|
||||||
or product2consumable[product_id]):
|
or product2consumable[product_id]):
|
||||||
continue
|
continue
|
||||||
second_qty, second_uom_id, uom_id = product_second_qty[key]
|
|
||||||
if not second_qty:
|
values = Line.create_values4complete(inventory, 0.)
|
||||||
continue
|
for i, fname in enumerate(grouping, 1):
|
||||||
kwargs = dict((f, key[i])
|
values[fname] = key[i]
|
||||||
for i, f in enumerate(grouping[1:], 1))
|
|
||||||
values = Line.create_values4complete(product_id, inventory,
|
|
||||||
0., uom_id, **kwargs)
|
|
||||||
values['second_expected_quantity'] = second_qty
|
values['second_expected_quantity'] = second_qty
|
||||||
values['second_uom'] = second_uom_id
|
|
||||||
values['second_quantity'] = max(second_qty, 0.0)
|
values['second_quantity'] = max(second_qty, 0.0)
|
||||||
to_create.append(values)
|
to_create.append(values)
|
||||||
if to_create:
|
if to_create:
|
||||||
|
@ -595,9 +572,8 @@ class InventoryLine:
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_values4complete(cls, product_id, inventory, quantity, uom_id,
|
def create_values4complete(cls, inventory, quantity):
|
||||||
**kwargs):
|
|
||||||
values = super(InventoryLine, cls).create_values4complete(
|
values = super(InventoryLine, cls).create_values4complete(
|
||||||
product_id, inventory, quantity, uom_id, **kwargs)
|
inventory, quantity)
|
||||||
values['second_quantity'] = 0.
|
values['second_quantity'] = 0.
|
||||||
return values
|
return values
|
||||||
|
|
Loading…
Reference in New Issue