summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosse Colpaert <jco@odoo.com>2017-09-19 15:48:31 +0200
committeramoyaux <arm@odoo.com>2017-09-27 18:10:20 +0200
commit4cb2e626a9ea30ea05e2844a29ca8eec6f2bc567 (patch)
tree6af43eff6688667c75d9b4558857bd75a45731f5
parent0a75db1db2a807f6251938005cd1f85d6053a247 (diff)
[IMP] mrp: Allow optional bom lines with 0 qty
When processing moves with 0 initial demand, it will set the initial demand = qty_done. Also, when updating the quantity of an MO, don't take into account those with 0 quantity.
-rw-r--r--addons/mrp/models/mrp_bom.py3
-rw-r--r--addons/mrp/models/mrp_production.py4
-rw-r--r--addons/mrp/models/mrp_workorder.py2
-rw-r--r--addons/mrp/wizard/mrp_product_produce.py2
4 files changed, 7 insertions, 4 deletions
diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index 06e3479c190..f41e4a5a111 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -214,7 +214,8 @@ class MrpBomLine(models.Model):
has_attachments = fields.Boolean('Has Attachments', compute='_compute_has_attachments')
_sql_constraints = [
- ('bom_qty_zero', 'CHECK (product_qty>0)', 'All product quantities must be greater than 0.\n'
+ ('bom_qty_zero', 'CHECK (product_qty>=0)', 'All product quantities must be greater or equal to 0.\n'
+ 'Lines with 0 quantities can be used as optional lines. \n'
'You should install the mrp_byproduct module if you want to manage extra products on BoMs !'),
]
diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py
index 5098601f358..9d2076596a0 100644
--- a/addons/mrp/models/mrp_production.py
+++ b/addons/mrp/models/mrp_production.py
@@ -399,7 +399,7 @@ class MrpProduction(models.Model):
if move:
if quantity > 0:
move[0].write({'product_uom_qty': quantity})
- else:
+ elif quantity < 0: # Do not remove 0 lines
if move[0].quantity_done > 0:
raise UserError(_('Lines need to be deleted, but can not as you still have some quantities to consume in them. '))
move[0]._action_cancel()
@@ -510,6 +510,8 @@ class MrpProduction(models.Model):
for order in self:
moves_not_to_do = order.move_raw_ids.filtered(lambda x: x.state == 'done')
moves_to_do = order.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
+ for move in moves_to_do.filtered(lambda m: m.product_qty == 0.0 and m.quantity_done > 0):
+ move.product_uom_qty = move.quantity_done
moves_to_do._action_done()
moves_to_do = order.move_raw_ids.filtered(lambda x: x.state == 'done') - moves_not_to_do
order._cal_price(moves_to_do)
diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py
index f0854ee3523..18329432edd 100644
--- a/addons/mrp/models/mrp_workorder.py
+++ b/addons/mrp/models/mrp_workorder.py
@@ -245,7 +245,7 @@ class MrpWorkorder(models.Model):
self.ensure_one()
MoveLine = self.env['stock.move.line']
tracked_moves = self.move_raw_ids.filtered(
- lambda move: move.state not in ('done', 'cancel') and move.product_id.tracking != 'none' and move.product_id != self.production_id.product_id)
+ lambda move: move.state not in ('done', 'cancel') and move.product_id.tracking != 'none' and move.product_id != self.production_id.product_id and move.bom_line_id)
for move in tracked_moves:
qty = move.unit_factor * self.qty_producing
if move.product_id.tracking == 'serial':
diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py
index 617e5f012f9..338dbabea42 100644
--- a/addons/mrp/wizard/mrp_product_produce.py
+++ b/addons/mrp/wizard/mrp_product_produce.py
@@ -37,7 +37,7 @@ class MrpProductProduce(models.TransientModel):
res['product_qty'] = todo_quantity
if 'produce_line_ids' in fields:
lines = []
- for move in production.move_raw_ids.filtered(lambda x: (x.product_id.tracking != 'none') and x.state not in ('done', 'cancel')):
+ for move in production.move_raw_ids.filtered(lambda x: (x.product_id.tracking != 'none') and x.state not in ('done', 'cancel') and x.bom_line_id):
qty_to_consume = todo_quantity / move.bom_line_id.bom_id.product_qty * move.bom_line_id.product_qty
for move_line in move.move_line_ids:
if float_compare(qty_to_consume, 0.0, precision_rounding=move.product_uom.rounding) < 0\