[FIX] stock: write on item instead of iterable

The stock.quant `_compute_display_name` overide was writing the name on
the recordset `self` instead of the current loop element making the
quant name all the same.

This commit also remove the ' - no data -' fallback by displaying at
least the location.

closes odoo/odoo#128375

Signed-off-by: Steve Van Essche <svs@odoo.com>
This commit is contained in:
William Henrotin
2023-07-13 18:18:03 +02:00
parent 0fe78c01d9
commit d7ce5553c7
2 changed files with 24 additions and 4 deletions
+2 -4
View File
@@ -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):
+22
View File
@@ -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()