[FIX] stock, mrp: unique serial numbers warning

Different products can have a same serial number but the code didn't
consider it.
This commit is contained in:
Simon Lejeune
2017-09-25 18:17:52 +02:00
parent 059710b2b0
commit 6728fe6aac
2 changed files with 12 additions and 12 deletions
+4 -5
View File
@@ -193,9 +193,8 @@ class MrpProductProduceLine(models.TransientModel):
def _check_for_duplicated_serial_numbers(self):
if self.mapped('lot_id'):
lot_names = [ml.lot_id.name for ml in self]
recorded_serials_counter = Counter(lot_names)
for lot_id, occurrences in recorded_serials_counter.items():
lots_map = [(ml.product_id.id, ml.lot_id.name) for ml in self]
recorded_serials_counter = Counter(lots_map)
for (product_id, lot_id), occurrences in recorded_serials_counter.items():
if occurrences > 1 and lot_id is not False:
return _(
'You cannot consume the same serial number twice. Please correct the serial numbers encoded.')
return _('You cannot consume the same serial number twice. Please correct the serial numbers encoded.')
+8 -7
View File
@@ -140,16 +140,17 @@ class StockMoveLine(models.Model):
:return: an error message directed to the user if needed else False
"""
if self.mapped('lot_id'):
lot_names = [ml.lot_id.name for ml in self]
recorded_serials_counter = Counter(lot_names)
for lot_id, occurrences in recorded_serials_counter.items():
lots_map = [(ml.product_id.id, ml.lot_id.name) for ml in self]
recorded_serials_counter = Counter(lots_map)
for (product_id, lot_id), occurrences in recorded_serials_counter.items():
if occurrences > 1 and lot_id is not False:
return _('You cannot consume the same serial number twice. Please correct the serial numbers encoded.')
return _('You cannot use the same serial number twice. Please correct the serial numbers encoded.')
elif self.mapped('lot_name'):
recorded_serials_counter = Counter(self.mapped('lot_name'))
for lot_id, occurrences in recorded_serials_counter.items():
lots_map = [(ml.product_id.id, ml.lot_name) for ml in self]
recorded_serials_counter = Counter(lots_map)
for (product_id, lot_id), occurrences in recorded_serials_counter.items():
if occurrences > 1 and lot_id is not False:
return _('You cannot consume the same serial number twice. Please correct the serial numbers encoded.')
return _('You cannot use the same serial number twice. Please correct the serial numbers encoded.')
return False
@api.model