mirror of https://github.com/OCA/web.git
[11.0][IMP] Add tests
parent
d3fbfc9a35
commit
ab363b7af2
|
@ -8,7 +8,7 @@ class Base(models.AbstractModel):
|
|||
_inherit = 'base'
|
||||
|
||||
def _get_record_parents(self, field):
|
||||
if not self:
|
||||
if not self or not hasattr(self, self._parent_name):
|
||||
return []
|
||||
return getattr(
|
||||
self, self._parent_name
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
* Enric Tobella <etobella@creublanca.es>
|
||||
* Jaime Arroyo <jaime.arroyo@creublanca.es>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
from . import test_widget_child_selector
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2019 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestWidgetChildSelector(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.partner_1 = self.env['res.partner'].create({'name': 'P1'})
|
||||
self.partner_2 = self.env['res.partner'].create({
|
||||
'name': 'P2',
|
||||
'parent_id': self.partner_1.id
|
||||
})
|
||||
self.partner_3 = self.env['res.partner'].create({
|
||||
'name': 'P3',
|
||||
'parent_id': self.partner_2.id
|
||||
})
|
||||
# Model that doesnt have the parent/child structure
|
||||
self.group = self.env['res.groups'].create({
|
||||
'name': 'Group'
|
||||
})
|
||||
|
||||
def test_widget_child_selector(self):
|
||||
res = self.partner_2.get_record_direct_childs_parents(
|
||||
{'child_selection_field': 'name'}
|
||||
)
|
||||
self.assertIn((self.partner_1.id, self.partner_1.name), res['parents'])
|
||||
self.assertIn((self.partner_3.id, self.partner_3.name), res['childs'])
|
||||
res = self.group.get_record_direct_childs_parents({})
|
||||
self.assertFalse(res['parents'])
|
||||
self.assertFalse(res['childs'])
|
Loading…
Reference in New Issue