Skip to content

Commit

Permalink
[ADD] l10n_us_partner_name: Create module
Browse files Browse the repository at this point in the history
* Add `partner-contact` to OCA depends
* Reverse ordering of first and last names provided by `partner_firstname`
  • Loading branch information
lasley committed Nov 13, 2016
1 parent efabd78 commit d343962
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 15 deletions.
63 changes: 63 additions & 0 deletions 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
<https://github.com/OCA/l10n-usa/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 <dave@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 http://odoo-community.org.
5 changes: 5 additions & 0 deletions 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
1 change: 1 addition & 0 deletions 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', ],}
Expand Down
5 changes: 5 additions & 0 deletions 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
26 changes: 26 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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
35 changes: 35 additions & 0 deletions 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),
)
16 changes: 1 addition & 15 deletions 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

0 comments on commit d343962

Please sign in to comment.