summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-01-14 10:58:44 +0000
committerRaphael Collet <rco@odoo.com>2019-02-13 10:43:50 +0000
commitcbdc8d864b2fe97d8de83fc7c8e13fdea779d00a (patch)
treefbf34aa262bd64ea1914850f308b56dc3c3f6875 /odoo/fields.py
parent44b791f5d75ea07383dd1f4ab73b41945d834b88 (diff)
[FIX] fields: read/write company-dependent fields without ir.property access
This is the first step to a more comprehensive handling of company-dependent fields which are ir_properties. With model-specific access rights, users should be able to read/update a company-dependent field no matter their access rights on ir_property. Before this commit, a user having access to res.partner, but not to ir.property couldn't write on property_account_receivable/payable just because he couldn't write the corresponding ir.property. After this commit, he can. OPW 1923345
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index 36d815215ff..4a41b4c4915 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -636,13 +636,25 @@ class Field(MetaField('DummyField', (object,), {})):
return model.env['ir.property'].get(self.name, self.model_name)
def _compute_company_dependent(self, records):
- Property = records.env['ir.property']
+ # read property as superuser, as the current user may not have access
+ context = records.env.context
+ if 'force_company' not in context:
+ field_id = records.env['ir.model.fields']._get_id(self.model_name, self.name)
+ company = records.env['res.company']._company_default_get(self.model_name, field_id)
+ context = dict(context, force_company=company.id)
+ Property = records.env(user=SUPERUSER_ID, context=context)['ir.property']
values = Property.get_multi(self.name, self.model_name, records.ids)
for record in records:
record[self.name] = values.get(record.id)
def _inverse_company_dependent(self, records):
- Property = records.env['ir.property']
+ # update property as superuser, as the current user may not have access
+ context = records.env.context
+ if 'force_company' not in context:
+ field_id = records.env['ir.model.fields']._get_id(self.model_name, self.name)
+ company = records.env['res.company']._company_default_get(self.model_name, field_id)
+ context = dict(context, force_company=company.id)
+ Property = records.env(user=SUPERUSER_ID, context=context)['ir.property']
values = {
record.id: self.convert_to_write(record[self.name], record)
for record in records