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. 30
      partner_industry_secondary/tests/test_res_partner_industry.py
  7. 20
      partner_industry_secondary/views/res_config_settings.xml
  8. 3
      partner_industry_secondary/views/res_partner_industry_view.xml
  9. 108
      partner_industry_secondary/views/res_partner_view.xml

7
partner_industry_secondary/__manifest__.py

@ -12,15 +12,12 @@
"author": "Tecnativa, Odoo Community Association (OCA)", "author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,
"depends": [
"base_setup",
"contacts",
],
"depends": ["base_setup", "contacts",],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",
"security/partner_industry_security.xml", "security/partner_industry_security.xml",
"views/res_partner_industry_view.xml", "views/res_partner_industry_view.xml",
"views/res_partner_view.xml", "views/res_partner_view.xml",
"views/res_config_settings.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) @openupgrade.migrate(use_env=True)
def migrate(env, version): 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): class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"
group_use_partner_industry_for_person = fields.Boolean( 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. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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): 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( 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): def _check_industries(self):
for partner in self: for partner in self:
if partner.industry_id in partner.secondary_industry_ids: if partner.industry_id in partner.secondary_industry_ids:
raise exceptions.ValidationError( 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. # Copyright 2019 Tecnativa - Cristina Martin R.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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): class ResPartnerIndustry(models.Model):
_inherit = 'res.partner.industry'
_inherit = "res.partner.industry"
_order = "parent_path" _order = "parent_path"
_parent_order = "name" _parent_order = "name"
_parent_store = True _parent_store = True
name = fields.Char(required=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) parent_path = fields.Char(index=True)
@api.multi @api.multi
@ -34,8 +35,9 @@ class ResPartnerIndustry(models.Model):
return [(cat.id, " / ".join(get_names(cat))) for cat in self] return [(cat.id, " / ".join(get_names(cat))) for cat in self]
@api.constrains('parent_id')
@api.constrains("parent_id")
def _check_parent_id(self): def _check_parent_id(self):
if not self._check_recursion(): if not self._check_recursion():
raise exceptions.ValidationError( raise exceptions.ValidationError(
_('Error! You cannot create recursive industries.'))
_("Error! You cannot create recursive industries.")
)

30
partner_industry_secondary/tests/test_res_partner_industry.py

@ -3,30 +3,29 @@
# Copyright 2016 Tecnativa S.L. - Pedro M. Baeza # Copyright 2016 Tecnativa S.L. - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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.exceptions import ValidationError
from odoo.tests import common
class TestResPartnerIndustry(common.SavepointCase): class TestResPartnerIndustry(common.SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestResPartnerIndustry, cls).setUpClass() 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): def test_check_industries(self):
with self.assertRaises(ValidationError): 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): def test_check_recursion(self):
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
@ -34,6 +33,5 @@ class TestResPartnerIndustry(common.SavepointCase):
def test_name(self): def test_name(self):
self.assertEqual( self.assertEqual(
self.industry_child.name_get()[0][1],
"Test / Test child",
self.industry_child.name_get()[0][1], "Test / Test child",
) )

20
partner_industry_secondary/views/res_config_settings.xml

@ -2,7 +2,6 @@
<!-- Copyright 2018 Eficent Business and IT Consulting Services, S.L. <!-- Copyright 2018 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo> <odoo>
<record id="res_config_settings_view_form" model="ir.ui.view"> <record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form</field> <field name="name">res.config.settings.view.form</field>
<field name="model">res.config.settings</field> <field name="model">res.config.settings</field>
@ -16,13 +15,25 @@
<field name="group_use_partner_industry_for_person" /> <field name="group_use_partner_industry_for_person" />
</div> </div>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane">
<label string="Industry for individual" for="group_use_partner_industry_for_person"/>
<label
string="Industry for individual"
for="group_use_partner_industry_for_person"
/>
<div class="text-muted"> <div class="text-muted">
Enable industries for individuals Enable industries for individuals
</div> </div>
<div class="content-group"> <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
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>
</div> </div>
@ -31,5 +42,4 @@
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

3
partner_industry_secondary/views/res_partner_industry_view.xml

@ -3,7 +3,6 @@
Copyright 2018 Eficent Business and IT Consulting Services, S.L. Copyright 2018 Eficent Business and IT Consulting Services, S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo> <odoo>
<record id="res_partner_industry_view_form" model="ir.ui.view"> <record id="res_partner_industry_view_form" model="ir.ui.view">
<field name="name">Industry</field> <field name="name">Industry</field>
<field name="model">res.partner.industry</field> <field name="model">res.partner.industry</field>
@ -14,7 +13,6 @@
</field> </field>
</field> </field>
</record> </record>
<record id="res_partner_industry_view_tree" model="ir.ui.view"> <record id="res_partner_industry_view_tree" model="ir.ui.view">
<field name="name">Industry</field> <field name="name">Industry</field>
<field name="model">res.partner.industry</field> <field name="model">res.partner.industry</field>
@ -25,5 +23,4 @@
</field> </field>
</field> </field>
</record> </record>
</odoo> </odoo>

108
partner_industry_secondary/views/res_partner_view.xml

@ -3,113 +3,155 @@
Copyright 2018 Eficent Business and IT Consulting Services, S.L. - Jordi Ballester 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). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo> <odoo>
<record model="ir.ui.view" id="view_partner_form_industry"> <record model="ir.ui.view" id="view_partner_form_industry">
<field name="name">Partner form with industry</field> <field name="name">Partner form with industry</field>
<field name="model">res.partner</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="arch" type="xml">
<field name="industry_id" position="after"> <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> </field>
<xpath expr="//field[@name='child_ids']/form//field[@name='title']" position="after">
<xpath
expr="//field[@name='child_ids']/form//field[@name='title']"
position="after"
>
<field name="is_company" invisible="1" /> <field name="is_company" invisible="1" />
<field name="industry_id" placeholder="Sector"
<field
name="industry_id"
placeholder="Sector"
options='{"no_open": True}' options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', False)]}"/>
<field name="secondary_industry_ids" widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"/>
attrs="{'invisible': [('is_company', '=', False)]}"
/>
<field
name="secondary_industry_ids"
widget="many2many_tags"
attrs="{'invisible': [('is_company', '=', False)]}"
/>
</xpath> </xpath>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="view_partner_tree_industry"> <record model="ir.ui.view" id="view_partner_tree_industry">
<field name="name">Partner tree with industry</field> <field name="name">Partner tree with industry</field>
<field name="model">res.partner</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="arch" type="xml">
<field name="email" position="after"> <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>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="view_res_partner_filter_industry"> <record model="ir.ui.view" id="view_res_partner_filter_industry">
<field name="name">Partner search with industry</field> <field name="name">Partner search with industry</field>
<field name="model">res.partner</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="arch" type="xml">
<field name="category_id" position="after"> <field name="category_id" position="after">
<field name="industry_id"
<field
name="industry_id"
string="Industry" string="Industry"
filter_domain="['|',('industry_id','ilike',self), filter_domain="['|',('industry_id','ilike',self),
('secondary_industry_ids.name','ilike',self)]"/>
('secondary_industry_ids.name','ilike',self)]"
/>
</field> </field>
<filter name="salesperson" position="after"> <filter name="salesperson" position="after">
<filter name="industry"
<filter
name="industry"
string="Industry" string="Industry"
domain="[('is_company','=', True)]" domain="[('is_company','=', True)]"
context="{'group_by': 'industry_id'}"/>
context="{'group_by': 'industry_id'}"
/>
</filter> </filter>
</field> </field>
</record> </record>
<!-- Views activated for group_use_partner_industry_for_person --> <!-- Views activated for group_use_partner_industry_for_person -->
<record model="ir.ui.view" id="view_partner_form_industry_person0"> <record model="ir.ui.view" id="view_partner_form_industry_person0">
<field name="name">Partner form with industry</field> <field name="name">Partner form with industry</field>
<field name="model">res.partner</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="groups_id" eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"/>
<field
name="groups_id"
eval="[(4, ref('partner_industry_secondary.group_use_partner_industry_for_person'))]"
/>
<field name="arch" type="xml"> <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> <attribute name="attrs">{'invisible': 0}</attribute>
</xpath> </xpath>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="view_partner_form_industry_person"> <record model="ir.ui.view" id="view_partner_form_industry_person">
<field name="name">Partner form with industry</field> <field name="name">Partner form with industry</field>
<field name="model">res.partner</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"> <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> <attribute name="attrs">{'invisible': 0}</attribute>
</xpath> </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> <attribute name="attrs">{'invisible': 0}</attribute>
</xpath> </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> <attribute name="attrs">{'invisible': 0}</attribute>
</xpath> </xpath>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="view_partner_tree_industry_person"> <record model="ir.ui.view" id="view_partner_tree_industry_person">
<field name="name">Partner tree with industry</field> <field name="name">Partner tree with industry</field>
<field name="model">res.partner</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="arch" type="xml">
<field name="industry_id" position="attributes"> <field name="industry_id" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute> <attribute name="attrs">{'invisible': 0}</attribute>
</field> </field>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="view_res_partner_filter_industry_person"> <record model="ir.ui.view" id="view_res_partner_filter_industry_person">
<field name="name">Partner search with industry</field> <field name="name">Partner search with industry</field>
<field name="model">res.partner</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"> <field name="arch" type="xml">
<filter name="industry" position="attributes"> <filter name="industry" position="attributes">
<attribute name="domain" /> <attribute name="domain" />
</filter> </filter>
</field> </field>
</record> </record>
</odoo> </odoo>
Loading…
Cancel
Save