From 821a8fd4f8de331e290d19e53973510255d8ec32 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 15 Dec 2015 17:16:06 +0100 Subject: [PATCH] Fix many bugs and styling, and prepare for OCA. --- base_custom_info/README.rst | 55 ++++- base_custom_info/__init__.py | 4 +- base_custom_info/__openerp__.py | 7 +- base_custom_info/i18n/es.po | 198 ++++++++++++++++++ base_custom_info/models/__init__.py | 4 +- base_custom_info/models/custom_info.py | 64 ++++-- base_custom_info/security/ir.model.access.csv | 14 +- ...view.xml => custom_info_property_view.xml} | 12 +- .../views/custom_info_template_view.xml | 2 +- .../views/custom_info_value_view.xml | 4 +- base_custom_info/views/menu.xml | 9 +- 11 files changed, 315 insertions(+), 58 deletions(-) create mode 100644 base_custom_info/i18n/es.po rename base_custom_info/views/{custom_info_template_line_view.xml => custom_info_property_view.xml} (73%) diff --git a/base_custom_info/README.rst b/base_custom_info/README.rst index 5604e2a88..24d634ed3 100644 --- a/base_custom_info/README.rst +++ b/base_custom_info/README.rst @@ -6,26 +6,62 @@ Base Custom Info ================ -This module allow create custom fields in models without alter models -structures. +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 means that you should **not** install this module by itself. If you found +it installed, it means probably that another module that needs it installed it. Usage ===== -To use this module, you need to: +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/186 + :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. 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 `_. +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 ======= @@ -36,6 +72,7 @@ Contributors * Rafael Blasco * Carlos Dauden * Sergio Teruel +* Jairo Llopis Maintainer ---------- @@ -50,4 +87,4 @@ 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. +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 index 7fffa6f51..16c96a10c 100644 --- a/base_custom_info/__init__.py +++ b/base_custom_info/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel -# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 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 \ No newline at end of file diff --git a/base_custom_info/__openerp__.py b/base_custom_info/__openerp__.py index 9b4521191..08eeb91f9 100644 --- a/base_custom_info/__openerp__.py +++ b/base_custom_info/__openerp__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel -# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 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 { @@ -13,7 +14,7 @@ ], 'data': [ 'views/custom_info_template_view.xml', - 'views/custom_info_template_line_view.xml', + 'views/custom_info_property_view.xml', 'views/custom_info_value_view.xml', 'views/menu.xml', 'security/ir.model.access.csv', 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/models/__init__.py b/base_custom_info/models/__init__.py index c7f3fd66c..278faf2ff 100644 --- a/base_custom_info/models/__init__.py +++ b/base_custom_info/models/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel -# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 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 index 3001ae6bd..0f42174a8 100644 --- a/base_custom_info/models/custom_info.py +++ b/base_custom_info/models/custom_info.py @@ -1,59 +1,77 @@ # -*- coding: utf-8 -*- -# (c) 2015 Antiun Ingeniería S.L. - Sergio Teruel -# (c) 2015 Antiun Ingeniería S.L. - Carlos Dauden +# © 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, _ +from openerp import api, fields, models class CustomInfoTemplate(models.Model): + """Defines custom properties expected for a given database object.""" _name = "custom.info.template" - _description = "Template of properties" + _description = "Custom information template" + _sql_constraints = [ + ("name_model", + "UNIQUE (name, model_id)", + "Another template with that name exists for that model."), + ] - name = fields.Char() - model_id = fields.Many2one(comodel_name='ir.model', string='Data Model') + name = fields.Char(translate=True) + model_id = fields.Many2one(comodel_name='ir.model', string='Model') info_ids = fields.One2many( - comodel_name='custom.info.template.line', + comodel_name='custom.info.property', inverse_name='template_id', string='Properties') -class CustomInfoTemplateLine(models.Model): - _name = "custom.info.template.line" - _description = "Properties" +class CustomInfoProperty(models.Model): + """Name of the custom information property.""" + _name = "custom.info.property" + _description = "Custom information property" + _sql_constraints = [ + ("name_template", + "UNIQUE (name, template_id)", + "Another property with that name exists for that template."), + ] - name = fields.Char() + 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="custom_info_name_id", + inverse_name="property_id", string="Property Values") class CustomInfoValue(models.Model): _name = "custom.info.value" - _description = "Values of properties" + _description = "Custom information value" _rec_name = 'value' + _sql_constraints = [ + ("property_model_res", + "UNIQUE (property_id, model, res_id)", + "Another property with that name exists for that resource."), + ] model = fields.Char(index=True, required=True) - res_id = fields.Integer(index=True, required=True) - custom_info_name_id = fields.Many2one( - comodel_name='custom.info.template.line', + res_id = fields.Integer("Resource ID", index=True, required=True) + property_id = fields.Many2one( + comodel_name='custom.info.property', required=True, - string='Property Name') - name = fields.Char(related='custom_info_name_id.name') - value = fields.Char() + string='Property') + name = fields.Char(related='property_id.name') + value = fields.Char(translate=True) class CustomInfo(models.AbstractModel): _name = "custom.info" - _description = "Abstract model from inherit to add info in any model" + _description = "Inheritable abstract model to add custom info in any model" custom_info_template_id = fields.Many2one( comodel_name='custom.info.template', - string='Property Template') + string='Custom Information Template') custom_info_ids = fields.One2many( comodel_name='custom.info.value', inverse_name='res_id', @@ -66,12 +84,12 @@ class CustomInfo(models.AbstractModel): if not self.custom_info_template_id: self.custom_info_ids = False else: - info_list = self.custom_info_ids.mapped('custom_info_name_id') + 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, - 'custom_info_name_id': info_name.id, + 'property_id': info_name.id, }) @api.multi diff --git a/base_custom_info/security/ir.model.access.csv b/base_custom_info/security/ir.model.access.csv index 388445929..d285e7021 100644 --- a/base_custom_info/security/ir.model.access.csv +++ b/base_custom_info/security/ir.model.access.csv @@ -1,7 +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_template_line_user,custom.info.template.line.user,model_custom_info_template_line,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_sale_manager,1,1,1,1 -access_custom_info_template_line_sale_manager,custom.info.template.line.salemanager,model_custom_info_template_line,base.group_sale_manager,1,1,1,1 -access_custom_info_value_sale_manager,custom.info.value.salemanager,model_custom_info_value,base.group_sale_manager,1,1,1,1 +"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_template_line_view.xml b/base_custom_info/views/custom_info_property_view.xml similarity index 73% rename from base_custom_info/views/custom_info_template_line_view.xml rename to base_custom_info/views/custom_info_property_view.xml index d682499fe..81fcf0bc5 100644 --- a/base_custom_info/views/custom_info_template_line_view.xml +++ b/base_custom_info/views/custom_info_property_view.xml @@ -3,8 +3,8 @@ - base.custom.info.template.line.tree - custom.info.template.line + base.custom.info.property.tree + custom.info.property @@ -14,10 +14,10 @@ - base.custom.info.template.line.form - custom.info.template.line + base.custom.info.property.form + custom.info.property -
+ @@ -34,7 +34,7 @@ Properties ir.actions.act_window - custom.info.template.line + 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 index 60f4e8e40..3f0349a22 100644 --- a/base_custom_info/views/custom_info_template_view.xml +++ b/base_custom_info/views/custom_info_template_view.xml @@ -48,7 +48,7 @@

Click to define a new custom info template.

- You must define a custom info template for every different + 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 index 5a08a9c5d..c7a5379c5 100644 --- a/base_custom_info/views/custom_info_value_view.xml +++ b/base_custom_info/views/custom_info_value_view.xml @@ -6,8 +6,8 @@ base.custom.info.value.tree custom.info.value - - + + diff --git a/base_custom_info/views/menu.xml b/base_custom_info/views/menu.xml index d23ef5fc8..5cb61a2f3 100644 --- a/base_custom_info/views/menu.xml +++ b/base_custom_info/views/menu.xml @@ -7,15 +7,18 @@ parent="base.menu_administration" sequence="45"/> - - -