Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
d3435ca279
  1. 2
      muk_utils/__manifest__.py
  2. 2
      muk_utils/models/base.py
  3. 29
      muk_utils/models/mixins_hierarchy.py

2
muk_utils/__manifest__.py

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

2
muk_utils/models/base.py

@ -42,7 +42,7 @@ class Base(models.AbstractModel):
def _build_search_childs_domain(self, parent_id, domain=[]): def _build_search_childs_domain(self, parent_id, domain=[]):
self._check_parent_field() self._check_parent_field()
parent_domain = [[self._parent_name, '=', parent_id]] parent_domain = [[self._parent_name, '=', parent_id]]
return expression.AND(parent_domain, domain) if domain else parent_domain
return expression.AND([parent_domain, domain]) if domain else parent_domain
#---------------------------------------------------------- #----------------------------------------------------------
# Security # Security

29
muk_utils/models/mixins_hierarchy.py

@ -23,6 +23,7 @@ import functools
import collections import collections
from odoo import models, fields, api from odoo import models, fields, api
from odoo.osv import expression
class Hierarchy(models.AbstractModel): class Hierarchy(models.AbstractModel):
@ -49,10 +50,10 @@ class Hierarchy(models.AbstractModel):
self._add_field(name, field) self._add_field(name, field)
path_names_search = None path_names_search = None
if not self._parent_path_store: if not self._parent_path_store:
path_names_search = '_search_parent_path_names',
path_names_search = '_search_parent_path_names'
add('parent_path_names', fields.Char( add('parent_path_names', fields.Char(
_module=self._module, _module=self._module,
compute='_compute_parent_path',
compute='_compute_parent_paths',
compute_sudo=self._parent_path_sudo, compute_sudo=self._parent_path_sudo,
store=self._parent_path_store, store=self._parent_path_store,
search=path_names_search, search=path_names_search,
@ -61,13 +62,27 @@ class Hierarchy(models.AbstractModel):
automatic=True)) automatic=True))
add('parent_path_json', fields.Text( add('parent_path_json', fields.Text(
_module=self._module, _module=self._module,
compute='_compute_parent_path',
compute='_compute_parent_paths',
compute_sudo=self._parent_path_sudo, compute_sudo=self._parent_path_sudo,
store=self._parent_path_store, store=self._parent_path_store,
string="Path Json", string="Path Json",
readonly=True, readonly=True,
automatic=True)) automatic=True))
#----------------------------------------------------------
# Helper
#----------------------------------------------------------
def _get_depends_parent_paths(self):
depends = ['parent_path']
if self._rec_name:
depends += [self._rec_name]
elif 'name' in self._fields:
depends += ['name']
elif 'x_name' in self._fields:
depends += ['x_name']
return depends
#---------------------------------------------------------- #----------------------------------------------------------
# Search # Search
#---------------------------------------------------------- #----------------------------------------------------------
@ -77,15 +92,15 @@ class Hierarchy(models.AbstractModel):
domain = [] domain = []
for value in operand.split('/'): for value in operand.split('/'):
args = [(self._rec_name_fallback(), operator, value)] args = [(self._rec_name_fallback(), operator, value)]
domain = expression.OR(args, domain) if domain else args
return domain
domain = expression.OR([args, domain]) if domain else args
return domain if domain else [(self._rec_name_fallback(), operator, "")]
#---------------------------------------------------------- #----------------------------------------------------------
# Read, View # Read, View
#---------------------------------------------------------- #----------------------------------------------------------
@api.depends('parent_path')
def _compute_parent_path(self):
@api.depends(lambda self: self._get_depends_parent_paths())
def _compute_parent_paths(self):
records = self.filtered(lambda record: record.parent_path) records = self.filtered(lambda record: record.parent_path)
paths = [list(map(int, rec.parent_path.split('/')[:-1])) for rec in records] paths = [list(map(int, rec.parent_path.split('/')[:-1])) for rec in records]
ids = paths and set(functools.reduce(operator.concat, paths)) or [] ids = paths and set(functools.reduce(operator.concat, paths)) or []

Loading…
Cancel
Save