summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-03-03 15:50:53 +0000
committerRaphael Collet <rco@odoo.com>2020-03-25 17:36:02 +0000
commita1654e59b9a0f07dc659b790171bae2500bd1adc (patch)
treea3ead48b798338912069571843b78f43ecc02ed1 /odoo/fields.py
parent3efffa8a556d20001e232661e218bdda2c05f1c5 (diff)
[FIX] core: computed fields can be copied if editable
Purpose of this commit is to let computed stored editable fields being copied if their field class allows it. Indeed the value of those fields is computed based on some triggers but can also be updated manually by users. When copying a record, it makes sense to consider that this value is what the user expects and allow its copy, if the original field allows it. Either it was computed, and copied value will be correct without having to call computation again (well, provided all dependencies have been copied, too), or it was updated and the copied value will be the one the user entered. Without this fix, an edited field is not copied, and will be recomputed, which may look like an inconsistent value. Task ID 2209163 closes odoo/odoo#48383 X-original-commit: 4b274d3b4101fbae154a572cdf40d23838899773 Signed-off-by: Olivier Dony (odo) <odo@openerp.com> Signed-off-by: Raphael Collet (rco) <rco@openerp.com> Co-authored-by: Raphael Collet <rco@odoo.com>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index 8e57ebb13c7..02a3aa37125 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -365,10 +365,12 @@ class Field(MetaField('DummyField', (object,), {})):
# initialize ``self`` with ``attrs``
if attrs.get('compute'):
# by default, computed fields are not stored, computed in superuser
- # mode if stored, not copied and readonly
+ # mode if stored, not copied (unless stored and explicitly not
+ # readonly), and readonly (unless inversible)
attrs['store'] = store = attrs.get('store', False)
attrs['compute_sudo'] = attrs.get('compute_sudo', store)
- attrs['copy'] = attrs.get('copy', False)
+ if not (attrs['store'] and not attrs.get('readonly', True)):
+ attrs['copy'] = attrs.get('copy', False)
attrs['readonly'] = attrs.get('readonly', not attrs.get('inverse'))
if attrs.get('related'):
# by default, related fields are not stored, computed in superuser