Skip to content
Snippets Groups Projects
Commit 045c6ad3 authored by Romain Derie's avatar Romain Derie
Browse files

[FIX] product: correctly consider context key for display_name


Regarding of the `display_default_code` context value, `display_name` is
supposed to return the product code or not, eg:
> product.display_name
> '[FURN_6666] Acoustic Bloc Screens'
> product.with_context(display_default_code=False).display_name
> 'Acoustic Bloc Screens'

But since the context was not considered when accessing this field, it would
always return the cached value, which was set from the first time that field
was read, with the `display_default_code` value used at that time.

tl;dr: `display_name` was ignoring the context once cached.

One of the critical issue was that internal code were displayed on the eshop
cart (not the eshop itself), see `name_short`.

task-2517830

closes odoo/odoo#70727

X-original-commit: b5b4d38a
Signed-off-by: default avatarRaphael Collet (rco) <rco@openerp.com>
Signed-off-by: default avatarRomain Derie <rdeodoo@users.noreply.github.com>
parent f31f1972
No related branches found
No related tags found
No related merge requests found
......@@ -428,6 +428,12 @@ class ProductProduct(models.Model):
args.append((('categ_id', 'child_of', self._context['search_default_categ_id'])))
return super(ProductProduct, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)
@api.depends_context('display_default_code')
def _compute_display_name(self):
# `display_name` is calling `name_get()`` which is overidden on product
# to depend on `display_default_code`
return super()._compute_display_name()
def name_get(self):
# TDE: this could be cleaned a bit I think
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_name
from . import test_variants
from . import test_pricelist
from . import test_product_pricelist
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import TransactionCase
class TestName(TransactionCase):
def setUp(self):
super().setUp()
self.product_name = 'Product Test Name'
self.product_code = 'PTN'
self.product = self.env['product.product'].create({
'name': self.product_name,
'default_code': self.product_code,
})
def test_10_product_name(self):
display_name = self.product.display_name
self.assertEqual(display_name, "[%s] %s" % (self.product_code, self.product_name),
"Code should be preprended the the name as the context is not preventing it.")
display_name = self.product.with_context(display_default_code=False).display_name
self.assertEqual(display_name, self.product_name,
"Code should not be preprended to the name as context should prevent it.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment