In Odoo 13 I cannot empty a One2many field from a Transient Model

48 Views Asked by At

I have created two models, lets say ModelA and ModelB.

ModelA has a Many2one field to sale_order_line. ModelA has a One2many field to ModelB ModelB has a Many2one field back to ModelA and is set ondelete='cascade'

class SaleOrderLine(models.Model):
    modela_id = fields.Many2one('model')


class ModelA(models.Model):
    order_line = fields.Many2one('sale.order.line')
    modelb_line_ids = fields.One2many('modelb', modela_wizard_id')

class ModelB(models.Model):
    modela_wizard_id = fields.Many2one('modela', ondelete='cascade')

class ModelC(models.TransientModel):
    order_line = fields.Many2one('sale.order.line')
    modela_id = fields.Many2one('modela', related='order_line.modela_id')
    modelb_line_ids = fields.One2many('modelb', 'modela_wizard_id', readonly=False, related='order_line.modela_id.modelb_line_ids')

I use these models to store information related to sales order lines. I can create records for ModelA with multiple ModelB records. This works fine.

However, from a different Transient model wizard, say ModelC I would like to be able to add/remove ModelB records linked to the sale_order_line.

I can do this so far on the Transient model: adding and removing is fine as long as I leave at least one record. If I try to remove all the records, nothing is removed, write and unlink do not trigger at all.

Are my field relationships perhaps set up incorrectly. I've tried so many different ways to no avail.

0

There are 0 best solutions below