如何将默认计算应用于list_price字段产品odoo v11 [英] how to apply a default calcul to the list_price field product odoo v11
问题描述
从odoo导入模型,字段,api
from odoo import models, fields , api
class product_template(models.Model):
class product_template(models.Model):
_inherit = 'product.template'
remise = fields.float('remise du fournisseur', size=10, required=True)
marge = fields.float('marge', size=10, required=True)
total_reste = fields.float('Reste', size=10, required=True)
def onchange_calculer(val1, val2):
return {'value': {'list_price': val1 * (val2/100) + val1}}
}
<我的xml查看文件代码
< my xml view file code
<record id="view_product_form" model="ir.ui.view">
<field name="name">product.template.common.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='list_price']" position="after">
<field name="x_remise1"/>
<field name="x_marge1"/>
<field name="list_price"
on_change ="onchange_calculer(standard_price,x_marge1)" readonly ="True"/>
on_change="onchange_calculer(standard_price, x_marge1)" readonly="True" />
</xpath>
</field>
</record>
我不明白为什么它不起作用
i can't see why it doesnt work
推荐答案
尝试一下.
@api.multi
@api.onchange('val1','val2')
def onchange_calculer(self):
for s in self:
s.list_price = s.val1 * (s.val2/100) + s.val1
其中val1和val2是product.template对象的字段,并且在检测到val1和val2字段值的任何变化时,onchage_calculer将启动. 对不起,我的英语.
Where val1 and val2 are fields of product.template object and onchage_calculer will start when detect any change in val1 and val2 fields values. sorry for my english.
P.D:fields.float('')sintax在v11中有效吗?
P.D: the fields.float('') sintax works in v11 ?
这篇关于如何将默认计算应用于list_price字段产品odoo v11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!