[IMP] tools: add DotDict helper
This function allow a quck dot.notation access to dictionary attributes We need to make it re-usable for a future enterprise commit
This commit is contained in:
@@ -6,6 +6,7 @@ except ImportError:
|
||||
from mock import patch
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import HttpCase, TransactionCase
|
||||
from odoo.tools import DotDict
|
||||
|
||||
''' /!\/!\
|
||||
Calling `get_pricelist_available` after setting `property_product_pricelist` on
|
||||
@@ -157,13 +158,6 @@ def simulate_frontend_context(self, website_id=1):
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
|
||||
class DotDict(dict):
|
||||
"""dot.notation access to dictionary attributes"""
|
||||
def __getattr__(*args):
|
||||
val = dict.get(*args)
|
||||
return DotDict(val) if type(val) is dict else val
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestWebsitePriceListAvailable(TransactionCase):
|
||||
# This is enough to avoid a mock (request.session/website do not exist during test)
|
||||
|
||||
@@ -1243,3 +1243,15 @@ def wrap_module(module, attr_list):
|
||||
raise AttributeError(attrib)
|
||||
# module and attr_list are in the closure
|
||||
return WrappedModule()
|
||||
|
||||
|
||||
class DotDict(dict):
|
||||
"""Helper for dot.notation access to dictionary attributes
|
||||
|
||||
E.g.
|
||||
foo = DotDict({'bar': False})
|
||||
return foo.bar
|
||||
"""
|
||||
def __getattr__(self, attrib):
|
||||
val = self.get(attrib)
|
||||
return DotDict(val) if type(val) is dict else val
|
||||
|
||||
Reference in New Issue
Block a user