I have defined product_status in product.supplierinfo like this:
from odoo import fields, models
class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo'
product_status = fields.Selection(
[('homologado','Homologado'),('no_homologado','No Homologado'),('on_hold','On Hold')],
string="Product Homologation Status",
default=None,
store=True)
In the user interface you can choose the value that you want it to be, then i want to show the value defined, when you do a PO.
For this I have added the field in the view purchase.order.line:
<odoo>
<record id="view_purchase_order_form_inherit_custom" model="ir.ui.view">
<field name="name">purchase.order.form.inherit.custom</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<!-- Agregar el campo product_status en la vista tree -->
<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="after">
<field name="product_status" string="Estado de Homologación"/> </xpath>
<!-- Agregar el campo product_status en la vista form -->
<xpath expr="//field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
<field name="product_status" string="Estado de Homologación"/>
</xpath>
</field>
</record>
</odoo>
Finally I have tried to relate both fields using the depends decorator, this is my code:
from odoo import models, fields, api
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
product_status = fields.Selection(
selection=[('homologado', 'Homologado'),('no_homologado', 'No Homologado'),('on_hold', 'On Hold')],
string="Product Homologation Status",
compute="_compute_product_status",
store=True,
readonly=True)
@api.depends('product_id', 'partner_id')
def _compute_product_status(self):
for line in self:
# Si no hay producto o partner, no hay nada que calcular
if not line.product_id or not line.partner_id:
line.product_status = False
continue
# Busca el supplierinfo correspondiente
supplierinfo = self.env['product.supplierinfo'].search([
('product_id', '=', line.product_id.id),
('partner_id', '=', line.partner_id.id),
], limit=1)
# Si existe supplierinfo, toma el `product_status`
if supplierinfo:
line.product_status = supplierinfo.product_status
else:
line.product_status = "on_hold"
My problem is that in the PO view it always appears the value of product_status as on_hold.
I dont know how to make both fields relate to each other, all help will be welcomed