跳至内容
菜单
此问题已终结
1 回复
5424 查看

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

形象
丢弃
相关帖文 回复 查看 活动
2
6月 22
3364
1
4月 22
2208
0
2月 22
4525
1
1月 22
2219
1
1月 21
3106