Browse Source

[IMP] partner_industry_secondary: black, isort, prettier

14.0
Stephan Keller 5 years ago
committed by Surachet Saejueng
parent
commit
acb33d19d4
  1. 7
      partner_industry_secondary/__manifest__.py
  2. 2
      partner_industry_secondary/migrations/12.0.1.0.0/post-migration.py
  3. 12
      partner_industry_secondary/models/res_config_settings.py
  4. 21
      partner_industry_secondary/models/res_partner.py
  5. 20
      partner_industry_secondary/models/res_partner_industry.py
  6. 4
      partner_industry_secondary/security/partner_industry_security.xml
  7. 30
      partner_industry_secondary/tests/test_res_partner_industry.py
  8. 60
      partner_industry_secondary/views/res_config_settings.xml
  9. 13
      partner_industry_secondary/views/res_partner_industry_view.xml
  10. 132
      partner_industry_secondary/views/res_partner_view.xml

7
partner_industry_secondary/__manifest__.py

@ -12,15 +12,12 @@
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"base_setup",
"contacts",
],
"depends": ["base_setup", "contacts",],
"data": [
"security/ir.model.access.csv",
"security/partner_industry_security.xml",
"views/res_partner_industry_view.xml",
"views/res_partner_view.xml",
"views/res_config_settings.xml",
]
],
}

2
partner_industry_secondary/migrations/12.0.1.0.0/post-migration.py

@ -6,4 +6,4 @@ from openupgradelib import openupgrade
@openupgrade.migrate(use_env=True)
def migrate(env, version):
env['res.partner.industry']._parent_store_compute()
env["res.partner.industry"]._parent_store_compute()

12
partner_industry_secondary/models/res_config_settings.py

@ -5,11 +5,11 @@ from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"
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_industry_secondary.'
'group_use_partner_industry_for_person')
"Use industry for individuals",
help="Set if you want to be able to use industries for " "individuals also.",
implied_group="partner_industry_secondary."
"group_use_partner_industry_for_person",
)

21
partner_industry_secondary/models/res_partner.py

@ -3,22 +3,27 @@
# 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, _
from odoo import _, api, exceptions, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"
industry_id = fields.Many2one(string='Main Industry')
industry_id = fields.Many2one(string="Main Industry")
secondary_industry_ids = fields.Many2many(
comodel_name='res.partner.industry', string="Secondary Industries",
domain="[('id', '!=', industry_id)]")
comodel_name="res.partner.industry",
string="Secondary Industries",
domain="[('id', '!=', industry_id)]",
)
@api.constrains('industry_id', 'secondary_industry_ids')
@api.constrains("industry_id", "secondary_industry_ids")
def _check_industries(self):
for partner in self:
if partner.industry_id in partner.secondary_industry_ids:
raise exceptions.ValidationError(
_('The main industry must be different '
'from the secondary industries.'))
_(
"The main industry must be different "
"from the secondary industries."
)
)

20
partner_industry_secondary/models/res_partner_industry.py

@ -5,21 +5,22 @@
# Copyright 2019 Tecnativa - Cristina Martin R.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, exceptions, fields, models, _
from odoo import _, api, exceptions, fields, models
class ResPartnerIndustry(models.Model):
_inherit = 'res.partner.industry'
_inherit = "res.partner.industry"
_order = "parent_path"
_parent_order = "name"
_parent_store = True
name = fields.Char(required=True)
parent_id = fields.Many2one(comodel_name='res.partner.industry',
ondelete='restrict')
child_ids = fields.One2many(comodel_name='res.partner.industry',
inverse_name='parent_id',
string="Children")
parent_id = fields.Many2one(
comodel_name="res.partner.industry", ondelete="restrict"
)
child_ids = fields.One2many(
comodel_name="res.partner.industry", inverse_name="parent_id", string="Children"
)
parent_path = fields.Char(index=True)
@api.multi
@ -34,8 +35,9 @@ class ResPartnerIndustry(models.Model):
return [(cat.id, " / ".join(get_names(cat))) for cat in self]
@api.constrains('parent_id')
@api.constrains("parent_id")
def _check_parent_id(self):
if not self._check_recursion():
raise exceptions.ValidationError(
_('Error! You cannot create recursive industries.'))
_("Error! You cannot create recursive industries.")
)

4
partner_industry_secondary/security/partner_industry_security.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<?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"/>
<field name="category_id" ref="base.module_category_hidden" />
</record>
</odoo>

30
partner_industry_secondary/tests/test_res_partner_industry.py

@ -3,30 +3,29 @@
# Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
from odoo.exceptions import ValidationError
from odoo.tests import common
class TestResPartnerIndustry(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestResPartnerIndustry, cls).setUpClass()
cls.industry_model = cls.env['res.partner.industry']
cls.industry_main = cls.industry_model.create({
'name': 'Test',
})
cls.industry_child = cls.industry_model.create({
'name': 'Test child',
'parent_id': cls.industry_main.id,
})
cls.industry_model = cls.env["res.partner.industry"]
cls.industry_main = cls.industry_model.create({"name": "Test",})
cls.industry_child = cls.industry_model.create(
{"name": "Test child", "parent_id": cls.industry_main.id,}
)
def test_check_industries(self):
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Test',
'industry_id': self.industry_main.id,
'secondary_industry_ids': [(4, self.industry_main.id)],
})
self.env["res.partner"].create(
{
"name": "Test",
"industry_id": self.industry_main.id,
"secondary_industry_ids": [(4, self.industry_main.id)],
}
)
def test_check_recursion(self):
with self.assertRaises(ValidationError):
@ -34,6 +33,5 @@ class TestResPartnerIndustry(common.SavepointCase):
def test_name(self):
self.assertEqual(
self.industry_child.name_get()[0][1],
"Test / Test child",
self.industry_child.name_get()[0][1], "Test / Test child",
)

60
partner_industry_secondary/views/res_config_settings.xml

@ -1,35 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- 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_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form</field>
<field name="model">res.config.settings</field>
<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 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_industry_for_person"/>
</div>
<div class="o_setting_right_pane">
<label string="Industry for individual" for="group_use_partner_industry_for_person"/>
<div class="text-muted">
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form</field>
<field name="model">res.config.settings</field>
<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 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_industry_for_person" />
</div>
<div class="o_setting_right_pane">
<label
string="Industry for individual"
for="group_use_partner_industry_for_person"
/>
<div class="text-muted">
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 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>
</xpath>
</field>
</record>
</div>
</xpath>
</field>
</record>
</odoo>

13
partner_industry_secondary/views/res_partner_industry_view.xml

@ -1,29 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 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="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 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="inherit_id" ref="base.res_partner_industry_view_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="parent_id"/>
<field name="parent_id" />
</field>
</field>
</record>
</odoo>

132
partner_industry_secondary/views/res_partner_view.xml

@ -1,115 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2015 Antiun Ingenieria S.L. - Javier Iniesta
Copyright 2018 Eficent Business and IT Consulting Services, S.L. - Jordi Ballester
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<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="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="industry_id" position="after">
<field name="secondary_industry_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"/>
<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="industry_id" placeholder="Sector"
options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False)]}"/>
<field name="secondary_industry_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"/>
<xpath
expr="//field[@name='child_ids']/form//field[@name='title']"
position="after"
>
<field name="is_company" invisible="1" />
<field
name="industry_id"
placeholder="Sector"
options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False)]}"
/>
<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_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="inherit_id" ref="base.view_partner_tree" />
<field name="arch" type="xml">
<field name="email" position="after">
<field name="industry_id"
attrs="{'invisible': [('is_company', '=', False)]}"/>
<field
name="industry_id"
attrs="{'invisible': [('is_company', '=', False)]}"
/>
</field>
</field>
</record>
<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="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<field name="category_id" position="after">
<field name="industry_id"
string="Industry"
filter_domain="['|',('industry_id','ilike',self),
('secondary_industry_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="industry"
string="Industry"
domain="[('is_company','=', True)]"
context="{'group_by': 'industry_id'}"/>
<filter
name="industry"
string="Industry"
domain="[('is_company','=', True)]"
context="{'group_by': 'industry_id'}"
/>
</filter>
</field>
</record>
<!-- Views activated for group_use_partner_industry_for_person -->
<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="base.view_partner_form"/>
<field name="groups_id" eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"/>
<field name="inherit_id" ref="base.view_partner_form" />
<field
name="groups_id"
eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"
/>
<field name="arch" type="xml">
<xpath expr="//page/group/group/field[@name='industry_id']" position="attributes">
<xpath
expr="//page/group/group/field[@name='industry_id']"
position="attributes"
>
<attribute name="attrs">{'invisible': 0}</attribute>
</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_industry_secondary.view_partner_form_industry"/>
<field name="groups_id" eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"/>
<field
name="inherit_id"
ref="partner_industry_secondary.view_partner_form_industry"
/>
<field
name="groups_id"
eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"
/>
<field name="arch" type="xml">
<xpath expr="//page/group/group/field[@name='secondary_industry_ids']" position="attributes">
<xpath
expr="//page/group/group/field[@name='secondary_industry_ids']"
position="attributes"
>
<attribute name="attrs">{'invisible': 0}</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']/form//field[@name='industry_id']" position="attributes">
<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_industry_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_industry_person">
<field name="name">Partner tree with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_industry_secondary.view_partner_tree_industry"/>
<field name="groups_id" eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"/>
<field
name="inherit_id"
ref="partner_industry_secondary.view_partner_tree_industry"
/>
<field
name="groups_id"
eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"
/>
<field name="arch" type="xml">
<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_industry_person">
<field name="name">Partner search with industry</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_industry_secondary.view_res_partner_filter_industry"/>
<field name="groups_id" eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"/>
<field
name="inherit_id"
ref="partner_industry_secondary.view_res_partner_filter_industry"
/>
<field
name="groups_id"
eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"
/>
<field name="arch" type="xml">
<filter name="industry" position="attributes">
<attribute name="domain"/>
<attribute name="domain" />
</filter>
</field>
</record>
</odoo>
Loading…
Cancel
Save