summaryrefslogtreecommitdiff
path: root/odoo/addons/test_new_api/models/test_new_api.py
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-11-20 08:00:31 +0000
committerRaphael Collet <rco@odoo.com>2020-12-02 11:45:17 +0000
commit5279a08a005bacee4ecd76cc189d8ce65c8e600c (patch)
treeb635beef0fd3e992f1fe407ec247775ec0bc6146 /odoo/addons/test_new_api/models/test_new_api.py
parentbaf32bbc177fe653ffc4ee4cd9c014c85910c8d2 (diff)
[FIX] core: invalidation of computed editable field in one2many
This fixes the issue introduced by revision fd50ba9fb838067fab0b920470cf79b9c94d785c The way computed fields are invalidated depends on the order of the dict passed as a parameter to method onchange(). This causes some unexpected behavior when dealing with computed editable fields: the user loses the value in that field because of the onchange. Explanation: during the onchange, the modified field is cached by record._update_cache(changed_values, validate=True) If the field is a one2many, 'value' contains an update command for each modified line. Because of 'validate=True', the assignment triggers field computations on the lines, which are already handled by another call to onchange(). In case anything on the parent model modifies some line, the whole one2many values are returned to the user, and accidentally recomputed fields show up in the interface. closes odoo/odoo#62060 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/addons/test_new_api/models/test_new_api.py')
-rw-r--r--odoo/addons/test_new_api/models/test_new_api.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/models/test_new_api.py b/odoo/addons/test_new_api/models/test_new_api.py
index 27af01e335b..2cb28702520 100644
--- a/odoo/addons/test_new_api/models/test_new_api.py
+++ b/odoo/addons/test_new_api/models/test_new_api.py
@@ -1147,3 +1147,35 @@ class ComputeMember(models.Model):
container = self.env['test_new_api.compute.container']
for member in self:
member.container_id = container.search([('name', '=', member.name)], limit=1)
+
+
+class ComputeEditable(models.Model):
+ _name = _description = 'test_new_api.compute_editable'
+
+ line_ids = fields.One2many('test_new_api.compute_editable.line', 'parent_id')
+
+ @api.onchange('line_ids')
+ def _onchange_line_ids(self):
+ for line in self.line_ids:
+ # even if 'same' is not in the view, it should be the same as 'value'
+ line.count += line.same
+
+
+class ComputeEditableLine(models.Model):
+ _name = _description = 'test_new_api.compute_editable.line'
+
+ parent_id = fields.Many2one('test_new_api.compute_editable')
+ value = fields.Integer()
+ same = fields.Integer(compute='_compute_same', store=True)
+ edit = fields.Integer(compute='_compute_edit', store=True, readonly=False)
+ count = fields.Integer()
+
+ @api.depends('value')
+ def _compute_same(self):
+ for line in self:
+ line.same = line.value
+
+ @api.depends('value')
+ def _compute_edit(self):
+ for line in self:
+ line.edit = line.value