diff --git a/partner_sector/README.rst b/partner_sector/README.rst new file mode 100644 index 000000000..88a51e0c3 --- /dev/null +++ b/partner_sector/README.rst @@ -0,0 +1,71 @@ +.. 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 + +============== +Partner Sector +============== + +This module adds the concept of economic sector for partners. + + +Configuration +============= + +To manage sectors, you need to: + +* Go to *Sales > Configuration > Address Book > Sectors*. + + +Usage +===== + +To use this module, you need to: + +* Go to any partner's form. + +Only companies have sectors. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/8.0 + +Known issues / Roadmap +====================== + +* Add a unique constraint for name per parent sector. + + +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 +* Antonio Espinosa +* Javier Iniesta + +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/partner_sector/__init__.py b/partner_sector/__init__.py new file mode 100644 index 000000000..ba0257333 --- /dev/null +++ b/partner_sector/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_sector/__openerp__.py b/partner_sector/__openerp__.py new file mode 100644 index 000000000..d00bded1e --- /dev/null +++ b/partner_sector/__openerp__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Sector", + "summary": "Add partner sectors", + "version": "8.0.1.0.0", + "category": "Customer Relationship Management", + "website": "http://www.antiun.com", + "author": "Antiun Ingeniería, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "base", + ], + "data": [ + "security/ir.model.access.csv", + "views/res_partner_sector_view.xml", + "views/res_partner_view.xml", + ] +} diff --git a/partner_sector/i18n/.gitkeep b/partner_sector/i18n/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/partner_sector/i18n/es.po b/partner_sector/i18n/es.po new file mode 100644 index 000000000..0b95fc273 --- /dev/null +++ b/partner_sector/i18n/es.po @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_sector +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-12-17 13:49+0000\n" +"PO-Revision-Date: 2015-12-17 13:49+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_sector +#: field:res.partner.sector,child_ids:0 +msgid "Children" +msgstr "Hijos" + +#. module: partner_sector +#: field:res.partner.sector,create_uid:0 +msgid "Created by" +msgstr "Creado por" + +#. module: partner_sector +#: field:res.partner.sector,create_date:0 +msgid "Created on" +msgstr "Creado en" + +#. module: partner_sector +#: field:res.partner.sector,id:0 +msgid "ID" +msgstr "ID" + +#. module: partner_sector +#: field:res.partner.sector,write_uid:0 +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: partner_sector +#: field:res.partner.sector,write_date:0 +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: partner_sector +#: field:res.partner,sector_id:0 +msgid "Main Sector" +msgstr "Sector principal" + +#. module: partner_sector +#: field:res.partner.sector,name:0 +msgid "Name" +msgstr "Nombre" + +#. module: partner_sector +#: field:res.partner.sector,parent_left:0 +msgid "Parent Left" +msgstr "Padre izquierdo" + +#. module: partner_sector +#: field:res.partner.sector,parent_right:0 +msgid "Parent Right" +msgstr "Padre derecho" + +#. module: partner_sector +#: field:res.partner.sector,parent_id:0 +msgid "Parent id" +msgstr "ID del padre" + +#. module: partner_sector +#: model:ir.model,name:partner_sector.model_res_partner +msgid "Partner" +msgstr "Empresa" + +#. module: partner_sector +#: view:res.partner:partner_sector.view_res_partner_filter_sector +msgid "Salesperson" +msgstr "Comercial" + +#. module: partner_sector +#: field:res.partner,secondary_sector_ids:0 +msgid "Secondary Sectors" +msgstr "Sectores secundarios" + +#. module: partner_sector +#: model:ir.model,name:partner_sector.model_res_partner_sector +#: view:res.partner:partner_sector.view_partner_form_sector +#: view:res.partner:partner_sector.view_res_partner_filter_sector +msgid "Sector" +msgstr "Sector" + +#. module: partner_sector +#: model:ir.actions.act_window,name:partner_sector.res_partner_sector_action +#: model:ir.ui.menu,name:partner_sector.menu_res_partner_sector +#: view:res.partner.sector:partner_sector.res_partner_sector_tree_view +msgid "Sectors" +msgstr "Sectores" + +#. module: partner_sector +#: code:addons/partner_sector/models/res_partner.py:21 +#, python-format +msgid "The main sector must be different from the secondary sectors." +msgstr "El sector principal debe ser diferente a los sectores secundarios." diff --git a/partner_sector/i18n/partner_sector.pot b/partner_sector/i18n/partner_sector.pot new file mode 100644 index 000000000..2262ae02a --- /dev/null +++ b/partner_sector/i18n/partner_sector.pot @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_sector +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-12-17 13:49+0000\n" +"PO-Revision-Date: 2015-12-17 13:49+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_sector +#: field:res.partner.sector,child_ids:0 +msgid "Children" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,create_uid:0 +msgid "Created by" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,create_date:0 +msgid "Created on" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,id:0 +msgid "ID" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,write_uid:0 +msgid "Last Updated by" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,write_date:0 +msgid "Last Updated on" +msgstr "" + +#. module: partner_sector +#: field:res.partner,sector_id:0 +msgid "Main Sector" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,name:0 +msgid "Name" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,parent_left:0 +msgid "Parent Left" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,parent_right:0 +msgid "Parent Right" +msgstr "" + +#. module: partner_sector +#: field:res.partner.sector,parent_id:0 +msgid "Parent id" +msgstr "" + +#. module: partner_sector +#: model:ir.model,name:partner_sector.model_res_partner +msgid "Partner" +msgstr "" + +#. module: partner_sector +#: view:res.partner:partner_sector.view_res_partner_filter_sector +msgid "Salesperson" +msgstr "" + +#. module: partner_sector +#: field:res.partner,secondary_sector_ids:0 +msgid "Secondary Sectors" +msgstr "" + +#. module: partner_sector +#: model:ir.model,name:partner_sector.model_res_partner_sector +#: view:res.partner:partner_sector.view_partner_form_sector +#: view:res.partner:partner_sector.view_res_partner_filter_sector +msgid "Sector" +msgstr "" + +#. module: partner_sector +#: model:ir.actions.act_window,name:partner_sector.res_partner_sector_action +#: model:ir.ui.menu,name:partner_sector.menu_res_partner_sector +#: view:res.partner.sector:partner_sector.res_partner_sector_tree_view +msgid "Sectors" +msgstr "" + +#. module: partner_sector +#: code:addons/partner_sector/models/res_partner.py:21 +#, python-format +msgid "The main sector must be different from the secondary sectors." +msgstr "" diff --git a/partner_sector/models/__init__.py b/partner_sector/models/__init__.py new file mode 100644 index 000000000..29ce4da80 --- /dev/null +++ b/partner_sector/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_partner +from . import res_partner_sector diff --git a/partner_sector/models/res_partner.py b/partner_sector/models/res_partner.py new file mode 100644 index 000000000..957fa38fd --- /dev/null +++ b/partner_sector/models/res_partner.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api, exceptions, _ + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + sector_id = fields.Many2one(comodel_name='res.partner.sector', + string='Main Sector') + + secondary_sector_ids = fields.Many2many( + comodel_name='res.partner.sector', string="Secondary Sectors", + domain="[('id', '!=', sector_id)]") + + @api.constrains('sector_id', 'secondary_sector_ids') + def _check_sectors(self): + if self.sector_id in self.secondary_sector_ids: + raise exceptions.Warning(_('The main sector must be different ' + 'from the secondary sectors.')) diff --git a/partner_sector/models/res_partner_sector.py b/partner_sector/models/res_partner_sector.py new file mode 100644 index 000000000..ae512d126 --- /dev/null +++ b/partner_sector/models/res_partner_sector.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api + + +class ResPartnerSector(models.Model): + _name = 'res.partner.sector' + _order = "parent_left" + _parent_order = "name" + _parent_store = True + _description = "Sector" + + name = fields.Char(required=True, translate=True) + parent_id = fields.Many2one(comodel_name='res.partner.sector', + ondelete='restrict') + child_ids = fields.One2many(comodel_name='res.partner.sector', + inverse_name='parent_id', + string="Children") + parent_left = fields.Integer('Parent Left', select=True) + parent_right = fields.Integer('Parent Right', select=True) + + @api.multi + def name_get(self): + def get_names(cat): + """ Return the list [cat.name, cat.parent_id.name, ...] """ + res = [] + while cat: + res.append(cat.name) + cat = cat.parent_id + return res + + return [(cat.id, " / ".join(reversed(get_names(cat)))) for cat in self] diff --git a/partner_sector/security/ir.model.access.csv b/partner_sector/security/ir.model.access.csv new file mode 100644 index 000000000..0fce0fe55 --- /dev/null +++ b/partner_sector/security/ir.model.access.csv @@ -0,0 +1,5 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_res_partner_sector_public","res_partner_sector group_public","model_res_partner_sector","base.group_public",1,0,0,0 +"access_res_partner_sector_portal","res_partner_sector group_portal","model_res_partner_sector","base.group_portal",1,0,0,0 +"access_res_partner_sector_group_partner_manager","res_partner_sector group_partner_manager","model_res_partner_sector","base.group_partner_manager",1,1,1,1 +"access_res_partner_sector_group_user","res_partner_sector group_user","model_res_partner_sector","base.group_user",1,0,0,0 diff --git a/partner_sector/static/description/icon.png b/partner_sector/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_sector/static/description/icon.png differ diff --git a/partner_sector/tests/__init__.py b/partner_sector/tests/__init__.py new file mode 100644 index 000000000..cba4e6c7f --- /dev/null +++ b/partner_sector/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_res_partner diff --git a/partner_sector/tests/test_res_partner.py b/partner_sector/tests/test_res_partner.py new file mode 100644 index 000000000..8b9d99e94 --- /dev/null +++ b/partner_sector/tests/test_res_partner.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2015 Antiun Ingenieria S.L. - Javier Iniesta +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +from openerp.exceptions import ValidationError + + +class TestResPartner(TransactionCase): + + def test_check_sectors(self): + sector = self.env['res.partner.sector'].create({'name': 'Test'}) + with self.assertRaises(ValidationError): + self.env['res.partner'].create( + {'name': 'Test', 'sector_id': sector.id, + 'secondary_sector_ids': [(4, sector.id)]}) diff --git a/partner_sector/views/res_partner_sector_view.xml b/partner_sector/views/res_partner_sector_view.xml new file mode 100644 index 000000000..7d6f73aa4 --- /dev/null +++ b/partner_sector/views/res_partner_sector_view.xml @@ -0,0 +1,32 @@ + + + + + + + Sectors + res.partner.sector + form + tree + + + + Partner Sector tree + res.partner.sector + + + + + + + + + + + + diff --git a/partner_sector/views/res_partner_view.xml b/partner_sector/views/res_partner_view.xml new file mode 100644 index 000000000..7b09c0212 --- /dev/null +++ b/partner_sector/views/res_partner_view.xml @@ -0,0 +1,54 @@ + + + + + + + Partner form with sector + res.partner + + + + + + + + + + + Partner tree with sector + res.partner + + + + + + + + + + Partner search with sector + res.partner + + + + + + + + + + + + +