Is it possible to change the field display_name in the sales dropdown in sales where the product to add to the order line is selected? The standard Odoo shows `display_name`, which is `default_code` + the product name. I want to know if it's possible and how to change for another different compute field instead to show in the dropdown in odoo 18
I'm trying to concatenate more fields so that they display in the dropdown without affecting other modules that use the product's display_name
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilità
- Magazzino
- PoS
- Progetti
- MRP
La domanda è stata contrassegnata
3
Risposte
134
Visualizzazioni
from odoo import models, api
class ProductProduct(models.Model):
_inherit = 'product.product'
@api.depends_context('show_sale_display')
def _compute_display_name(self):
if self.env.context.get('show_sale_display'):
for rec in self:
rec.display_name = f"[{rec.default_code or ''}] {rec.name} | ${rec.list_price:.2f}"
else:
super()._compute_display_name()
views/sale_order_view.xml
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_order_form_custom_display" model="ir.ui.view">
<field name="name">sale.order.form.custom.display</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/list/field[@name='product_id']" position="attributes">
<attribute name="context">{'show_sale_display': True}</attribute>
</xpath>
</field>
</record>
</odoo>
Result: Sale shows [ABC123] Product Name | $99.99 other modules show default.
I hope this information helps you
Thanks & Regards,
Kunjan Patel
Result: Sale shows [ABC123] Product Name | $99.99 other modules show default.
I hope this information helps you
Thanks & Regards,
Kunjan Patel
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
thank you all!!
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!
Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!
Registrati| Post correlati | Risposte | Visualizzazioni | Attività | |
|---|---|---|---|---|
|
|
0
dic 24
|
309 | ||
|
|
1
ott 25
|
710 | ||
|
|
2
mag 25
|
4557 | ||
|
|
0
nov 24
|
1538 | ||
|
|
1
ago 24
|
2363 |
Hello,
Yes you can inherit the name_search for that and update it as per your needs