Browse Source

[MIG] Update module to match V11 architecture

12.0-mig-module_prototyper_last
Patrick Tombez 6 years ago
committed by sebalix
parent
commit
f287670853
  1. 33
      configuration_helper/models/config.py

33
configuration_helper/models/config.py

@ -4,6 +4,7 @@
import re
from odoo import api, fields, models
from inspect import getmembers
class AbstractConfigSettings(models.AbstractModel):
@ -11,10 +12,6 @@ class AbstractConfigSettings(models.AbstractModel):
_description = 'Abstract configuration settings'
# prefix field name to differentiate fields in company with those in config
_prefix = 'setting_'
# this is the class name to import in your module
# (it should be ResCompany or res_company, depends of your code)
_companyObject = None
_setup_extra_done = False
company_id = fields.Many2one(
'res.company',
@ -32,22 +29,20 @@ class AbstractConfigSettings(models.AbstractModel):
def _setup_base(self):
cls = type(self)
super(AbstractConfigSettings, self)._setup_base()
if not cls._companyObject:
return
if cls._setup_extra_done:
return
for field_key in cls._companyObject.__dict__.keys():
field = cls._companyObject.__dict__[field_key]
if isinstance(field, fields.Field):
# allows to exclude some field
if self._filter_field(field_key):
# fields.agrs contains fields attributes
kwargs = field.args.copy()
kwargs['related'] = 'company_id.' + field_key
field_key = re.sub('^' + self._prefix, '', field_key)
self._add_field(field_key, field.new(**kwargs))
comp_fields = filter(
lambda f: (f[0].startswith(self._prefix) and
self._filter_field(f[0])),
getmembers(type(self.env['res.company']),
fields.Field.__instancecheck__)
)
for field_key, field in comp_fields:
kwargs = field.args.copy()
kwargs['related'] = 'company_id.' + field_key
field_key = re.sub('^' + self._prefix, '', field_key)
self._add_field(field_key, field.new(**kwargs))
cls._proper_fields = set(cls._fields)
self._add_inherited_fields()
cls.pool.model_cache[cls.__bases__] = cls
cls._setup_extra_done = True
Loading…
Cancel
Save