コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2261 ビュー

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


アバター
破棄
関連投稿 返信 ビュー 活動
1
1月 25
2421
2
9月 22
10113
2
4月 22
5066
2
1月 22
10439
0
7月 21
7751