Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
2260 Prikazi

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?



Avatar
Opusti
Avtor Best Answer

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


Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jan. 25
2421
2
sep. 22
10113
2
apr. 22
5066
2
jan. 22
10439
0
jul. 21
7751