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

@api.depends("product_tmpl_id")

def _computeBOMLine(self):

for record in self:

bom_lines = record.product_tmpl_id.bom_ids.mapped("bom_line_ids").filtered(lambda x: record.id in x.bom_product_template_attribute_value_ids.ids)

if any(bom_lines):

record.computed_bom_line_id = bom_lines[0].id

else:

record.computed_bom_line_id = False


computed_bom_line_id = fields.Many2one("mrp.bom.line",compute="_computeBOMLine", store=True)


Compute method is not getting called, unless I remove store attribute nothing happens.

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

Hi,
If you have a compute field in your model and if you give store=True for the field, the field value will not get recomputed if proper depends is not given for the compute function. As the compute function is not getting recomputed you will have wrong value in the field.

See:-  Why Stored Computed Fields Are Not Recomputing in Odoo


Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi,

yes It was related to store=True. I had to remove it since I couldn't figure out any other hook point to trigger it.


Thanks for the response.


Regards,

Sunil

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
พ.ค. 20
2543
How can I get ID of New record? แก้ไขแล้ว
2
ธ.ค. 24
14906
2
ก.พ. 25
7393
0
ต.ค. 20
3475
0
มี.ค. 24
1185