diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 40b031bce9f..3ae3c0726c5 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -548,16 +548,14 @@ class StockQuant(models.Model): def _compute_display_name(self): """name that will be displayed in the detailed operation""" for record in self: - name = [] - if self.env.user.has_group('stock.group_stock_multi_locations'): - name.append(record.location_id.display_name) + name = [record.location_id.display_name] if self.env.user.has_group('stock.group_production_lot') and record.lot_id: name.append(record.lot_id.name) if self.env.user.has_group('stock.group_tracking_lot') and record.package_id: name.append(record.package_id.name) if self.env.user.has_group('stock.group_tracking_owner') and record.owner_id: name.append(record.owner_id.name) - self.display_name = ' - '.join(name) if name else "- no data -" + record.display_name = ' - '.join(name) @api.constrains('product_id') def check_product_id(self): diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index 16778a0488b..bb6e8fe9f8a 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -797,6 +797,28 @@ class StockQuant(TransactionCase): quant.invalidate_recordset(['quantity']) self.assertEqual(quant.quantity, 11) + def test_quant_display_name(self): + """ Check the display name of a quant. """ + sn1 = self.env['stock.lot'].create({ + 'name': 'sn1', + 'product_id': self.product_serial.id, + 'company_id': self.env.company.id, + }) + lot1 = self.env['stock.lot'].create({ + 'name': 'lot1', + 'product_id': self.product_lot.id, + 'company_id': self.env.company.id, + }) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=sn1) + quants = self.stock_location.quant_ids + for q in quants: + if q.lot_id: + self.assertEqual(q.display_name, '%s - %s' % (q.location_id.display_name, q.lot_id.name)) + else: + self.assertEqual(q.display_name, '%s' % (q.location_id.display_name)) + class StockQuantRemovalStrategy(TransactionCase): def setUp(self): super().setUp()