Browse Source

[REF] Adapt to use res.partner.industry model

pull/619/head
mreficent 6 years ago
parent
commit
61d771467e
  1. 20
      partner_sector/README.rst
  2. 6
      partner_sector/__manifest__.py
  3. 2
      partner_sector/models/__init__.py
  4. 8
      partner_sector/models/res_config_settings.py
  5. 21
      partner_sector/models/res_partner.py
  6. 14
      partner_sector/models/res_partner_industry.py
  7. 7
      partner_sector/security/ir.model.access.csv
  8. 7
      partner_sector/security/partner_industry_security.xml
  9. 7
      partner_sector/security/partner_sector_security.xml
  10. 2
      partner_sector/tests/__init__.py
  11. 22
      partner_sector/tests/test_res_partner_sector.py
  12. 15
      partner_sector/views/res_config_settings.xml
  13. 29
      partner_sector/views/res_partner_industry_view.xml
  14. 30
      partner_sector/views/res_partner_sector_view.xml
  15. 90
      partner_sector/views/res_partner_view.xml

20
partner_sector/README.rst

@ -6,20 +6,20 @@
Partner Sector
==============
This module adds the concept of economic sector for partners.
This module adds secondary industries for partners.
Configuration
=============
To manage sectors, you need to:
To manage industries, you need to:
* Go to *Contacts > Configuration > Contacts > Sectors*.
* Go to *Contacts > Configuration > Sectors of Activity*.
By default only companies have sectors. To activate sectors in individuals also,
By default only companies have industries. To activate industries in individuals also,
you need to activate the following setting:
* Go to *Settings > General Settings > Partner Sectors > Sector in contacts > Use sector for individuals*
* Go to *Settings > General Settings > Partner Industries > Industry in contacts > Use industry for individuals*
Usage
@ -37,15 +37,16 @@ To use this module, you need to:
Known issues / Roadmap
======================
* Add a unique constraint for name per parent sector.
* Add a unique constraint for name per parent industry.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/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.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
@ -65,6 +66,7 @@ Contributors
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Luis M. Ontalba <luis.martinez@tecnativa.com>
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Miquel Raïch <miquel.raich@eficent.com>
Maintainer
----------

6
partner_sector/__manifest__.py

@ -4,7 +4,7 @@
{
"name": "Partner Sector",
"summary": "Add partner sectors",
"summary": "Add secondary partner industries",
"version": "11.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://github.com/OCA/partner-contact",
@ -17,8 +17,8 @@
],
"data": [
"security/ir.model.access.csv",
"security/partner_sector_security.xml",
"views/res_partner_sector_view.xml",
"security/partner_industry_security.xml",
"views/res_partner_industry_view.xml",
"views/res_partner_view.xml",
"views/res_config_settings.xml",
]

2
partner_sector/models/__init__.py

@ -1,5 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner
from . import res_partner_sector
from . import res_partner_industry
from . import res_config_settings

8
partner_sector/models/res_config_settings.py

@ -7,8 +7,8 @@ from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
group_use_partner_sector_for_person = fields.Boolean(
'Use sector for individuals',
help="Set if you want to be able to use sectors for "
group_use_partner_industry_for_person = fields.Boolean(
'Use industry for individuals',
help="Set if you want to be able to use industries for "
"individuals also.",
implied_group='partner_sector.group_use_partner_sector_for_person')
implied_group='partner_sector.group_use_partner_industry_for_person')

21
partner_sector/models/res_partner.py

@ -1,5 +1,6 @@
# Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
# Copyright 2016 Tecnativa S.L. - Vicent Cubells
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, exceptions, fields, models, _
@ -8,15 +9,15 @@ from odoo import api, exceptions, fields, models, _
class ResPartner(models.Model):
_inherit = 'res.partner'
sector_id = fields.Many2one(comodel_name='res.partner.sector',
string='Main Sector')
industry_id = fields.Many2one(string='Main Industry')
secondary_sector_ids = fields.Many2many(
comodel_name='res.partner.sector', string="Secondary Sectors",
domain="[('id', '!=', sector_id)]")
secondary_industry_ids = fields.Many2many(
comodel_name='res.partner.industry', string="Secondary Industries",
domain="[('id', '!=', industry_id)]")
@api.constrains('sector_id', 'secondary_sector_ids')
def _check_sectors(self):
if self.sector_id in self.secondary_sector_ids:
raise exceptions.UserError(_('The main sector must be different '
'from the secondary sectors.'))
@api.constrains('industry_id', 'secondary_industry_ids')
def _check_industries(self):
if self.industry_id in self.secondary_industry_ids:
raise exceptions.UserError(
_('The main industry must be different '
'from the secondary industries.'))

14
partner_sector/models/res_partner_sector.py → partner_sector/models/res_partner_industry.py

@ -1,22 +1,22 @@
# Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
# Copyright 2016 Tecnativa S.L. - Vicent Cubells
# Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, exceptions, fields, models, _
class ResPartnerSector(models.Model):
_name = 'res.partner.sector'
class ResPartnerIndustry(models.Model):
_inherit = 'res.partner.industry'
_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',
name = fields.Char(required=True)
parent_id = fields.Many2one(comodel_name='res.partner.industry',
ondelete='restrict')
child_ids = fields.One2many(comodel_name='res.partner.sector',
child_ids = fields.One2many(comodel_name='res.partner.industry',
inverse_name='parent_id',
string="Children")
parent_left = fields.Integer('Parent Left', index=True)
@ -38,4 +38,4 @@ class ResPartnerSector(models.Model):
def _check_parent_id(self):
if not self._check_recursion():
raise exceptions.ValidationError(
_('Error! You cannot create recursive sectors.'))
_('Error! You cannot create recursive industries.'))

7
partner_sector/security/ir.model.access.csv

@ -1,5 +1,4 @@
"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
"access_res_partner_industry_public","res_partner_industry group_public","model_res_partner_industry","base.group_public",1,0,0,0
"access_res_partner_industry_portal","res_partner_industry group_portal","model_res_partner_industry","base.group_portal",1,0,0,0
"access_res_partner_industry_group_partner_manager","res_partner_industry group_partner_manager","model_res_partner_industry","base.group_partner_manager",1,1,1,1

7
partner_sector/security/partner_industry_security.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_use_partner_industry_for_person" model="res.groups">
<field name="name">Use industry for individuals</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
</odoo>

7
partner_sector/security/partner_sector_security.xml

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_use_partner_sector_for_person" model="res.groups">
<field name="name">Use sector for individuals</field>
<field name="category_id" ref="base.module_category_hidden"/>
</record>
</odoo>

2
partner_sector/tests/__init__.py

@ -1,3 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_res_partner_sector
from . import test_res_partner_industry

22
partner_sector/tests/test_res_partner_sector.py

@ -7,33 +7,33 @@ from odoo.tests import common
from odoo.exceptions import ValidationError
class TestResPartnerSector(common.SavepointCase):
class TestResPartnerIndustry(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestResPartnerSector, cls).setUpClass()
cls.Sector = cls.env['res.partner.sector']
cls.sector_main = cls.Sector.create({
super(TestResPartnerIndustry, cls).setUpClass()
cls.industry_model = cls.env['res.partner.industry']
cls.industry_main = cls.industry_model.create({
'name': 'Test',
})
cls.sector_child = cls.Sector.create({
cls.industry_child = cls.industry_model.create({
'name': 'Test child',
'parent_id': cls.sector_main.id,
'parent_id': cls.industry_main.id,
})
def test_check_sectors(self):
def test_check_industries(self):
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Test',
'sector_id': self.sector_main.id,
'secondary_sector_ids': [(4, self.sector_main.id)],
'industry_id': self.industry_main.id,
'secondary_industry_ids': [(4, self.industry_main.id)],
})
def test_check_recursion(self):
with self.assertRaises(ValidationError):
self.sector_main.parent_id = self.sector_child.id
self.industry_main.parent_id = self.industry_child.id
def test_name(self):
self.assertEqual(
self.sector_child.name_get()[0][1],
self.industry_child.name_get()[0][1],
"Test / Test child",
)

15
partner_sector/views/res_config_settings.xml

@ -9,16 +9,21 @@
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='multi_company']" position="after">
<h2>Partner Sectors</h2>
<div class="row mt16 o_settings_container" name="partner_sectors">
<h2>Partner Industries</h2>
<div class="row mt16 o_settings_container" name="partner_industries">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="group_use_partner_sector_for_person"/>
<field name="group_use_partner_industry_for_person"/>
</div>
<div class="o_setting_right_pane">
<label string="Sector for individual" for="group_use_partner_sector_for_person"/>
<label string="Industry for individual" for="group_use_partner_industry_for_person"/>
<div class="text-muted">
Enable sectors for individuals.
Enable industries for individuals
</div>
<div class="content-group">
<div class="mt16" attrs="{'invisible': [('group_use_partner_industry_for_person', '=', False)]}">
<button name="%(base.res_partner_industry_action)d" icon="fa-arrow-right" type="action" string="Industries" class="btn-link"/>
</div>
</div>
</div>
</div>

29
partner_sector/views/res_partner_industry_view.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingenieria S.L. - Javier Iniesta
Copyright 2018 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record id="res_partner_industry_view_form" model="ir.ui.view">
<field name="name">Industry</field>
<field name="model">res.partner.industry</field>
<field name="inherit_id" ref="base.res_partner_industry_view_form"/>
<field name="arch" type="xml">
<field name="full_name" position="after">
<field name="parent_id"/>
</field>
</field>
</record>
<record id="res_partner_industry_view_tree" model="ir.ui.view">
<field name="name">Industry</field>
<field name="model">res.partner.industry</field>
<field name="inherit_id" ref="base.res_partner_industry_view_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="parent_id"/>
</field>
</field>
</record>
</odoo>

30
partner_sector/views/res_partner_sector_view.xml

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record id="res_partner_sector_action" model="ir.actions.act_window">
<field name="name">Sectors</field>
<field name="res_model">res.partner.sector</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>
<record id="res_partner_sector_tree_view" model="ir.ui.view">
<field name="name">Partner Sector tree</field>
<field name="model">res.partner.sector</field>
<field name="arch" type="xml">
<tree string="Sectors" editable="top">
<field name="name"/>
<field name="parent_id"/>
</tree>
</field>
</record>
<menuitem action="res_partner_sector_action"
id="menu_res_partner_sector"
name="Sectors"
parent="contacts.res_partner_menu_config"
sequence="3"/>
</odoo>

90
partner_sector/views/res_partner_view.xml

@ -4,103 +4,109 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record model="ir.ui.view" id="view_partner_form_sector">
<field name="name">Partner form with sector</field>
<record model="ir.ui.view" id="view_partner_form_industry">
<field name="name">Partner form with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="phone" position="before">
<field name="sector_id" placeholder="Sector"
options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False)]}"/>
<field name="secondary_sector_ids" widget="many2many_tags"
<field name="industry_id" position="after">
<field name="secondary_industry_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"/>
</field>
<xpath expr="//field[@name='child_ids']/form//field[@name='title']" position="after">
<field name="is_company" invisible="1"/>
<field name="sector_id" placeholder="Sector"
<field name="industry_id" placeholder="Sector"
options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False)]}"/>
<field name="secondary_sector_ids" widget="many2many_tags"
<field name="secondary_industry_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_partner_tree_sector">
<field name="name">Partner tree with sector</field>
<record model="ir.ui.view" id="view_partner_tree_industry">
<field name="name">Partner tree with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<field name="email" position="after">
<field name="sector_id"
<field name="industry_id"
attrs="{'invisible': [('is_company', '=', False)]}"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_res_partner_filter_sector">
<field name="name">Partner search with sector</field>
<record model="ir.ui.view" id="view_res_partner_filter_industry">
<field name="name">Partner search with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<field name="category_id" position="after">
<field name="sector_id"
string="Sector"
filter_domain="['|',('sector_id','ilike',self),
('secondary_sector_ids.name','ilike',self)]"/>
<field name="industry_id"
string="Industry"
filter_domain="['|',('industry_id','ilike',self),
('secondary_industry_ids.name','ilike',self)]"/>
</field>
<filter name="salesperson" position="after">
<filter name="sector"
string="Sector"
<filter name="industry"
string="Industry"
domain="[('is_company','=', True)]"
context="{'group_by': 'sector_id'}"/>
context="{'group_by': 'industry_id'}"/>
</filter>
</field>
</record>
<!-- Views activated for group_use_partner_sector_for_person -->
<!-- Views activated for group_use_partner_industry_for_person -->
<record model="ir.ui.view" id="view_partner_form_sector_person">
<field name="name">Partner form with sector</field>
<record model="ir.ui.view" id="view_partner_form_industry_person0">
<field name="name">Partner form with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_sector.view_partner_form_sector"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_sector_for_person'))]"/>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_industry_for_person'))]"/>
<field name="arch" type="xml">
<field name="sector_id" position="attributes">
<xpath expr="//page/group/group/field[@name='industry_id']" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
</field>
<field name="secondary_sector_ids" position="attributes">
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_partner_form_industry_person">
<field name="name">Partner form with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_sector.view_partner_form_industry"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_industry_for_person'))]"/>
<field name="arch" type="xml">
<xpath expr="//page/group/group/field[@name='secondary_industry_ids']" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
</field>
<xpath expr="//field[@name='child_ids']/form//field[@name='sector_id']" position="attributes">
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='industry_id']" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='secondary_sector_ids']" position="attributes">
<xpath expr="//field[@name='child_ids']/form//field[@name='secondary_industry_ids']" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_partner_tree_sector_person">
<field name="name">Partner tree with sector</field>
<record model="ir.ui.view" id="view_partner_tree_industry_person">
<field name="name">Partner tree with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_sector.view_partner_tree_sector"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_sector_for_person'))]"/>
<field name="inherit_id" ref="partner_sector.view_partner_tree_industry"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_industry_for_person'))]"/>
<field name="arch" type="xml">
<field name="sector_id" position="attributes">
<field name="industry_id" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_res_partner_filter_sector_person">
<field name="name">Partner search with sector</field>
<record model="ir.ui.view" id="view_res_partner_filter_industry_person">
<field name="name">Partner search with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_sector.view_res_partner_filter_sector"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_sector_for_person'))]"/>
<field name="inherit_id" ref="partner_sector.view_res_partner_filter_industry"/>
<field name="groups_id" eval="[(4, ref('partner_sector.group_use_partner_industry_for_person'))]"/>
<field name="arch" type="xml">
<filter name="sector" position="attributes">
<filter name="industry" position="attributes">
<attribute name="domain"/>
</filter>
</field>

Loading…
Cancel
Save