summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2019-04-23 09:19:48 +0000
committerWilliam Henrotin <whe@odoo.com>2019-04-23 13:24:43 +0000
commita45e843decefbb2fed3505bd2c9ce68f66f00d2e (patch)
treeca9a92e841dea6923a394404f11681c5edd0ba9e
parent92480b86978929e57c1c15d975cebfd0d6441135 (diff)
[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>
-rw-r--r--addons/mrp/models/mrp_abstract_workorder.py25
-rw-r--r--addons/mrp/models/mrp_workorder.py12
2 files changed, 18 insertions, 19 deletions
diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py
index 67f2c4946c9..da0d40aa5bb 100644
--- a/addons/mrp/models/mrp_abstract_workorder.py
+++ b/addons/mrp/models/mrp_abstract_workorder.py
@@ -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(
diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py
index 402743f856e..154c9d60b49 100644
--- a/addons/mrp/models/mrp_workorder.py
+++ b/addons/mrp/models/mrp_workorder.py
@@ -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)