Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2259 Lượt xem

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?



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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()


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 25
2421
2
thg 9 22
10113
2
thg 4 22
5066
2
thg 1 22
10439
0
thg 7 21
7751