From d34396295b6120fa2b339e81dd17da996447952c Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Sun, 13 Nov 2016 09:09:43 -0800 Subject: [PATCH] [ADD] l10n_us_partner_name: Create module * Add `partner-contact` to OCA depends * Reverse ordering of first and last names provided by `partner_firstname` --- l10n_us_partner_name/README.rst | 63 +++++++++++++++++++ l10n_us_partner_name/__init__.py | 5 ++ l10n_us_partner_name/__manifest__.py | 1 + l10n_us_partner_name/models/__init__.py | 5 ++ l10n_us_partner_name/models/res_partner.py | 26 ++++++++ l10n_us_partner_name/tests/__init__.py | 5 ++ .../tests/test_res_partner.py | 35 +++++++++++ oca_dependencies.txt | 16 +---- 8 files changed, 141 insertions(+), 15 deletions(-) create mode 100644 l10n_us_partner_name/README.rst create mode 100644 l10n_us_partner_name/__init__.py create mode 100644 l10n_us_partner_name/__manifest__.py create mode 100755 l10n_us_partner_name/models/__init__.py create mode 100755 l10n_us_partner_name/models/res_partner.py create mode 100644 l10n_us_partner_name/tests/__init__.py create mode 100644 l10n_us_partner_name/tests/test_res_partner.py diff --git a/l10n_us_partner_name/README.rst b/l10n_us_partner_name/README.rst new file mode 100644 index 00000000..45b3969f --- /dev/null +++ b/l10n_us_partner_name/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +==================== +l10n US Partner Name +==================== + +Use American conventions for partner names: + +* Split first and last names (provided by ``partner_firstname``) +* Display name as ``Firstname Lastname`` + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/203/10.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + + + + +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 smashing it by providing a detailed and welcomed feedback. + + + +Credits +======= + +Contributors +------------ + +* Dave Lasley + +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 http://odoo-community.org. diff --git a/l10n_us_partner_name/__init__.py b/l10n_us_partner_name/__init__.py new file mode 100644 index 00000000..6b7b00c3 --- /dev/null +++ b/l10n_us_partner_name/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import models diff --git a/l10n_us_partner_name/__manifest__.py b/l10n_us_partner_name/__manifest__.py new file mode 100644 index 00000000..e5d3dbca --- /dev/null +++ b/l10n_us_partner_name/__manifest__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- # Copyright 2016 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). { 'name': 'American Partner Name', 'version': '10.0.1.0.0', 'author': "LasLabs, Odoo Community Association (OCA)", 'category': 'Contact Management', "website": "https://laslabs.com", "license": "LGPL-3", "application": False, 'installable': True, 'depends': [ 'partner_firstname', ], } \ No newline at end of file diff --git a/l10n_us_partner_name/models/__init__.py b/l10n_us_partner_name/models/__init__.py new file mode 100755 index 00000000..5e0c3661 --- /dev/null +++ b/l10n_us_partner_name/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import res_partner diff --git a/l10n_us_partner_name/models/res_partner.py b/l10n_us_partner_name/models/res_partner.py new file mode 100755 index 00000000..764c5fde --- /dev/null +++ b/l10n_us_partner_name/models/res_partner.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, models + + +class ResPartner(models.Model): + + _inherit = 'res.partner' + + @api.model + def _get_computed_name(self, lastname, firstname): + return u" ".join((p for p in (firstname, lastname) if p)) + + @api.model + def _get_inverse_name(self, name, is_company=False): + """ It reverses the results of the super to provide ``First Last`` """ + result = super(ResPartner, self)._get_inverse_name( + name, is_company=is_company, + ) + result.update({ + 'firstname': result['lastname'], + 'lastname': result['firstname'], + }) + return result diff --git a/l10n_us_partner_name/tests/__init__.py b/l10n_us_partner_name/tests/__init__.py new file mode 100644 index 00000000..c6280687 --- /dev/null +++ b/l10n_us_partner_name/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import test_res_partner diff --git a/l10n_us_partner_name/tests/test_res_partner.py b/l10n_us_partner_name/tests/test_res_partner.py new file mode 100644 index 00000000..f3b6496a --- /dev/null +++ b/l10n_us_partner_name/tests/test_res_partner.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo.tests.common import TransactionCase + + +class TestResPartner(TransactionCase): + + def setUp(self): + super(TestResPartner, self).setUp() + self.first_name = 'Dave' + self.last_name = 'Lasley' + self.partner = self.env['res.partner'].create({ + 'name': '%s %s' % (self.first_name, self.last_name), + }) + + def test_get_inverse_name_firstname(self): + """ It should properly set firstname on partner """ + self.assertEqual( + self.partner.firstname, self.first_name, + ) + + def test_get_inverse_name_lastname(self): + """ It should properly set lastname on partner """ + self.assertEqual( + self.partner.lastname, self.last_name, + ) + + def test_get_computed_name(self): + """ It should compute name as `Firstname Lastname` """ + self.assertEqual( + self.partner.name, + '%s %s' % (self.first_name, self.last_name), + ) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index ac0117d1..7ab17139 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,15 +1 @@ -# List the OCA project dependencies, one per line -# Add a repository url and branch if you need a forked version -# -# Examples -# ======== -# -# To depend on the standard version of sale-workflow, use: -# sale-workflow -# -# To explicitely give the URL of a fork, and still use the version specified in -# .travis.yml, use: -# sale-workflow https://github.com/OCA/sale-workflow -# -# To provide both the URL and a branch, use: -# sale-workflow https://github.com/OCA/sale-workflow branchname +partner-contact \ No newline at end of file