コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
82 ビュー

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!

アバター
破棄
最善の回答

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.

アバター
破棄