I have this module that allows to select the category of product that going to be used for this purchase, because we have a lot of products this a way to limit the search result,
but the problem is all the info related to order_id field are available after the product is selected, for example state, if we make state visible in the order line it value is there only after selecting a product, the same for my field category, is someone have an idea to fix this.
I am using odoo 11.0
from odoo import api, fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
category = fields.Many2one('product.category', )
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
category = fields.Many2one (related='order_id.category', string='Cat', readonly=True, store=True)
product_id = fields.Many2one('product.product', domain="['&', ('categ_id','=',category), ('purchase_ok', '=', True)]",
string='Product', change_default=True, required=True)