Skip to Content
मेन्यू
This question has been flagged
3 Replies
980 Views

Hi,

I am resorting to the forum as I'm at my wits end as to why this is happening. It seems to have started happening after upgrading to Odoo 18

My issue is that display_name is not working as I'd expect.

If I edit the product, it appears as I'd like ([default_code] name)

Screenshot: https://drive.google.com/file/d/1uBE3QdlUmqllqBtq8RN3TOk0QCNGEaLB/view?usp=sharing


When I browse the product in the sol_product_many2one widget, they are appearing

Screenshot: https://drive.google.com/file/d/1i-IV2Uq-iYCbtXP8unByj3f2nJv5pnL1/view?usp=sharing


But - when I add the product it just disappears.

Screenshot: https://drive.google.com/file/d/1ngwsDimqb6VQfnMJpdu9R-tbWHSA4LH8/view?usp=sharing


It also does not show on PDF quotes / order confs. 


Is this new default behaviour that I need to fix manually with Odoo 18, or is something not configured right? I tried to investigate the sol_product_many2one but it's a bit too dense for me. I also checked the "name" column in the sale_order_line table, and that indeed does not include the default_code.


Thank you so much in advance!

Avatar
Discard
Best Answer

Hello Frank,



It looks like the display name customization isn't being consistently applied across the sales order line. Here's how you can address this:



  First, verify the computed field for display_name in your product.product model. Ensure it correctly concatenates default_code and name.

  Next, check if the sale_order_line model inherits or overrides the name_get method. If it does, ensure it includes the default_code in the display name.

  If the name field in sale_order_line is populated only with the product name, you might need to create an automated action or a server action to update this field with the desired [default_code] name format when a product is added to the sales order line.

  Finally, for PDF reports, ensure the report template correctly fetches and displays the display_name or the concatenated value of default_code and name from the sale_order_line.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Avatar
Discard
Best Answer

Hi,

In Odoo 18, the behavior of product names changed: the display_name (which shows [default_code] name) is now only used for UI display and is not automatically copied into the sale order line’s name field. This is why the product appears correctly in the widget but disappears after selection and doesn’t show in PDFs. To restore the old behavior, you can override the product_id onchange in sale.order.line so that the name field stores the display name.


Code:

from odoo import models, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    @api.onchange('product_id')

    def _onchange_product_id_custom(self):

        res = super(SaleOrderLine, self)._onchange_product_id()

        if self.product_id:

            self.name = self.product_id.display_name or self.product_id.name

        return res


Hope it helps.

Avatar
Discard
Best Answer

What’s Happening in Odoo 18

  1. display_name no longer includes [default_code] name automatically everywhere.

    • In Odoo 17 and earlier, the default behavior was for display_name to return [default_code] name if default_code existed.

    • In Odoo 18, the logic for display_name is not used consistently across all widgets or record displays anymore. Some widgets like sol_product_many2one still use it, but fields like product_id.name or report lines may now rely on name or direct database values that exclude default_code.

  2. On the Sale Order Line (SOL), the name field is manually computed.

    • This field is populated during product_id_change() or _compute_product_id_change().

    • It does not include [default_code] unless you explicitly add it to the logic.

  3. PDF reports and quotes depend on the sale.order.line.name field.

    • If default_code isn’t part of that field, it won’t appear on your documents.

 How to Fix It

You need to override the behavior that generates the sale order line name to include the default_code. This will make it show up correctly in:

  • The form view

  • The PDF/print report

  • Any related downstream record

 Override product_id_change in a custom module or via Studio (dev mode)


from odoo import models


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    def _compute_product_id_change(self):

        super()._compute_product_id_change()


        for line in self:

            if line.product_id:

                product = line.product_id

                default_code = product.default_code or ''

                name = product.name or ''

                display_name = "[%s] %s" % (default_code, name) if default_code else name

                line.name = display_name


 Fix PDF Quotes/Reports

Ensure your QWeb report template uses line.name and not just product_id.name. You don’t have to change this if you fix the name field as shown above — but just double-check.

 Why This Changed in Odoo 18?

Odoo 18 leans more toward modular, explicit control over display logic — likely to reduce performance overhead and simplify translation and customization. However, it means you have to manually define where and how you want default_code included.

Summary of What You Should Do

  •  Override _compute_product_id_change() to customize how name on sale.order.line is populated.

  •  Confirm your report template pulls from line.name, not product_id.name.

  •  Don’t rely solely on display_name anymore — it's not consistently used in PDF/reporting contexts.

Avatar
Discard