diff --git a/base_custom_info/README.rst b/base_custom_info/README.rst new file mode 100644 index 000000000..14f3b5a90 --- /dev/null +++ b/base_custom_info/README.rst @@ -0,0 +1,95 @@ +.. 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 allows to create custom fields in models without altering model's +structure. + +Installation +============ + +This module serves as a base for other modules that implement this behavior in +concrete models. + +This module is a technical dependency and is to be installed in parallel to +other modules. + +Usage +===== + +This module defines *Custom Info Templates* that define what properties are +expected for a given record. + +To define a template, you need to: + +* Go to *Settings > Custom Info > Templates*. +* Create one. +* Add some *Properties* to it. + +All database records with that template enabled will automatically fill those +properties. + +To manage the properties, you need to: + +* Go to *Settings > Custom Info > Properties*. + +To manage their values, you need to: + +* Go to *Settings > Custom Info > Values*. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/135/8.0 + +Development +=========== + +To create a module that supports custom information, just depend on this module +and inherit from the ``custom.info`` model. + +Known issues / Roadmap +====================== + +* All data types of custom information values are text strings. + +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 +`_. + +Credits +======= + +Contributors +------------ + +* Rafael Blasco +* Carlos Dauden +* Sergio Teruel +* Jairo Llopis + +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. diff --git a/base_custom_info/__init__.py b/base_custom_info/__init__.py new file mode 100644 index 000000000..5faa0139b --- /dev/null +++ b/base_custom_info/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingeniería S.L. - Sergio Teruel +# © 2015 Antiun Ingeniería S.L. - Carlos Dauden +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models diff --git a/base_custom_info/__openerp__.py b/base_custom_info/__openerp__.py new file mode 100644 index 000000000..79982b965 --- /dev/null +++ b/base_custom_info/__openerp__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingeniería S.L. - Sergio Teruel +# © 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + 'name': "Base Custom Info", + 'summary': "Add custom field in models", + 'category': 'Tools', + 'version': '8.0.1.0.0', + 'depends': [ + 'base', + ], + 'data': [ + 'views/custom_info_template_view.xml', + 'views/custom_info_property_view.xml', + 'views/custom_info_value_view.xml', + 'views/menu.xml', + 'security/ir.model.access.csv', + ], + "images": [ + "images/menu.png", + "images/properties.png", + "images/templates.png", + "images/values.png", + ], + 'author': 'Antiun Ingeniería S.L., ' + 'Incaser Informatica S.L., ' + 'Odoo Community Association (OCA)', + 'website': 'http://www.antiun.com', + 'license': 'AGPL-3', + 'installable': True, +} diff --git a/base_custom_info/i18n/es.po b/base_custom_info/i18n/es.po new file mode 100644 index 000000000..4e14ddb37 --- /dev/null +++ b/base_custom_info/i18n/es.po @@ -0,0 +1,198 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_custom_info +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-12-15 17:10+0100\n" +"PO-Revision-Date: 2015-12-15 17:12+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.5\n" + +#. module: base_custom_info +#: model:ir.actions.act_window,help:base_custom_info.custom_info_template_action +msgid "" +"

\n" +" Click to define a new custom info template.\n" +"

\n" +" You must define a custom info template for each\n" +" product properties group.\n" +"

\n" +" " +msgstr "" +"

\n" +"Pulsa para definir una nueva plantilla de información personalizada.\n" +"

\n" +"Debe definir una plantilla de información personalizada para cada diferente grupo de propiedades.\n" +"

" + +#. module: base_custom_info +#: sql_constraint:custom.info.value:0 +msgid "Another property with that name exists for that resource." +msgstr "Ya existe otra propiedad con ese nombre para ese recurso." + +#. module: base_custom_info +#: sql_constraint:custom.info.property:0 +msgid "Another property with that name exists for that template." +msgstr "Ya existe otra propiedad con ese nombre en esa plantilla." + +#. module: base_custom_info +#: sql_constraint:custom.info.template:0 +msgid "Another template with that name exists for that model." +msgstr "Ya existe otra plantilla con ese nombre para ese modelo." + +#. module: base_custom_info +#: field:custom.info.property,create_uid:0 +#: field:custom.info.template,create_uid:0 +#: field:custom.info.value,create_uid:0 +msgid "Created by" +msgstr "Creado por" + +#. module: base_custom_info +#: field:custom.info.property,create_date:0 +#: field:custom.info.template,create_date:0 +#: field:custom.info.value,create_date:0 +msgid "Created on" +msgstr "Creado el" + +#. module: base_custom_info +#: model:ir.ui.menu,name:base_custom_info.menu_base_custom_info +msgid "Custom Info" +msgstr "Información personalizada" + +#. module: base_custom_info +#: view:custom.info.template:base_custom_info.base_custom_info_template_form +msgid "Custom Info Template" +msgstr "Plantilla de información personalizada" + +#. module: base_custom_info +#: view:custom.info.property:base_custom_info.base_custom_info_template_line_form +msgid "Custom Info Template Properties" +msgstr "Propiedades de la plantilla de información personalizada" + +#. module: base_custom_info +#: view:custom.info.property:base_custom_info.base_custom_info_template_line_tree +#: view:custom.info.template:base_custom_info.base_custom_info_template_tree +msgid "Custom Info Templates" +msgstr "Plantillas de información personalizada" + +#. module: base_custom_info +#: field:custom.info,custom_info_template_id:0 +msgid "Custom Information Template" +msgstr "Plantilla de información personalizada" + +#. module: base_custom_info +#: field:custom.info,custom_info_ids:0 +msgid "Custom Properties" +msgstr "Propiedades personalizadas" + +#. module: base_custom_info +#: view:custom.info.value:base_custom_info.base_custom_info_value_tree +msgid "Custom Property Values" +msgstr "Valores de las propiedades personalizadas" + +#. module: base_custom_info +#: model:ir.model,name:base_custom_info.model_custom_info_property +msgid "Custom information property" +msgstr "Propiedad de información personalizada" + +#. module: base_custom_info +#: model:ir.model,name:base_custom_info.model_custom_info_template +msgid "Custom information template" +msgstr "Plantilla de información personalizada" + +#. module: base_custom_info +#: model:ir.model,name:base_custom_info.model_custom_info_value +msgid "Custom information value" +msgstr "Valor de información personalizada" + +#. module: base_custom_info +#: field:custom.info,id:0 field:custom.info.property,id:0 +#: field:custom.info.template,id:0 field:custom.info.value,id:0 +msgid "ID" +msgstr "ID" + +#. module: base_custom_info +#: view:custom.info.template:base_custom_info.base_custom_info_template_form +msgid "Info Lines" +msgstr "Líneas de información" + +#. module: base_custom_info +#: model:ir.model,name:base_custom_info.model_custom_info +msgid "Inheritable abstract model to add custom info in any model" +msgstr "Modelo abstracto que se puede heredar para añadir información personalizada a cualquier modelo" + +#. module: base_custom_info +#: field:custom.info.property,write_uid:0 +#: field:custom.info.template,write_uid:0 field:custom.info.value,write_uid:0 +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: base_custom_info +#: field:custom.info.property,write_date:0 +#: field:custom.info.template,write_date:0 +#: field:custom.info.value,write_date:0 +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: base_custom_info +#: field:custom.info.template,model_id:0 field:custom.info.value,model:0 +msgid "Model" +msgstr "Modelo" + +#. module: base_custom_info +#: field:custom.info.property,name:0 field:custom.info.template,name:0 +msgid "Name" +msgstr "Nombre" + +#. module: base_custom_info +#: field:custom.info.template,info_ids:0 +#: model:ir.actions.act_window,name:base_custom_info.custom_info_template_line_action +#: model:ir.ui.menu,name:base_custom_info.menu_base_custom_info_template_line +msgid "Properties" +msgstr "Propiedades" + +#. module: base_custom_info +#: field:custom.info.value,property_id:0 +msgid "Property" +msgstr "Propiedad" + +#. module: base_custom_info +#: field:custom.info.property,info_value_ids:0 +msgid "Property Values" +msgstr "Valor de la propiedad" + +#. module: base_custom_info +#: field:custom.info.value,res_id:0 +msgid "Resource ID" +msgstr "ID del recurso" + +#. module: base_custom_info +#: field:custom.info.property,template_id:0 +msgid "Template" +msgstr "Plantilla" + +#. module: base_custom_info +#: model:ir.actions.act_window,name:base_custom_info.custom_info_template_action +#: model:ir.ui.menu,name:base_custom_info.menu_base_custom_info_template +msgid "Templates" +msgstr "Plantillas" + +#. module: base_custom_info +#: field:custom.info.value,value:0 +msgid "Value" +msgstr "Valor" + +#. module: base_custom_info +#: model:ir.actions.act_window,name:base_custom_info.custom_info_value_action +#: model:ir.ui.menu,name:base_custom_info.menu_base_custom_info_value +msgid "Values" +msgstr "Valores" diff --git a/base_custom_info/images/menu.png b/base_custom_info/images/menu.png new file mode 100644 index 000000000..08fb79050 Binary files /dev/null and b/base_custom_info/images/menu.png differ diff --git a/base_custom_info/images/properties.png b/base_custom_info/images/properties.png new file mode 100644 index 000000000..d6ae74d00 Binary files /dev/null and b/base_custom_info/images/properties.png differ diff --git a/base_custom_info/images/templates.png b/base_custom_info/images/templates.png new file mode 100644 index 000000000..515b86313 Binary files /dev/null and b/base_custom_info/images/templates.png differ diff --git a/base_custom_info/images/values.png b/base_custom_info/images/values.png new file mode 100644 index 000000000..f95eca7fd Binary files /dev/null and b/base_custom_info/images/values.png differ diff --git a/base_custom_info/models/__init__.py b/base_custom_info/models/__init__.py new file mode 100644 index 000000000..278faf2ff --- /dev/null +++ b/base_custom_info/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingeniería S.L. - Sergio Teruel +# © 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 diff --git a/base_custom_info/models/custom_info.py b/base_custom_info/models/custom_info.py new file mode 100644 index 000000000..883a4055c --- /dev/null +++ b/base_custom_info/models/custom_info.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingeniería S.L. - Sergio Teruel +# © 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 2015 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, fields, models + + +class CustomInfoModelLink(models.AbstractModel): + _description = "A model that gets its ``ir.model`` computed" + _name = "custom.info.model_link" + + model = fields.Char( + index=True, + readonly=True, + required=True) + model_id = fields.Many2one( + 'ir.model', + 'Model', + compute="_compute_model_id", + store=True) + + @api.multi + @api.depends("model") + def _compute_model_id(self): + """Get a related model from its name, for better UI.""" + for s in self: + s.model_id = self.env["ir.model"].search([("model", "=", s.model)]) + + +class CustomInfoTemplate(models.Model): + """Defines custom properties expected for a given database object.""" + _description = "Custom information template" + _name = "custom.info.template" + _inherit = "custom.info.model_link" + _sql_constraints = [ + ("name_model", + "UNIQUE (name, model)", + "Another template with that name exists for that model."), + ] + + name = fields.Char(required=True, translate=True) + info_ids = fields.One2many( + 'custom.info.property', + 'template_id', + 'Properties') + + +class CustomInfoProperty(models.Model): + """Name of the custom information property.""" + _description = "Custom information property" + _name = "custom.info.property" + _sql_constraints = [ + ("name_template", + "UNIQUE (name, template_id)", + "Another property with that name exists for that template."), + ] + + name = fields.Char(translate=True) + template_id = fields.Many2one( + comodel_name='custom.info.template', + string='Template') + info_value_ids = fields.One2many( + comodel_name="custom.info.value", + inverse_name="property_id", + string="Property Values") + + +class CustomInfoValue(models.Model): + _description = "Custom information value" + _name = "custom.info.value" + _inherit = "custom.info.model_link" + _rec_name = 'value' + _sql_constraints = [ + ("property_model_res", + "UNIQUE (property_id, model, res_id)", + "Another property with that name exists for that resource."), + ] + + res_id = fields.Integer("Resource ID", index=True, required=True) + property_id = fields.Many2one( + comodel_name='custom.info.property', + required=True, + string='Property') + name = fields.Char(related='property_id.name') + value = fields.Char(translate=True) + + +class CustomInfo(models.AbstractModel): + _description = "Inheritable abstract model to add custom info in any model" + _name = "custom.info" + + custom_info_template_id = fields.Many2one( + comodel_name='custom.info.template', + string='Custom Information 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 Properties') + + @api.multi + @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('property_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, + 'property_id': info_name.id, + "res_id": self.id, + }) + + @api.multi + def unlink(self): + info_values = self.mapped('custom_info_ids') + res = super(CustomInfo, self).unlink() + if res: + info_values.unlink() + return res diff --git a/base_custom_info/security/ir.model.access.csv b/base_custom_info/security/ir.model.access.csv new file mode 100644 index 000000000..d285e7021 --- /dev/null +++ b/base_custom_info/security/ir.model.access.csv @@ -0,0 +1,7 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_custom_info_template_user","custom.info.template.user","model_custom_info_template","base.group_user",1,0,0,0 +"access_custom_info_property_user","custom.info.template.line.user","model_custom_info_property","base.group_user",1,0,0,0 +"access_custom_info_value_user","custom.info.value.user","model_custom_info_value","base.group_user",1,0,0,0 +"access_custom_info_template_sale_manager","custom.info.template.salemanager","model_custom_info_template","base.group_system",1,1,1,1 +"access_custom_info_property_sale_manager","custom.info.template.line.salemanager","model_custom_info_property","base.group_system",1,1,1,1 +"access_custom_info_value_sale_manager","custom.info.value.salemanager","model_custom_info_value","base.group_system",1,1,1,1 diff --git a/base_custom_info/views/custom_info_property_view.xml b/base_custom_info/views/custom_info_property_view.xml new file mode 100644 index 000000000..81fcf0bc5 --- /dev/null +++ b/base_custom_info/views/custom_info_property_view.xml @@ -0,0 +1,43 @@ + + + + + + base.custom.info.property.tree + custom.info.property + + + + + + + + + + base.custom.info.property.form + custom.info.property + +
+ + + + + + + + + +
+
+
+ + + Properties + ir.actions.act_window + custom.info.property + tree,form + form + + +
+
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..ef81b7008 --- /dev/null +++ b/base_custom_info/views/custom_info_template_view.xml @@ -0,0 +1,60 @@ + + + + + + base.custom.info.template.tree + custom.info.template + + + + + + + + + + + + base.custom.info.template.form + custom.info.template + +
+ + + + + + + + + + + + + + +
+
+
+ + + Templates + ir.actions.act_window + custom.info.template + tree,form + form + + + +

+ Click to define a new custom info template. +

+ You must define a custom info template for each + product properties group. +

+
+
+ +
+
diff --git a/base_custom_info/views/custom_info_value_view.xml b/base_custom_info/views/custom_info_value_view.xml new file mode 100644 index 000000000..2c3c6f8a3 --- /dev/null +++ b/base_custom_info/views/custom_info_value_view.xml @@ -0,0 +1,27 @@ + + + + + + base.custom.info.value.tree + custom.info.value + + + + + + + + + + + + Values + ir.actions.act_window + custom.info.value + tree,form + form + + + + diff --git a/base_custom_info/views/menu.xml b/base_custom_info/views/menu.xml new file mode 100644 index 000000000..5cb61a2f3 --- /dev/null +++ b/base_custom_info/views/menu.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + +