mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 22:12:02 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -64,6 +64,12 @@ class _Relational(Field[BaseModel]):
|
|||
# a lot of missing records, just fetch that field
|
||||
remaining = records[len(vals):]
|
||||
remaining.fetch([self.name])
|
||||
# fetch does not raise MissingError, check value
|
||||
if record_id not in field_cache:
|
||||
raise MissingError("\n".join([
|
||||
env._("Record does not exist or has been deleted."),
|
||||
env._("(Record: %(record)s, User: %(user)s)", record=record_id, user=env.uid),
|
||||
])) from None
|
||||
else:
|
||||
remaining = records.__class__(env, (record_id,), records._prefetch_ids)
|
||||
super().__get__(remaining, owner)
|
||||
|
|
@ -870,7 +876,8 @@ class One2many(_RelationalMulti):
|
|||
# link self to its inverse field and vice-versa
|
||||
comodel = model.env[self.comodel_name]
|
||||
try:
|
||||
comodel._fields[self.inverse_name]
|
||||
field = comodel._fields[self.inverse_name]
|
||||
field.setup(comodel)
|
||||
except KeyError:
|
||||
raise ValueError(f"{self.inverse_name!r} declared in {self!r} does not exist on {comodel._name!r}.")
|
||||
|
||||
|
|
@ -1358,10 +1365,14 @@ class Many2many(_RelationalMulti):
|
|||
context.update(self.context)
|
||||
comodel = records.env[self.comodel_name].with_context(**context)
|
||||
|
||||
# bypass the access during search if method is overwriten to avoid
|
||||
# possibly filtering all records of the comodel before joining
|
||||
filter_access = self.bypass_search_access and type(comodel)._search is not BaseModel._search
|
||||
|
||||
# make the query for the lines
|
||||
domain = self.get_comodel_domain(records)
|
||||
try:
|
||||
query = comodel._search(domain, order=comodel._order)
|
||||
query = comodel._search(domain, order=comodel._order, bypass_access=filter_access)
|
||||
except AccessError as e:
|
||||
raise AccessError(records.env._("Failed to read field %s", self) + '\n' + str(e)) from e
|
||||
|
||||
|
|
@ -1378,6 +1389,16 @@ class Many2many(_RelationalMulti):
|
|||
for id1, id2 in records.env.execute_query(query.select(sql_id1, sql_id2)):
|
||||
group[id1].append(id2)
|
||||
|
||||
# filter using record rules
|
||||
if filter_access and group:
|
||||
corecord_ids = OrderedSet(id_ for ids in group.values() for id_ in ids)
|
||||
accessible_corecords = comodel.browse(corecord_ids)._filtered_access('read')
|
||||
if len(accessible_corecords) < len(corecord_ids):
|
||||
# some records are inaccessible, remove them from groups
|
||||
corecord_ids = set(accessible_corecords._ids)
|
||||
for id1, ids in group.items():
|
||||
group[id1] = [id_ for id_ in ids if id_ in corecord_ids]
|
||||
|
||||
# store result in cache
|
||||
values = [tuple(group[id_]) for id_ in records._ids]
|
||||
self._insert_cache(records, values)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue