Browse Source

[ADD] partner_alias: Add module.

* Extends res partner with firstname aliases
pull/382/head
Brett Wood 8 years ago
parent
commit
a5985e2e61
  1. 60
      partner_alias/README.rst
  2. 5
      partner_alias/__init__.py
  3. 28
      partner_alias/__manifest__.py
  4. 17
      partner_alias/demo/res_partner_alias_demo.xml
  5. 12
      partner_alias/demo/res_partner_demo.xml
  6. 6
      partner_alias/models/__init__.py
  7. 16
      partner_alias/models/res_partner.py
  8. 41
      partner_alias/models/res_partner_alias.py
  9. 0
      partner_alias/security/ir.model.access.csv
  10. BIN
      partner_alias/static/description/icon.png
  11. 5
      partner_alias/tests/__init__.py
  12. 27
      partner_alias/tests/test_partner_alias.py
  13. 52
      partner_alias/views/res_partner_alias_view.xml
  14. 26
      partner_alias/views/res_partner_view.xml

60
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
<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
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Brett Wood <bwood@laslabs.com>
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.

5
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

28
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",
],
}

17
partner_alias/demo/res_partner_alias_demo.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 LasLabs Inc.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_partner_alias_alias_1" model="res.partner.alias">
<field name="firstname">Phillip</field>
<field name="partner_id" ref="res_partner_partner_malcom" />
</record>
<record id="res_partner_alias_alias_2" model="res.partner.alias">
<field name="firstname">Greg</field>
<field name="partner_id" ref="res_partner_partner_malcom" />
</record>
</odoo>

12
partner_alias/demo/res_partner_demo.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 LasLabs Inc.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_partner_partner_malcom" model="res.partner">
<field name="firstname">Malcom</field>
<field name="lastname">Widdleton</field>
</record>
</odoo>

6
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

16
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',
)

41
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'),
]

0
partner_alias/security/ir.model.access.csv

BIN
partner_alias/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

5
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

27
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'

52
partner_alias/views/res_partner_alias_view.xml

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 LasLabs Inc.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_partner_alias_view_tree" model="ir.ui.view">
<field name="name">res.partner.alias.view.tree</field>
<field name="model">res.partner.alias</field>
<field name="arch" type="xml">
<tree string="Partner Aliases">
<field name="firstname" />
</tree>
</field>
</record>
<record id="res_partner_alias_view_form" model="ir.ui.view">
<field name="name">res.partner.alias.view.form</field>
<field name="model">res.partner.alias</field>
<field name="arch" type="xml">
<form string="Partner Alias">
<group>
<group>
<field name="firstname" />
</group>
</group>
</form>
</field>
</record>
<record id="res_partner_alias_view_search" model="ir.ui.view">
<field name="name">res.partner.alias.view.search</field>
<field name="model">res.partner.alias</field>
<field name="arch" type="xml">
<search string="Partner Aliases">
<field name="firstname" />
</search>
</field>
</record>
<record id="res_partner_alias_action" model="ir.actions.act_window">
<field name="name">Aliases</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner.alias</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="res_partner_alias_view_search" />
<field name="domain">[]</field>
<field name="context">{}</field>
</record>
</odoo>

26
partner_alias/views/res_partner_view.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 LasLabs Inc.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="personal_information" model="ir.ui.view">
<field name="name">Personal information page for contacts form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_contact_personal_information_page.personal_information" />
<field name="arch" type="xml">
<xpath expr="//page[@name='personal_information_page']" position="inside">
<group string="Aliases" name="aliases">
<field name="alias_ids" nolabel="1">
<tree editable="bottom"
context="{'default_partner_id': id}"
>
<field name="firstname" />
</tree>
</field>
</group>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save