[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.
This commit is contained in:
Josse Colpaert
2017-09-27 18:10:20 +02:00
committed by amoyaux
parent 0a75db1db2
commit 4cb2e626a9
4 changed files with 7 additions and 4 deletions
+2 -1
View File
@@ -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 !'),
]
+3 -1
View File
@@ -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)
+1 -1
View File
@@ -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':
+1 -1
View File
@@ -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\