diff --git a/partner_alias/README.rst b/partner_alias/README.rst new file mode 100644 index 000000000..30329b911 --- /dev/null +++ b/partner_alias/README.rst @@ -0,0 +1,60 @@ +.. 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 Alias +============= + +This module extends partners with the concepts of aliases. + +Usage +===== + +* Simply navigate to the form view of the partner, click on `Personal Information` + (only visible if the partner is an individual), and the alias attributes are below. + +.. 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/10.0 + +Known issues / Roadmap +====================== + +* Upgrade One2many alias_ids tree to tags when One2many tags module available. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Brett Wood + +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. diff --git a/partner_alias/__init__.py b/partner_alias/__init__.py new file mode 100644 index 000000000..b7a0aa9ca --- /dev/null +++ b/partner_alias/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_alias/__manifest__.py b/partner_alias/__manifest__.py new file mode 100644 index 000000000..de6375e91 --- /dev/null +++ b/partner_alias/__manifest__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Alias", + "summary": "Adds aliases to partner names.", + "version": "10.0.1.0.0", + "category": "Contacts", + "website": "https://laslabs.com", + "author": "Laslabs, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "partner_contact_personal_information_page", + "partner_firstname", + ], + "data": [ + "security/ir.model.access.csv", + "views/res_partner_view.xml", + "views/res_partner_alias_view.xml", + ], + "demo": [ + "demo/res_partner_demo.xml", + "demo/res_partner_alias_demo.xml", + ], +} diff --git a/partner_alias/demo/res_partner_alias_demo.xml b/partner_alias/demo/res_partner_alias_demo.xml new file mode 100644 index 000000000..86687de99 --- /dev/null +++ b/partner_alias/demo/res_partner_alias_demo.xml @@ -0,0 +1,17 @@ + + + + + + + Phillip + + + + + Greg + + + + diff --git a/partner_alias/demo/res_partner_demo.xml b/partner_alias/demo/res_partner_demo.xml new file mode 100644 index 000000000..99d12df54 --- /dev/null +++ b/partner_alias/demo/res_partner_demo.xml @@ -0,0 +1,12 @@ + + + + + + + Malcom + Widdleton + + + diff --git a/partner_alias/models/__init__.py b/partner_alias/models/__init__.py new file mode 100644 index 000000000..33e539a32 --- /dev/null +++ b/partner_alias/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_partner +from . import res_partner_alias diff --git a/partner_alias/models/res_partner.py b/partner_alias/models/res_partner.py new file mode 100644 index 000000000..241c0efd4 --- /dev/null +++ b/partner_alias/models/res_partner.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResPartner(models.Model): + + _inherit = 'res.partner' + + alias_ids = fields.One2many( + string='Aliases', + comodel_name='res.partner.alias', + inverse_name='partner_id', + ) diff --git a/partner_alias/models/res_partner_alias.py b/partner_alias/models/res_partner_alias.py new file mode 100644 index 000000000..c58fef61d --- /dev/null +++ b/partner_alias/models/res_partner_alias.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ResPartnerAlias(models.Model): + + _inherits = {'res.partner': 'partner_id'} + _name = 'res.partner.alias' + _description = 'Res Partner Alias' + + partner_id = fields.Many2one( + string='Related Partner', + comodel_name='res.partner', + required=True, + ondelete='cascade', + index=True, + ) + firstname = fields.Char( + string='First Name', + required=True, + ) + + @api.multi + @api.constrains('firstname') + def _check_firstname(self): + for record in self: + if record.firstname == record.partner_id.firstname: + raise ValidationError(_( + 'Alias first name cannot be the same as ' + 'primary firstname' + )) + + _sql_constraints = [ + ('alias_name_uniq', + 'UNIQUE(firstname)', + 'Alias first name must be unique'), + ] diff --git a/partner_alias/security/ir.model.access.csv b/partner_alias/security/ir.model.access.csv new file mode 100644 index 000000000..a33b6ed01 --- /dev/null +++ b/partner_alias/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +res_partner_alias_user,res_partner_alias group_user,model_res_partner_alias,base.group_user,1,1,1,1 diff --git a/partner_alias/static/description/icon.png b/partner_alias/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_alias/static/description/icon.png differ diff --git a/partner_alias/tests/__init__.py b/partner_alias/tests/__init__.py new file mode 100644 index 000000000..1477b9569 --- /dev/null +++ b/partner_alias/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_partner_alias diff --git a/partner_alias/tests/test_partner_alias.py b/partner_alias/tests/test_partner_alias.py new file mode 100644 index 000000000..8d1aeeb69 --- /dev/null +++ b/partner_alias/tests/test_partner_alias.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + +from odoo.exceptions import ValidationError +from psycopg2 import IntegrityError + + +class TestPartnerAlias(TransactionCase): + + def setUp(self): + super(TestPartnerAlias, self).setUp() + self.alias_1 = self.env.ref( + 'partner_alias.res_partner_alias_alias_1' + ) + + def test_check_name(self): + """ Test raise ValidationError if alias name same as partner """ + with self.assertRaises(ValidationError): + self.alias_1.firstname = 'Malcom' + + def test_unique_name(self): + """ Test raises IntegrityError is name not unique """ + with self.assertRaises(IntegrityError): + self.alias_1.firstname = 'Greg' diff --git a/partner_alias/views/res_partner_alias_view.xml b/partner_alias/views/res_partner_alias_view.xml new file mode 100644 index 000000000..d316925e9 --- /dev/null +++ b/partner_alias/views/res_partner_alias_view.xml @@ -0,0 +1,52 @@ + + + + + + + res.partner.alias.view.tree + res.partner.alias + + + + + + + + + res.partner.alias.view.form + res.partner.alias + +
+ + + + + +
+
+
+ + + res.partner.alias.view.search + res.partner.alias + + + + + + + + + Aliases + ir.actions.act_window + res.partner.alias + form + tree,form + + [] + {} + + +
diff --git a/partner_alias/views/res_partner_view.xml b/partner_alias/views/res_partner_view.xml new file mode 100644 index 000000000..d34335c4b --- /dev/null +++ b/partner_alias/views/res_partner_view.xml @@ -0,0 +1,25 @@ + + + + + + + Personal information page for contacts form + res.partner + + + + + + + + + + + + + + +