From 687966d57ab6ab11270dbff340f7ed736a214fb5 Mon Sep 17 00:00:00 2001 From: Carlos Incaser Date: Fri, 4 Dec 2015 19:12:24 +0100 Subject: [PATCH] [ADD][8.0] base_custom_info: Init develop --- base_custom_info/README.rst | 53 ++++++++++++++ base_custom_info/__init__.py | 6 ++ base_custom_info/__openerp__.py | 21 ++++++ base_custom_info/models/__init__.py | 6 ++ .../models/custom_info_template.py | 69 ++++++++++++++++++ .../views/custom_info_template_view.xml | 71 +++++++++++++++++++ 6 files changed, 226 insertions(+) create mode 100644 base_custom_info/README.rst create mode 100644 base_custom_info/__init__.py create mode 100644 base_custom_info/__openerp__.py create mode 100644 base_custom_info/models/__init__.py create mode 100644 base_custom_info/models/custom_info_template.py create mode 100644 base_custom_info/views/custom_info_template_view.xml diff --git a/base_custom_info/README.rst b/base_custom_info/README.rst new file mode 100644 index 000000000..5604e2a88 --- /dev/null +++ b/base_custom_info/README.rst @@ -0,0 +1,53 @@ +.. 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 + +================ +Base Custom Info +================ + +This module allow create custom fields in models without alter models +structures. + +Usage +===== + +To use this module, you need to: + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/186 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 +`here `_. + +Credits +======= + +Contributors +------------ + +* Rafael Blasco +* Carlos Dauden +* Sergio Teruel + +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 http://odoo-community.org. diff --git a/base_custom_info/__init__.py b/base_custom_info/__init__.py new file mode 100644 index 000000000..7fffa6f51 --- /dev/null +++ b/base_custom_info/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel +# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models \ No newline at end of file diff --git a/base_custom_info/__openerp__.py b/base_custom_info/__openerp__.py new file mode 100644 index 000000000..f9b4f68f4 --- /dev/null +++ b/base_custom_info/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel +# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + 'name': "Base Custom Info", + 'summary': "Add custom field in models", + 'category': 'Customize', + 'version': '8.0.1.0.0', + 'depends': [ + 'base', + ], + 'data': [ + ], + 'author': 'Antiun Ingeniería S.L., ' + 'Incaser Informatica S.L., ', + 'website': 'http://www.antiun.com', + 'license': 'AGPL-3', + 'installable': True, +} diff --git a/base_custom_info/models/__init__.py b/base_custom_info/models/__init__.py new file mode 100644 index 000000000..f523517ad --- /dev/null +++ b/base_custom_info/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel +# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import custom_info_template diff --git a/base_custom_info/models/custom_info_template.py b/base_custom_info/models/custom_info_template.py new file mode 100644 index 000000000..37fb7fc45 --- /dev/null +++ b/base_custom_info/models/custom_info_template.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel +# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, fields, models, _ + + +class CustomInfoTemplate(models.Model): + _name = "custom.info.template" + + name = fields.Char() + model_id = fields.Many2one(comodel_name='ir.model', string='Data Model') + info_ids = fields.One2many( + comodel_name='custom.info.template.line', + inverse_name='template_id', + string='Info') + + +class CustomInfoTemplateLine(models.Model): + _name = "custom.info.template.line" + + name = fields.Char() + template_id = fields.Many2one( + comodel_name='custom.info.template', + string='Template') + info_value_ids = fields.One2many( + comodel_name="custom.info.value", + inverse_name="custom_info_name_id", + string="Info Values") + + +class CustomInfoValue(models.Model): + _name = "custom.info.value" + _rec_name = 'value' + + model = fields.Char(select=True) + res_id = fields.Integer(select=True) + custom_info_name_id = fields.Many2one( + comodel_name='custom.info.template.line', + string='Info Name') + value = fields.Char() + + +class CustomInfo(models.AbstractModel): + _name = "custom.info" + + custom_info_template_id = fields.Many2one( + comodel_name='custom.info.template', + string='Info Template') + custom_info_ids = fields.One2many( + comodel_name='custom.info.value', + inverse_name='res_id', + domain=lambda self: [('model', '=', self._name)], + auto_join=True, + string='Custom Info') + + @api.onchange('custom_info_template_id') + def _onchange_custom_info_template_id(self): + if not self.custom_info_template_id: + self.custom_info_ids = False + else: + info_list = self.custom_info_ids.mapped('custom_info_name_id') + for info_name in self.custom_info_template_id.info_ids: + if info_name not in info_list: + self.custom_info_ids |= self.custom_info_ids.new({ + 'model': self._name, + 'custom_info_name_id': info_name.id, + }) diff --git a/base_custom_info/views/custom_info_template_view.xml b/base_custom_info/views/custom_info_template_view.xml new file mode 100644 index 000000000..660577421 --- /dev/null +++ b/base_custom_info/views/custom_info_template_view.xml @@ -0,0 +1,71 @@ + + + + + + base.custom.info.template.form + base.custom.info.template + +
+ + + + + + + + + + + + + +
+
+
+ + + base.custom.info.template.tree + base.custom.info.template + + + + + + + + + + + base.custom.info.template.line.form + base.custom.info.template.line + +
+ + + + + + + + + +
+
+
+ + + base.custom.info.value.tree + base.custom.info.value + + + + + + + + + + +
+