summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-05-31 14:35:21 +0000
committerRaphael Collet <rco@odoo.com>2019-06-03 12:37:39 +0000
commitb415da5daacd51e1fec39b29a91ce2a715b0f193 (patch)
treeaad23cc373f353249733c99632a356ec2e3785fc /odoo/fields.py
parent0d88571faae0627e316c96cfb0e8f58f9aebd3c5 (diff)
[IMP] fields: add method to get a usable domain from a field
closes odoo/odoo#33816 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index 8baf2fa2edd..222d42a3cda 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -2070,6 +2070,13 @@ class _Relational(Field):
_logger.warning("Field %s with unknown comodel_name %r", self, self.comodel_name)
self.comodel_name = '_unknown'
+ def get_domain_list(self, model):
+ """ Return a list domain from the domain parameter. """
+ domain = self.domain
+ if callable(domain):
+ domain = domain(model)
+ return domain if isinstance(domain, list) else []
+
@property
def _related_domain(self):
if callable(self.domain):
@@ -2493,8 +2500,7 @@ class One2many(_RelationalMulti):
comodel = records.env[self.comodel_name].with_context(**self.context)
inverse = self.inverse_name
get_id = (lambda rec: rec.id) if comodel._fields[inverse].type == 'many2one' else int
- domain = self.domain(records) if callable(self.domain) else self.domain
- domain = domain + [(inverse, 'in', records.ids)]
+ domain = self.get_domain_list(records) + [(inverse, 'in', records.ids)]
lines = comodel.search(domain, limit=self.limit)
# group lines by inverse field (without prefetching other fields)
@@ -2568,8 +2574,7 @@ class One2many(_RelationalMulti):
elif act[0] in (5, 6):
flush()
ids = act[2] if act[0] == 6 else []
- domain = self.domain(model) if callable(self.domain) else self.domain
- domain = domain + [(inverse, 'in', records.ids)]
+ domain = self.get_domain_list(model) + [(inverse, 'in', records.ids)]
if ids:
domain = domain + [('id', 'not in', ids)]
unlink(comodel.search(domain)._ids)
@@ -2726,11 +2731,7 @@ class Many2many(_RelationalMulti):
def read(self, records):
comodel = records.env[self.comodel_name].with_context(**self.context)
-
- # String domains are supposed to be dynamic and evaluated on client-side
- # only (thus ignored here).
- domain = self.domain if isinstance(self.domain, list) else []
-
+ domain = self.get_domain_list(records)
wquery = comodel._where_calc(domain)
comodel._apply_ir_rules(wquery, 'read')
order_by = comodel._generate_order_by(None, wquery)