From 6728fe6aac10ff886eb213dc13c502b14e4ec5c2 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 25 Sep 2017 10:11:01 +0200 Subject: [PATCH] [FIX] stock, mrp: unique serial numbers warning Different products can have a same serial number but the code didn't consider it. --- addons/mrp/wizard/mrp_product_produce.py | 9 ++++----- addons/stock/models/stock_move_line.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index 6c15772fdab..617e5f012f9 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -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.') diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 75a4d960d01..ab164d8a656 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -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