Hello. Before start some code:
class ExampleModelItem(models.Model):
_name = "example.model.item"
partner_id = fields.Many2one(comodel_name='res.partner')
lines = fields.Many2many(comodel_name='sale.order.line')
@api.onchange("partner_id")
def _compute_sale_lines(self):
ctx_obj = self._context['reglas']
class ExampleModel(models.Model):
_name = "example.model"
reglas = fields.One2many(comodel_name='example.model.item', inverse_name='...', string="...")
lines = fields.Many2many(comodel_name='sale.order.line')
The view in "example.model" looks like :
<field name="reglas" context="{'reglas': reglas}">
<tree>...</tree>
<form>...</form>
</field>
As you can see in the view we set the field in the context, we get the value to ctx_obj variable in the _compute function.
This ctx_obj have a list of the old o2m structure [(0, False, {...}), (1, 1, {...}), (4, 3, False), ..., (type, id, data)]
The problem i facing is, how can i know in the compute method if the record is one of the records in the ctx_obj? Or even better, wich one. When self.id exists its easy, because i can find that id in the ctx_obj. But when self.id is a Newid object, the ctx_obj will be a False. Is there a way to acknowledge is the newid is already in the context object or not??
Thank you in advance