我在Customer中有一个布尔字段x_no_change
。如果price_unit
为真,我需要在报价单中访问此字段并为报价单上的每个sale.order.line设置x_no_change
。我似乎无法访问或检查每个sale.order.line的x_no_change
。
my_partner.py
class my_partner(osv.osv):
_inherit = 'res.partner'
_columns = {
'x_no_change': fields.boolean(string='No change allowed')
}
_defaults = {
'x_no_change': False
}
my_quote.py
class my_quote(osv.osv):
_inherit = 'sale.order'
_columns = {
'x_customer_no_change': fields.related('partner_id', 'x_no_change', type='boolean', string="No change allowed")
}
_defaults = {
'x_customer_no_change': False
}
def onchange_partner_id(self, cr, uid, ids, partner, context=None):
partner = self.pool.get('res.partner').browse(cr, uid, partner, context=context)
#some other codes
val['x_customer_no_change'] = partner.x_no_change or False
return {'value': val}
class my_order_line(osv.osv):
_inherit = 'sale.order.line'
_columns = {
'x_order_no_change': fields.related('sale.order', 'x_customer_no_change', type='boolean', string='No change allowed')
}
my_quote.xml
<record id="view_sale_line_form_inherit" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="name">sale.order.line.form.inherit</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- x_customer_no_change on sale.order gets checked on change and appears to work perfectly -->
<xpath expr="//group/field[@name='partner_shipping_id']" position="after">
<field name="x_customer_no_change"/>
</xpath>
<!-- Not working: error -->
<xpath expr="//tree/field[@name='price_unit']" position="attributes">
<attribute name="attrs">{'readonly':[('x_order_no_change','=',True)]}</attribute>
</xpath>
</field>
</record>
未捕获错误:QWeb2 - template ['ListView.row']:运行时错误: 错误:域中的未知字段x_order_no_change [[ “x_order_no_change”, “=”,真]]
我错过了什么?如何根据为所选客户设置的x_no_change
值为每个订单行项设置readonly属性?提前谢谢!
答案 0 :(得分:0)
my_partner.py
class my_partner(osv.osv):
_inherit = 'res.partner'
_columns = {
'x_no_change' : fields.boolean(string='No change allowed'),
}
my_quote.py
class my_quote(osv.osv):
_inherit = 'sale.order'
_columns = {
'x_customer_no_change' : fields.related('partner_id', 'x_no_change', type='boolean', string='No change allowed'),
}
my_quote.xml
<record id="view_sale_line_form_inherit" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="name">sale.order.line.form.inherit</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- x_customer_no_change on sale.order gets checked on change and appears to work perfectly -->
<xpath expr="//group/field[@name='partner_shipping_id']" position="after">
<field name="x_customer_no_change"/>
</xpath>
<xpath expr="//tree/field[@name='price_unit']" position="attributes">
<attribute name="attrs">{'readonly':[('x_customer_no_change','=',True)]}</attribute>
</xpath>
</field>
</record>
答案 1 :(得分:0)
my_partner.py
class my_partner(osv.osv):
_inherit = 'res.partner'
x_no_change = fields.Boolean(string='No change allowed', store=True)
my_quote.py
class my_order_line(osv.osv):
_inherit = 'sale.order.line'
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
res = super(my_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
uom, qty_uos, uos, name, partner_id,
lang, update_tax, date_order, packaging, fiscal_position, flag, context)
partner_obj = self.pool.get('res.partner')
partner = partner_obj.browse(cr, uid, partner_id)
if not flag:
res['value']['x_no_change_line'] = partner.x_no_change
return res
x_no_change_line = fields.Boolean(string='No change allowed', readonly=True)
my_quote.xml
<record id="view_sale_line_form_inherit" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="name">sale.order.line.form.inherit</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='price_unit']" position="after">
<field name="x_no_change_line" invisible="1"/>
</xpath>
<xpath expr="//tree/field[@name='price_unit']" position="attributes">
<attribute name="attrs">{'readonly':[('x_no_change_line','=',True)]}</attribute>
</xpath>
</field>
</record>