Skip to content

Commit c4f7a86

Browse files
yvaucherhbrunn
authored andcommitted
[MGR] configuration_helper
* [PORT] [9.0] configuration_helper Port to API 8.0 and make it compatible with a config definition in API 8.0. Remove some hacks with onchange and write to get and set the related values. * Add a module to define classes in order to test configuration_helper
1 parent 5b78140 commit c4f7a86

File tree

12 files changed

+250
-217
lines changed

12 files changed

+250
-217
lines changed

configuration_helper/README.rst

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
====================
6+
Configuration Helper
7+
====================
8+
9+
*This module is intended for developer only. It does nothing used alone.*
10+
11+
It helps to create `config.settings` by providing an abstract Class.
12+
13+
This class:
14+
15+
* creates automatically related fields in 'whatiwant.config.settings'
16+
using those defined in 'res.company': it avoids duplicated field definitions.
17+
* company_id field with default value is created
18+
* onchange_company_id is defined to update all related fields
19+
* supported fields: char, text, integer, float, datetime, date, boolean, m2o
20+
21+
22+
How to use
23+
----------
24+
25+
.. code-block:: python
26+
27+
from . company import ResCompany
28+
29+
class WhatiwantClassSettings(orm.TransientModel):
30+
_inherit = ['res.config.settings', 'abstract.config.settings']
31+
_name = 'whatiwant.config.settings'
32+
# fields must be defined in ResCompany class
33+
# related fields are automatically generated from previous definitions
34+
_companyObject = ResCompany
35+
# all prefixed field with _prefix in res.company, will be available in 'whatiwant.config.settings' model
36+
_prefix = 'prefixyouchoose_'
37+
38+
39+
Roadmap
40+
-------
41+
* support (or check support) for these field types : o2m, m2m, reference, property, selection
42+
* automatically generate a default view for 'whatiwant.config.settings' (in --debug ?)
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues
48+
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
49+
check there if your issue has already been reported. If you spotted it first,
50+
help us smashing it by providing a detailed and welcomed feedback.
51+
52+
Contributors
53+
------------
54+
55+
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
56+
* David BEAL <david.beal@akretion.com>
57+
* Sébastien BEAU <sebastien.beau@akretion.com>

configuration_helper/__init__.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
1-
# -*- coding: utf-8 -*-
2-
##############################################################################
3-
#
4-
# Author: David BEAL
5-
# Copyright 2014 Akretion
6-
#
7-
# This program is free software: you can redistribute it and/or modify
8-
# it under the terms of the GNU Affero General Public License as
9-
# published by the Free Software Foundation, either version 3 of the
10-
# License, or (at your option) any later version.
11-
#
12-
# This program is distributed in the hope that it will be useful,
13-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
# GNU Affero General Public License for more details.
16-
#
17-
# You should have received a copy of the GNU Affero General Public License
18-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19-
#
20-
##############################################################################
21-
22-
from . import config # noqa
1+
from . import models

configuration_helper/__openerp__.py

+17-81
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
##############################################################################
3-
#
4-
# Author: David BEAL
5-
# Copyright 2014 Akretion
6-
#
7-
# This program is free software: you can redistribute it and/or modify
8-
# it under the terms of the GNU Affero General Public License as
9-
# published by the Free Software Foundation, either version 3 of the
10-
# License, or (at your option) any later version.
11-
#
12-
# This program is distributed in the hope that it will be useful,
13-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
# GNU Affero General Public License for more details.
16-
#
17-
# You should have received a copy of the GNU Affero General Public License
18-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19-
#
20-
##############################################################################
21-
22-
{
23-
'name': 'Configuration Helper',
24-
'version': '0.8',
25-
'author': "Akretion,Odoo Community Association (OCA)",
26-
'maintainer': 'Akretion',
27-
'category': 'server',
28-
'complexity': 'normal',
29-
'depends': ['base'],
30-
'description': """
31-
Configuration Helper
32-
====================
33-
34-
*This module is intended for developer only. It does nothing used alone.*
35-
36-
This module :
37-
38-
* create automatically related fields in 'whatiwant.config.settings'
39-
using those defined in 'res.company' : it avoid duplicated field definitions.
40-
* company_id field with default value is created
41-
* onchange_company_id is defined to update all related fields
42-
* supported fields: char, text, integer, float, datetime, date, boolean, m2o
43-
44-
45-
How to use
46-
----------
47-
48-
.. code-block:: python
49-
50-
from . company import ResCompany
51-
52-
class WhatiwantClassSettings(orm.TransientModel):
53-
_inherit = ['res.config.settings', 'abstract.config.settings']
54-
_name = 'whatiwant.config.settings'
55-
# fields must be defined in ResCompany class
56-
# related fields are automatically generated from previous definitions
57-
_companyObject = ResCompany
58-
59-
60-
Roadmap
61-
-------
62-
* support (or check support) for these field types : o2m, m2m, reference, property, selection
63-
* automatically generate a default view for 'whatiwant.config.settings' (in --debug ?)
64-
65-
66-
Contributors
67-
------------
68-
69-
* David BEAL <david.beal@akretion.com>
70-
* Sébastien BEAU <sebastien.beau@akretion.com>
71-
* Yannick Vaucher, Camptocamp, (code refactoring from his module 'delivery_carrier_label_postlogistics')
72-
73-
""",
74-
'website': 'http://www.akretion.com/',
75-
'data': [
76-
],
77-
'tests': [],
78-
'installable': False,
79-
'auto_install': False,
80-
'license': 'AGPL-3',
81-
'application': True,
82-
}
2+
# © 2014 David BEAL Akretion
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
{'name': 'Configuration Helper',
5+
'version': '9.0.1.0.0',
6+
'author': "Akretion,Odoo Community Association (OCA)",
7+
'maintainer': 'Akretion',
8+
'category': 'server',
9+
'complexity': 'normal',
10+
'depends': ['base'],
11+
'website': 'http://www.akretion.com/',
12+
'data': [],
13+
'tests': [],
14+
'installable': True,
15+
'auto_install': False,
16+
'license': 'AGPL-3',
17+
'application': False,
18+
}

configuration_helper/config.py

-114
This file was deleted.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import config

configuration_helper/models/config.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
# © 2014 David BEAL Akretion
3+
# © 2016 Yannick Vaucher (Camptocamp SA)
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
import re
6+
7+
from openerp import api, fields, models
8+
9+
10+
class AbstractConfigSettings(models.AbstractModel):
11+
_name = 'abstract.config.settings'
12+
_description = 'Abstract configuration settings'
13+
# prefix field name to differentiate fields in company with those in config
14+
_prefix = 'setting_'
15+
# this is the class name to import in your module
16+
# (it should be ResCompany or res_company, depends of your code)
17+
_companyObject = None
18+
_setup_extra_done = False
19+
20+
company_id = fields.Many2one(
21+
'res.company',
22+
'Company',
23+
required=True,
24+
default=lambda self: self.env.user.company_id
25+
)
26+
27+
def _filter_field(self, field_key):
28+
"""Inherit in your module to define for which company field
29+
you don't want have a matching related field"""
30+
return True
31+
32+
@api.model
33+
def _setup_base(self, partial):
34+
cls = type(self)
35+
super(AbstractConfigSettings, self)._setup_base(partial)
36+
if not self._companyObject:
37+
return
38+
if cls._setup_extra_done:
39+
return
40+
for field_key in cls._companyObject.__dict__.keys():
41+
field = cls._companyObject.__dict__[field_key]
42+
if isinstance(field, fields.Field):
43+
# allows to exclude some field
44+
if self._filter_field(field_key):
45+
# fields.agrs contains fields attributes
46+
kwargs = field.args.copy()
47+
kwargs['related'] = 'company_id.' + field_key
48+
field_key = re.sub('^' + self._prefix, '', field_key)
49+
self._add_field(field_key, field.new(**kwargs))
50+
cls._proper_fields = set(cls._fields)
51+
52+
self._add_inherited_fields()
53+
cls.pool.model_cache[cls.__bases__] = cls
54+
cls._setup_extra_done = True

test_configuration_helper/README.rst

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
============================
6+
Configuration Helper - TESTS
7+
============================
8+
9+
*This module is only intended to test configuration_helper module.*
10+
11+
Contributors
12+
------------
13+
14+
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
15+
16+
Maintainer
17+
----------
18+
19+
.. image:: https://odoo-community.org/logo.png
20+
:alt: Odoo Community Association
21+
:target: https://odoo-community.org
22+
23+
This module is maintained by the OCA.
24+
25+
OCA, or the Odoo Community Association, is a nonprofit organization whose
26+
mission is to support the collaborative development of Odoo features and
27+
promote its widespread use.
28+
29+
To contribute to this module, please visit https://odoo-community.org.
30+

test_configuration_helper/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

0 commit comments

Comments
 (0)