Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2262 Переглядів

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
2
січ. 22
10439
0
лип. 21
7751