Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5423 มุมมอง

Hello,

I'm playing with field.Integer() and I think my question is very easy for an odoo expert.

How to compute value from a website ?

I tried this code below but when I change the value in the form, the compute result is not changing.

If you have documentation about it, it would be great.

Regards

model.py:

name = fields.Char()
biography = fields.Html()
nbr1 = fields.Integer()
result = fields.Integer(compute="_compute_total")

@api.onchange('nbr1')
def _compute_total(self):
for record in self:
record.result = 2*self.nbr1

template.xml:




Last modified:




:






อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You should use the @api.depends decorator instead of @api.onchange for computed fields that depend on other fields.

    name = fields.Char()

    biography = fields.Html()

    nbr1 = fields.Integer()

    result = fields.Integer(compute='_compute_total', store=True)


    @api.depends('nbr1')

    def _compute_total(self):

        for record in self:

            record.result = 2 * record.nbr1


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Can't edit web event page แก้ไขแล้ว
2
มิ.ย. 22
3361
1
เม.ย. 22
2207
0
ก.พ. 22
4523
1
ม.ค. 22
2218
1
ม.ค. 21
3105