mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[11.0][IMP] child_selection_clear
This commit is contained in:
@@ -1,38 +1,31 @@
|
||||
# Copyright 2019 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, _
|
||||
from odoo import models
|
||||
|
||||
|
||||
class Base(models.AbstractModel):
|
||||
_inherit = 'base'
|
||||
|
||||
def get_record_parent(self):
|
||||
self.ensure_one()
|
||||
if not hasattr(self, self._parent_name):
|
||||
return False
|
||||
parent = getattr(self, self._parent_name)
|
||||
if not parent:
|
||||
return False
|
||||
return parent.name_get()[0]
|
||||
|
||||
def _get_record_parents(self, field):
|
||||
if not self:
|
||||
return [(False, _('Root'))]
|
||||
return []
|
||||
return getattr(
|
||||
self, self._parent_name
|
||||
)._get_record_parents(field) + [(self.id, str(getattr(self, field)))]
|
||||
|
||||
def _get_record_direct_childs(self, field):
|
||||
def _get_record_direct_childs(self, field, domain):
|
||||
if not hasattr(self, self._parent_name):
|
||||
return []
|
||||
return [(r.id, str(getattr(r, field))) for r in self.search([(
|
||||
self._parent_name, '=', self.id or False
|
||||
)])]
|
||||
)] + domain)]
|
||||
|
||||
def get_record_direct_childs_parents(self, options):
|
||||
def get_record_direct_childs_parents(self, options, domain=False):
|
||||
if not domain:
|
||||
domain = []
|
||||
field = options.get('child_selection_field', 'display_name')
|
||||
return {
|
||||
'childs': self._get_record_direct_childs(field),
|
||||
'childs': self._get_record_direct_childs(field, domain),
|
||||
'parents': self._get_record_parents(field)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user