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
- Бухгалтерия
- Склад
- PoS
- Проекты
- MRP
Этот вопрос был отмечен
3
Ответы
142
Представления
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!!
Не оставайтесь в стороне – присоединяйтесь к обсуждению!
Создайте аккаунт сегодня, чтобы получить доступ к эксклюзивным функциям и стать частью нашего замечательного сообщества!
Регистрация| Похожие посты | Ответы | Просмотры | Активность | |
|---|---|---|---|---|
|
|
0
дек. 24
|
310 | ||
|
|
1
окт. 25
|
713 | ||
|
|
2
мая 25
|
4557 | ||
|
|
0
нояб. 24
|
1538 | ||
|
|
1
авг. 24
|
2365 |
Hello,
Yes you can inherit the name_search for that and update it as per your needs