Hi there,
Im trying to change product_id field domain based on a boolean in the sale order form view.
Please let me know what Im doing wrong or if there is any other approach. Thanks!
So this is what I have tried:
My xml file:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_order_form" model="ir.ui.view">
<field name="name">prointer.view_order_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="priority">90</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="sale_type" on_change="change_product_id_type(sale_type)"/>
<field name="product_id"/> <!-- this field gets updated-->
</xpath>
<xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="replace">
<field name="product_id"/> <!--This field get override with my inherit but doesnt update with domain change-->
</xpath>
</field>
</record>
</data>
</openerp>
My python file
from openerp import models, fields, api
import logging
class ProCustomSale(models.Model):
_name = 'sale.order'
_inherit = 'sale.order'
sale_type = fields.Boolean(string="Modo Venta", )
@api.onchange('sale_type')
def change_product_id_type(self, cr, uid, ids, sale_type, context=None):
logging.info('changing domain')
if sale_type: return {'domain': {'product_id': [('type', '!=', 'service')]}}
else: return {'domain': {'product_id': [('type', '=', 'service')]}}
class ProCustomLine(models.Model):
_name = 'sale.order.line'
_inherit = 'sale.order.line'
#this is the only way I can make it change,but the domain above doesnt do anything in the order line but if I make a new copy of the field anywhere else in the xml file,it works
product_id = fields.Many2one('product.product', 'Product2', domain=['&', ('sale_ok', '=', True), ('type', '=', 'service')], change_default=True, readonly=True, states={'draft': [('readonly', False)]}, ondelete='restrict')
ProCustomSale()
ProCustomLine()