[REF] mrp: share similar code

The quantity to consume for a component is computed in different places
(community and enterprise modules, workorder and produce wizard) during
a production. This commit share those computations into a static function.

closes odoo/odoo#32864

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
William Henrotin
2019-04-23 13:24:43 +00:00
parent 92480b8697
commit a45e843dec
2 changed files with 18 additions and 19 deletions
+16 -9
View File
@@ -26,6 +26,20 @@ class MrpAbstractWorkorder(models.AbstractModel):
)
use_create_components_lots = fields.Boolean(related="production_id.picking_type_id.use_create_components_lots")
@api.model
def _prepare_component_quantity(self, move, qty_producing):
""" helper that computes quantity to consume (or to create in case of byproduct)
depending on the quantity producing and the move's unit factor"""
if move.product_id.tracking == 'serial':
uom = move.product_id.uom_id
else:
uom = move.product_uom
return move.product_uom._compute_quantity(
qty_producing * move.unit_factor,
uom,
round=False
)
def _workorder_line_ids(self):
self.ensure_one()
return self.raw_workorder_line_ids | self.finished_workorder_line_ids
@@ -63,15 +77,8 @@ class MrpAbstractWorkorder(models.AbstractModel):
# Compute the new quantity for the current component
rounding = move.product_uom.rounding
if move.product_id.tracking == 'serial':
uom = move.product_id.uom_id
else:
uom = move.product_uom
new_qty = move.product_uom._compute_quantity(
self.qty_producing * move.unit_factor,
uom,
round=False
)
new_qty = self._prepare_component_quantity(move, self.qty_producing)
# In case the production uom is different than the workorder uom
# it means the product is serial and production uom is not the reference
new_qty = self.product_uom_id._compute_quantity(
+2 -10
View File
@@ -232,11 +232,7 @@ class MrpWorkorder(models.Model):
lambda move: move.state not in ('done', 'cancel')
)
for move in moves:
qty_to_consume = move.product_uom._compute_quantity(
self.qty_producing * move.unit_factor,
move.product_id.uom_id,
round=False
)
qty_to_consume = self._prepare_component_quantity(move, self.qty_producing)
line_values = self._generate_lines_values(move, qty_to_consume)
self.env['mrp.workorder.line'].create(line_values)
@@ -273,11 +269,7 @@ class MrpWorkorder(models.Model):
continue
qty_already_consumed += wl.qty_done
qty_to_consume = move.product_uom._compute_quantity(
workorder.qty_producing * move.unit_factor,
move.product_id.uom_id,
round=False
)
qty_to_consume = self._prepare_component_quantity(move, workorder.qty_producing)
wl_to_unlink.unlink()
if float_compare(qty_to_consume, qty_already_consumed, precision_rounding=rounding) > 0:
line_values = workorder._generate_lines_values(move, qty_to_consume - qty_already_consumed)