From 21003506c061e59ec89d0e0450fbcd1d3e2da825 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 28 May 2021 18:29:07 +0000 Subject: [FIX] core: origin of main record in onchange When invoking onchange() on a line in a one2many field, the inverse many2one field is given as a dict of values. Those values are the ones of the "container" record in the form view, and they include the "id" of the container record. The method onchange() instantiates the container record as a new record with the given values. Fix the code to set the expected "origin" of that record to the record with the given "id". closes odoo/odoo#71474 X-original-commit: ebfb5d90fd4ff65ee1d2fc73faf8f9eaa18f4521 Signed-off-by: Raphael Collet (rco) --- odoo/fields.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'odoo/fields.py') diff --git a/odoo/fields.py b/odoo/fields.py index 64f2cb01edd..e1bf6331df8 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2650,7 +2650,10 @@ class Many2one(_Relational): # value is either a pair (id, name), or a tuple of ids id_ = value[0] if value else None elif isinstance(value, dict): - id_ = record.env[self.comodel_name].new(value).id + # return a new record (with the given field 'id' as origin) + comodel = record.env[self.comodel_name] + origin = comodel.browse(value.get('id')) + id_ = comodel.new(value, origin=origin).id else: id_ = None -- cgit v1.2.3