Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions configuration_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

====================
Configuration Helper
====================

*This module is intended for developer only. It does nothing used alone.*

It helps to create `config.settings` by providing an abstract Class.

This class:

* creates automatically related fields in 'whatiwant.config.settings'
using those defined in 'res.company': it avoids duplicated field definitions.
* company_id field with default value is created
* onchange_company_id is defined to update all related fields
* supported fields: char, text, integer, float, datetime, date, boolean, m2o


How to use
----------

.. code-block:: python

from . company import ResCompany

class WhatiwantClassSettings(orm.TransientModel):
_inherit = ['res.config.settings', 'abstract.config.settings']
_name = 'whatiwant.config.settings'
# fields must be defined in ResCompany class
# related fields are automatically generated from previous definitions
_companyObject = ResCompany

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing:

# all prefixed field with _prefix in res.company, will be available in 'whatiwant.config.settings' model
_prefix = 'prefixyouchoose_'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# all prefixed field with _prefix in res.company, will be available in 'whatiwant.config.settings' model
_prefix = 'prefixyouchoose_'


Roadmap
-------
* support (or check support) for these field types : o2m, m2m, reference, property, selection
* automatically generate a default view for 'whatiwant.config.settings' (in --debug ?)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Contributors
------------

* Yannick Vaucher <yannick.vaucher@camptocamp.com>
* David BEAL <david.beal@akretion.com>
* Sébastien BEAU <sebastien.beau@akretion.com>
23 changes: 1 addition & 22 deletions configuration_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: David BEAL
# Copyright 2014 Akretion
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import config # noqa
from . import models
98 changes: 17 additions & 81 deletions configuration_helper/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,18 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: David BEAL
# Copyright 2014 Akretion
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
'name': 'Configuration Helper',
'version': '0.8',
'author': "Akretion,Odoo Community Association (OCA)",
'maintainer': 'Akretion',
'category': 'server',
'complexity': 'normal',
'depends': ['base'],
'description': """
Configuration Helper
====================

*This module is intended for developer only. It does nothing used alone.*

This module :

* create automatically related fields in 'whatiwant.config.settings'
using those defined in 'res.company' : it avoid duplicated field definitions.
* company_id field with default value is created
* onchange_company_id is defined to update all related fields
* supported fields: char, text, integer, float, datetime, date, boolean, m2o


How to use
----------

.. code-block:: python

from . company import ResCompany

class WhatiwantClassSettings(orm.TransientModel):
_inherit = ['res.config.settings', 'abstract.config.settings']
_name = 'whatiwant.config.settings'
# fields must be defined in ResCompany class
# related fields are automatically generated from previous definitions
_companyObject = ResCompany


Roadmap
-------
* support (or check support) for these field types : o2m, m2m, reference, property, selection
* automatically generate a default view for 'whatiwant.config.settings' (in --debug ?)


Contributors
------------

* David BEAL <david.beal@akretion.com>
* Sébastien BEAU <sebastien.beau@akretion.com>
* Yannick Vaucher, Camptocamp, (code refactoring from his module 'delivery_carrier_label_postlogistics')

""",
'website': 'http://www.akretion.com/',
'data': [
],
'tests': [],
'installable': False,
'auto_install': False,
'license': 'AGPL-3',
'application': True,
}
# © 2014 David BEAL Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{'name': 'Configuration Helper',
'version': '9.0.1.0.0',
'author': "Akretion,Odoo Community Association (OCA)",
'maintainer': 'Akretion',
'category': 'server',
'complexity': 'normal',
'depends': ['base'],
'website': 'http://www.akretion.com/',
'data': [],
'tests': [],
'installable': True,
'auto_install': False,
'license': 'AGPL-3',
'application': False,
}
114 changes: 0 additions & 114 deletions configuration_helper/config.py

This file was deleted.

1 change: 1 addition & 0 deletions configuration_helper/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import config
54 changes: 54 additions & 0 deletions configuration_helper/models/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# © 2014 David BEAL Akretion
# © 2016 Yannick Vaucher (Camptocamp SA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re

from openerp import api, fields, models


class AbstractConfigSettings(models.AbstractModel):
_name = 'abstract.config.settings'
_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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a mixedCase suddenly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it was already there, so at least only to keep compatibility.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can break compatibility here to become cleaner, no problem between versions.
There was no version for V8, only v7.

_setup_extra_done = False

company_id = fields.Many2one(
'res.company',
'Company',
required=True,
default=lambda self: self.env.user.company_id
)

def _filter_field(self, field_key):
"""Inherit in your module to define for which company field
you don't want have a matching related field"""
return True

@api.model
def _setup_base(self, partial):
cls = type(self)
super(AbstractConfigSettings, self)._setup_base(partial)
if not self._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))
cls._proper_fields = set(cls._fields)

self._add_inherited_fields()
cls.pool.model_cache[cls.__bases__] = cls
cls._setup_extra_done = True
30 changes: 30 additions & 0 deletions test_configuration_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

============================
Configuration Helper - TESTS
============================

*This module is only intended to test configuration_helper module.*

Contributors
------------

* Yannick Vaucher <yannick.vaucher@camptocamp.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.

1 change: 1 addition & 0 deletions test_configuration_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Loading