Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
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.

 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try to use the write method as below:

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 15
16308
2
thg 3 22
6425
1
thg 2 22
2748
1
thg 12 19
5469
0
thg 12 18
13