跳至內容
選單
此問題已被標幟
class SoftOneInvoice(models.Model):    
    _inherit= "account.move"
    global_discount=fields.Float('global discount')
class SoftOneInvoiceLine(models.Model):
    _inherit= "account.move.line"     @api.onchange("discount")
    def _onchange_discount(self):
        self.move_id.global_discount=0.0

The code above doesn't update in form view  the custom field global_discount of account.move model when I change the discount field of an account move line.

 

頭像
捨棄
最佳答案

Try to use the write method as below:

self.move_id.write({'global_discount':0.0})

頭像
捨棄
作者

Tried with both .write and .update methods without success.

You can do it by override write method as below and you can add your conditions if you want to check the value of discount by using vals.get('discount') :

def write(self, vals):
res = super(SoftOneInvoiceLine, self).write(vals)
if 'discount' in vals:
self.move_id.global_discount=0.0
return res

相關帖文 回覆 瀏覽次數 活動
2
4月 15
16303
2
3月 22
6418
1
2月 22
2747
1
12月 19
5462
0
12月 18
13