Skip to content
Snippets Groups Projects
Commit 7fc1a3ca authored by Goffin Simon's avatar Goffin Simon
Browse files

[FIX] mrp: Computing the qty of the BOM Structure report

Each qty of a line in the BOM Structure report must be computed in
the uom of its BOM line.

Example:

With 2 products: A, B

BOM A: 100 kg of A is produced by 5t of B

So 1kg of A needs how many t of B ?:

In the code:
qty_per_bom = 100 kg expressed in the uom of B => qty_per_bom = 0.1t
qty = 1 kg expressed in the uom of B => qty = 0.001t
l.product_qty = 5t
qty of B = (l.product_qty *qty)/ qty_per_bom = 0.05t

opw:697502
parent e8b0c1db
Branches
Tags
No related merge requests found
......@@ -10,12 +10,23 @@ class BomStructureReport(models.AbstractModel):
def get_children(self, object, level=0):
result = []
def _get_rec(object, level, qty=1.0):
def _get_rec(object, level, qty=1.0, uom=False):
for l in object:
res = {}
res['pname'] = l.product_id.name_get()[0][1]
res['pcode'] = l.product_id.default_code
res['pqty'] = l.product_qty * qty
qty_per_bom = l.bom_id.product_qty
if uom and uom != l.product_uom_id:
qty = uom._compute_quantity(qty, l.product_uom_id)
if uom and l.product_uom_id != l.bom_id.product_uom_id:
qty_per_bom = l.bom_id.product_uom_id._compute_quantity(qty_per_bom, l.product_uom_id)
res['pqty'] = (l.product_qty *qty)/ qty_per_bom
elif uom:
res['pqty'] = (l.product_qty *qty)/ qty_per_bom
else:
#for the first case, the ponderation is right
res['pqty'] = (l.product_qty *qty)
res['puom'] = l.product_uom_id
res['uname'] = l.product_uom_id.name
res['level'] = level
res['code'] = l.bom_id.code
......@@ -23,7 +34,7 @@ class BomStructureReport(models.AbstractModel):
if l.child_line_ids:
if level < 6:
level += 1
_get_rec(l.child_line_ids, level, qty=res['pqty'])
_get_rec(l.child_line_ids, level, qty=res['pqty'], uom=res['puom'])
if level > 0 and level < 6:
level -= 1
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment