|
@ -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 [] |
|
|