Browse Source

publish muk_utils - 12.0

pull/30/head
MuK IT GmbH 6 years ago
parent
commit
1145933202
  1. 2
      muk_utils/__manifest__.py
  2. 32
      muk_utils/models/mixins_hierarchy.py

2
muk_utils/__manifest__.py

@ -19,7 +19,7 @@
{
"name": "MuK Utils",
"summary": """Utility Features""",
"version": '12.0.1.6.11',
"version": '12.0.1.6.13',
"category": 'Extra Tools',
"license": "AGPL-3",
"author": "MuK IT",

32
muk_utils/models/mixins_hierarchy.py

@ -34,6 +34,8 @@ class Hierarchy(models.AbstractModel):
_parent_path_sudo = False
_parent_path_store = False
_name_path_context = "show_path"
#----------------------------------------------------------
# Database
#----------------------------------------------------------
@ -104,7 +106,9 @@ class Hierarchy(models.AbstractModel):
records = self.filtered(lambda record: record.parent_path)
paths = [list(map(int, rec.parent_path.split('/')[:-1])) for rec in records]
ids = paths and set(functools.reduce(operator.concat, paths)) or []
data = dict(self.browse(ids)._filter_access('read').name_get())
model_without_path = self.with_context(**{self._name_path_context: False})
filtered_records = model_without_path._filter_access('read').browse(ids)
data = dict(filtered_records.name_get())
for record in records:
path_names = [""]
path_json = []
@ -124,6 +128,32 @@ class Hierarchy(models.AbstractModel):
'parent_path_json': json.dumps(path_json),
})
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
domain = list(args or [])
if not (name == '' and operator == 'ilike') :
if '/' in name:
domain += [('parent_path_names', operator, name)]
else:
domain += [(self._rec_name, operator, name)]
records = self.browse(self._search(domain, limit=limit, access_rights_uid=name_get_uid))
return models.lazy_name_get(records.sudo(name_get_uid or self.env.uid))
@api.multi
def name_get(self):
if self.env.context.get(self._name_path_context):
res = []
for record in self:
names = record.parent_path_names
if not names:
res.append(super(Hierarchy, record).name_get()[0])
elif not len(names) > 50:
res.append((record.id, names))
else:
res.append((record.id, ".." + names[-48:]))
return res
return super(Hierarchy, self).name_get()
#----------------------------------------------------------
# Create, Update, Delete
#----------------------------------------------------------

Loading…
Cancel
Save