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

My problem is I have model A with list of model B. In model B I've got a field with a compute method. In that method I have to use data that is stored in model A M2M field. When the method is triggered by api.depends it works. But when I save model A record the model B compute method is triggered and the M2M field is empty even if there are values in it.

But I need those values, what I'm doing wrong?


ModelA
------
partner_ids = field.Many2many()
line_ids = fields.One2many(ModelB, model_a_id)

ModelB
------
model_a_id = fields.Many2one(ModelA)
calculated_field = field.Float(compute='_get_value', store=True)


@api.depends(some fields)

def _get_value(self):
for rec in self:
# some computations
if rec.model_a_id.partner_ids:
# do something

 

อวตาร
ละทิ้ง

If you want the computed field to be calculated if the value in modelA.M2M field changes then in api.depends you need to add the M2M field as below:

@api.depends("model_a_id.partner_ids")

ผู้เขียน

nope that is not not the question or the problem!

Related Posts ตอบกลับ มุมมอง กิจกรรม
How to get Many2many records ids แก้ไขแล้ว
1
มิ.ย. 22
5200
0
ม.ค. 24
169
1
ก.ย. 23
1578
1
ธ.ค. 22
3096
2
มี.ค. 21
4464