I have created a price list tab in product.template in which I have created a table product.template.line with the field x_name. How can I now display this field as a selection field in the purchase.order.line table, which only displays the number of the selected product?
The code works with a char field:
from odoo import api, fields, models
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
x_studio_pc = fields.Char(
string="PC",
compute='_compute_pcs',
store=True
)
@api.depends('product_id', 'product_id.product_tmpl_id')
def _compute_pcs(self):
for line in self:
names = []
tmpl = line.product_id.product_tmpl_id
if tmpl and hasattr(tmpl, 'x_pc_liste'):
for pc_line in tmpl.x_pc_liste:
if pc_line.x_name:
names.append(pc_line.x_name)
line.x_studio_pc = ", ".join(names)
Thank you very much
I'm not sure what you try to achieve. A selection field has a rather fixed set of options. It looks more like you want to have a Many2one on your Product Template and a Many2many on your PO line.