summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2017-03-13 10:59:59 +0100
committerNicolas Martinelli <nim@odoo.com>2017-03-15 14:01:04 +0100
commit27f656a23e92df52b2f78fdd7c31b8c045b1f39b (patch)
tree32af6958f5737a44f043e65a25d3c977aa4a872d
parent73de39150a320786bd3e449363670b0a57e86c9d (diff)
[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
-rw-r--r--addons/mrp/i18n/mrp.pot6
-rw-r--r--addons/mrp/models/stock_move.py10
-rw-r--r--addons/mrp/wizard/mrp_product_produce.py4
3 files changed, 18 insertions, 2 deletions
diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot
index 5123568e86d..c85998a4bc1 100644
--- a/addons/mrp/i18n/mrp.pot
+++ b/addons/mrp/i18n/mrp.pot
@@ -3250,6 +3250,12 @@ 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
msgid "You have already processed %d. Please input a quantity higher than %d "
diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 3c6a99fa6eb..608d11e9bce 100644
--- a/addons/mrp/models/stock_move.py
+++ b/addons/mrp/models/stock_move.py
@@ -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':
diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py
index f6a70c4a1f6..b7cd863a5fc 100644
--- a/addons/mrp/wizard/mrp_product_produce.py
+++ b/addons/mrp/wizard/mrp_product_produce.py
@@ -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})