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

Hi,

In parent model:

product_id = fields.Many2one('product.product', compute='_compute_product_id_for_measure')
measure_data_ids = fields.One2many('measure.spec', 'point_id')

In child model:

point_id = fields.Many2one('elw.point', 'Control Point', ondelete='cascade')
product_id = fields.Many2one('product.product', string="Product", domain="[('type','in',('product','consu'))]",store=True, related="point_id.product_id")

When I deleted a record from parent model, its child record removed only two relation fields ('point_id' and 'product_id') as shown. How can I delete its child record completely when the parent record is removed?



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

Hi all,

I have solved this issue by overwriting the unlink method as follows

def unlink(self):
for rec in self:
if rec.state != 'none' or rec.picking_id:
raise ValidationError(
_("Can not delete the record that is not in 'To Do' or has Deliveries/Receipts order"))
elif len(rec.measure_data_ids) > 0:
# unlink child's records
rec.measure_data_ids.unlink()
return super(ElwCheck, self).unlink()


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 25
2421
2
ก.ย. 22
10113
2
เม.ย. 22
5066
How to set ondelete on selection_add แก้ไขแล้ว
2
ม.ค. 22
10439
0
ก.ค. 21
7751