summaryrefslogtreecommitdiff
path: root/addons/mrp/models
diff options
context:
space:
mode:
authorFlorent de Labarre <florent.mirieu@gmail.com>2017-11-13 14:29:09 +0100
committerArnold Moyaux <arm@odoo.com>2018-01-16 09:30:27 +0100
commit2bd10fa7578a44f0d534020efef059fb054e853d (patch)
tree03eb9ee8b1f38bf758a5c34084e7e666e27df3b8 /addons/mrp/models
parent3ede4c72df9e22a2b0c3129edc20d69201de2520 (diff)
[FIX] mrp: unbuild use the MO instead of BOM
When the user unbuild a product with a MO specified the system will generate the inverse moves from the BOM. However the BOM could have change. This commit instead use the MO specified in order to generate the inverse moves.
Diffstat (limited to 'addons/mrp/models')
-rw-r--r--addons/mrp/models/mrp_unbuild.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py
index 6c87ed8614e..0ff3db0a337 100644
--- a/addons/mrp/models/mrp_unbuild.py
+++ b/addons/mrp/models/mrp_unbuild.py
@@ -88,6 +88,10 @@ class MrpUnbuild(models.Model):
if self.product_id.tracking != 'none' and not self.lot_id.id:
raise UserError(_('Should have a lot for the finished product'))
+ if self.mo_id:
+ if self.mo_id.state != 'done':
+ raise UserError(_('You cannot unbuild a undone manufacturing order.'))
+
consume_move = self._generate_consume_moves()[0]
produce_moves = self._generate_produce_moves()
@@ -156,12 +160,31 @@ class MrpUnbuild(models.Model):
def _generate_produce_moves(self):
moves = self.env['stock.move']
for unbuild in self:
- factor = unbuild.product_uom_id._compute_quantity(unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
- boms, lines = unbuild.bom_id.explode(unbuild.product_id, factor, picking_type=unbuild.bom_id.picking_type_id)
- for line, line_data in lines:
- moves += unbuild._generate_move_from_bom_line(line, line_data['qty'])
+ if unbuild.mo_id:
+ raw_moves = unbuild.mo_id.move_raw_ids.filtered(lambda move: move.state == 'done')
+ factor = unbuild.product_qty / unbuild.mo_id.product_uom_id._compute_quantity(unbuild.mo_id.product_qty, unbuild.product_uom_id)
+ for raw_move in raw_moves:
+ moves += unbuild._generate_move_from_raw_moves(raw_move, factor)
+ else:
+ factor = unbuild.product_uom_id._compute_quantity(unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
+ boms, lines = unbuild.bom_id.explode(unbuild.product_id, factor, picking_type=unbuild.bom_id.picking_type_id)
+ for line, line_data in lines:
+ moves += unbuild._generate_move_from_bom_line(line, line_data['qty'])
return moves
+ def _generate_move_from_raw_moves(self, raw_move, factor):
+ return self.env['stock.move'].create({
+ 'name': self.name,
+ 'date': self.create_date,
+ 'product_id': raw_move.product_id.id,
+ 'product_uom_qty': raw_move.product_uom_qty * factor,
+ 'product_uom': raw_move.product_uom.id,
+ 'procure_method': 'make_to_stock',
+ 'location_dest_id': self.location_dest_id.id,
+ 'location_id': raw_move.location_dest_id.id,
+ 'unbuild_id': self.id,
+ })
+
def _generate_move_from_bom_line(self, bom_line, quantity):
return self.env['stock.move'].create({
'name': self.name,