我在客户表格中有客户和存款字段,实际上是one2many但是用户在存款中添加一行并提交或编辑一些现有的。我想对那个事件做一些计算。我尝试了onchange
和compute
,但它不起作用。
答案 0 :(得分:0)
添加或编辑One2many字段是FormView。
所以你只需在FormView * .xml
中输入你要做的事情实施例。使用我的SUM字段
<record model="ir.ui.view" id="view_nstda_bst_dbill_form">
<field name="name">nstda.bst.dbill.form</field>
<field name="model">nstda.bst.dbill</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="nstda_bst_dbill" class="nstda_bst_dbill_form" >
<group>
<field name="status" invisible="1" />
<field name="matno" />
<!-- <field name="matdesc" /> -->
<label for="balance" />
<div>
<field name="balance" style="width: 20%%" />
<field name="uom_1" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<label for="balance_rs" />
<div>
<field name="balance_rs" style="color:Red;width: 20%%" />
<field name="uom_2" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<label for="qty" />
<div>
<field name="qty" style="width: 20%%"
attrs="{'required':[('status','in',['draft','edit',False])]}" />
<field name="uom" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<!-- <field name="unitprice" /> -->
<label for="unitprice" />
<div>
<field name="unitprice" style="width: 20%%" />
<field name="currency" style="width: 10%%;" />
</div>
<field name="sum" invisible="1" />
<field name="dbill_discount_sum" invisible="1" />
</group>
</form>
</field>
</record>
和* .py方面是......
实施例
@api.one
@api.onchange('qty','matno')
@api.depends('qty','matno')
def _set_sum(self):
self.sum = self.unitprice * self.qty
sum = fields.Float(string="summary", store=True, compute='_set_sum')
matno = fields.Many2one('bst.stock', 'matno')
qty = fields.Integer('qty')