[FIX] mrp: duplicated raw materials

- Create Product A with a BOM which depends on a product with tracking
  "By Unique Serial Number" (Product B).
- Create a MO for Product A
- In the "Register lots" wizard, add two lines for "Product B", with the
  same serial number.

Nothing prevents the user to do it, even when the inventory is posted.

opw-709888
This commit is contained in:
Nicolas Martinelli
2017-03-15 14:01:04 +01:00
parent 73de39150a
commit 27f656a23e
3 changed files with 18 additions and 2 deletions
+6
View File
@@ -3249,6 +3249,12 @@ msgstr ""
msgid "You cannot cancel a move move having already consumed material"
msgstr ""
#. module: mrp
#: code:addons/mrp/models/stock_move.py:40
#, python-format
msgid "You cannot use the same serial number in two different lines."
msgstr ""
#. module: mrp
#: code:addons/mrp/wizard/change_production_qty.py:44
#, python-format
+10
View File
@@ -28,6 +28,16 @@ class StockMoveLots(models.Model):
done_move = fields.Boolean('Move Done', related='move_id.is_done', store=True) # TDE FIXME: naming
plus_visible = fields.Boolean("Plus Visible", compute='_compute_plus')
@api.one
@api.constrains('lot_id')
def _check_lot_id(self):
if self.move_id.product_id.tracking == 'serial':
lots = set([])
for move_lot in self.move_id.move_lot_ids.filtered(lambda r: not r.lot_produced_id):
if move_lot.lot_id in lots:
raise exceptions.UserError(_('You cannot use the same serial number in two different lines.'))
lots.add(move_lot.lot_id)
def _compute_plus(self):
for movelot in self:
if movelot.move_id.product_id.tracking == 'serial':
+2 -2
View File
@@ -125,8 +125,8 @@ class MrpProductProduce(models.TransientModel):
#Possibly the entire move is selected
remaining_qty = movelots.quantity - movelots.quantity_done
if remaining_qty > 0:
new_move_lot = movelots.copy()
new_move_lot.write({'quantity':movelots.quantity_done, 'lot_produced_id': self.lot_id.id})
default = {'quantity': movelots.quantity_done, 'lot_produced_id': self.lot_id.id}
new_move_lot = movelots.copy(default=default)
movelots.write({'quantity': remaining_qty, 'quantity_done': 0})
else:
movelots.write({'lot_produced_id': self.lot_id.id})