I created a new model with the name product.service.type
. Then in the model, product.product
I also created a field Many2many
(with a name service_type
pointing to the model product.service.type
).
Now I have a model test
that has fields product_id
and service_type_id
, both Many2one
point to product.product
and product.service.type
respectively.
When I select a product, I want to change the domain of the service type to display only the service types of the selected product. I managed it through onchange
:
def onchange_product_id(self, cr, uid, ids, product_id, context=None):
if product_id:
product = self.pool.get('product.product').browse(
cr, uid, [product_id], context=context)
service_type_ids = product.service_type.mapped('id')
return {
'domain': {
'service_type_id': [('id', 'in', service_type_ids)],
},
}
This works great, the problem is that you are editing the record (without creating a new one), because in this case onchange
it is not executed, and therefore the domain shows all types of services.
title
. , , title
, , Corp., Ltd. .., , , , , , .. . . title
, is_company
. , , ( ).
?