Browse Source

Merge pull request #313 from Yajo/custom-info

[8.0][base_custom_info] New module to have custom information associated to any model
pull/389/head
Pedro M. Baeza 9 years ago
parent
commit
7815170243
  1. 95
      base_custom_info/README.rst
  2. 6
      base_custom_info/__init__.py
  3. 34
      base_custom_info/__openerp__.py
  4. 198
      base_custom_info/i18n/es.po
  5. BIN
      base_custom_info/images/menu.png
  6. BIN
      base_custom_info/images/properties.png
  7. BIN
      base_custom_info/images/templates.png
  8. BIN
      base_custom_info/images/values.png
  9. 6
      base_custom_info/models/__init__.py
  10. 125
      base_custom_info/models/custom_info.py
  11. 7
      base_custom_info/security/ir.model.access.csv
  12. 43
      base_custom_info/views/custom_info_property_view.xml
  13. 60
      base_custom_info/views/custom_info_template_view.xml
  14. 27
      base_custom_info/views/custom_info_value_view.xml
  15. 25
      base_custom_info/views/menu.xml

95
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
<https://github.com/OCA/product-attribute/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
<https://github.com/OCA/
product-attribute/issues/new?body=module:%20
base_custom_info%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Rafael Blasco <rafabn@antiun.com>
* Carlos Dauden <carlos@incaser.es>
* Sergio Teruel <sergio@incaser.es>
* Jairo Llopis <yajo.sk8@gmail.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.

6
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

34
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,
}

198
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 ""
"<p class=\"oe_view_nocontent_create\">\n"
" Click to define a new custom info template.\n"
" </p><p>\n"
" You must define a custom info template for each\n"
" product properties group.\n"
" </p>\n"
" "
msgstr ""
"<p class=\"oe_view_nocontent_create\">\n"
"Pulsa para definir una nueva plantilla de información personalizada.\n"
"</p><p>\n"
"Debe definir una plantilla de información personalizada para cada diferente grupo de propiedades.\n"
"</p>"
#. 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"

BIN
base_custom_info/images/menu.png

After

Width: 177  |  Height: 117  |  Size: 3.5 KiB

BIN
base_custom_info/images/properties.png

After

Width: 1064  |  Height: 440  |  Size: 21 KiB

BIN
base_custom_info/images/templates.png

After

Width: 1077  |  Height: 447  |  Size: 19 KiB

BIN
base_custom_info/images/values.png

After

Width: 1217  |  Height: 226  |  Size: 14 KiB

6
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

125
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

7
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

43
base_custom_info/views/custom_info_property_view.xml

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="base_custom_info_template_line_tree" model="ir.ui.view">
<field name="name">base.custom.info.property.tree</field>
<field name="model">custom.info.property</field>
<field name="arch" type="xml">
<tree string="Custom Info Templates">
<field name="name"/>
<field name="template_id"/>
</tree>
</field>
</record>
<record id="base_custom_info_template_line_form" model="ir.ui.view">
<field name="name">base.custom.info.property.form</field>
<field name="model">custom.info.property</field>
<field name="arch" type="xml">
<form string="Custom Info Template Properties">
<sheet>
<group>
<field name="name"/>
<field name="template_id"/>
</group>
<group>
<field name="info_value_ids"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="custom_info_template_line_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">custom.info.property</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>
</data>
</openerp>

60
base_custom_info/views/custom_info_template_view.xml

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="base_custom_info_template_tree" model="ir.ui.view">
<field name="name">base.custom.info.template.tree</field>
<field name="model">custom.info.template</field>
<field name="arch" type="xml">
<tree string="Custom Info Templates">
<field name="name"/>
<field name="model"/>
<field name="model_id"/>
<field name="info_ids"/>
</tree>
</field>
</record>
<record id="base_custom_info_template_form" model="ir.ui.view">
<field name="name">base.custom.info.template.form</field>
<field name="model">custom.info.template</field>
<field name="arch" type="xml">
<form string="Custom Info Template">
<sheet>
<group>
<field name="name"/>
<field name="model"/>
<field name="model_id"/>
</group>
<group>
<field name="info_ids">
<tree string="Info Lines" editable="bottom">
<field name="name"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record id="custom_info_template_action" model="ir.actions.act_window">
<field name="name">Templates</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">custom.info.template</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
<field name="view_id" eval="False"/> <!-- Force empty -->
<field name="domain" eval="False"/> <!-- Force empty -->
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to define a new custom info template.
</p><p>
You must define a custom info template for each
product properties group.
</p>
</field>
</record>
</data>
</openerp>

27
base_custom_info/views/custom_info_value_view.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="base_custom_info_value_tree" model="ir.ui.view">
<field name="name">base.custom.info.value.tree</field>
<field name="model">custom.info.value</field>
<field name="arch" type="xml">
<tree string="Custom Property Values">
<field name="property_id"/>
<field name="value"/>
<field name="model_id"/>
<field name="res_id"/>
</tree>
</field>
</record>
<record id="custom_info_value_action" model="ir.actions.act_window">
<field name="name">Values</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">custom.info.value</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>
</data>
</openerp>

25
base_custom_info/views/menu.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Parent Custom Info in Settings-->
<menuitem id="menu_base_custom_info" name="Custom Info"
parent="base.menu_administration" sequence="45"/>
<!--base.custom.info.template-->
<menuitem id="menu_base_custom_info_template"
action="custom_info_template_action"
parent="menu_base_custom_info" sequence="5"/>
<!--base.custom.info.template.line-->
<menuitem id="menu_base_custom_info_template_line"
action="custom_info_template_line_action"
parent="menu_base_custom_info" sequence="10"/>
<!--base.custom.info.value-->
<menuitem id="menu_base_custom_info_value"
action="custom_info_value_action"
parent="menu_base_custom_info" sequence="15"/>
</data>
</openerp>
Loading…
Cancel
Save