Skip to content

Commit

Permalink
[MIG] partner_address_two_lines: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Mar 12, 2024
1 parent b9994ff commit 8ee5bab
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 8 deletions.
10 changes: 10 additions & 0 deletions partner_address_two_lines/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ Contributors

- Thomas Nowicki <thomas.nowicki@camptocamp.com>
- Akim Juillerat <akim.juillerat@camptocamp.com>
- Juan Miguel Sánchez Arce juan.sanchez@camptocamp.com
- `Trobz <https://www.trobz.com>`__:

- Tris Doan <tridm@trobz.com>

Other credits
-------------

The migration of this module from 16.0 to 17.0 was financially supported
by Camptocamp

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion partner_address_two_lines/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Partner address in two lines",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": "The company and the partner name are on two different lines",
"author": "Camptocamp," "Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
45 changes: 40 additions & 5 deletions partner_address_two_lines/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models
from odoo import api, models


class ResPartner(models.Model):
_inherit = "res.partner"

def _get_contact_name(self, partner, name):
def _get_complete_name(self):
res = super()._get_complete_name()
if self.env.context.get("_two_lines_partner_address"):
return "{}\n {}".format(
partner.commercial_company_name or partner.sudo().parent_id.name, name
displayed_types = self._complete_name_displayed_types
type_description = dict(
self._fields["type"]._description_selection(self.env)
)

name = self.name or ""
if not name and self.type in displayed_types:
name = type_description[self.type]
name = (
f"{self.commercial_company_name or self.sudo().parent_id.name}\n{name}"
)
res = name.strip()
return res

@api.depends(
"complete_name",
"email",
"vat",
"state_id",
"country_id",
"commercial_company_name",
)
@api.depends_context(
"show_address",
"partner_show_db_id",
"address_inline",
"show_email",
"show_vat",
"lang",
"_two_lines_partner_address",
)
def _compute_display_name(self): # pylint: disable=W8110
super()._compute_display_name()
if self.env.context.get("_two_lines_partner_address"):
for rec in self:
name = rec._get_complete_name()
rec.display_name = name.strip()
else:
return super()._get_contact_name(partner, name)
super()._compute_display_name()
3 changes: 3 additions & 0 deletions partner_address_two_lines/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
- Thomas Nowicki \<<thomas.nowicki@camptocamp.com>\>
- Akim Juillerat \<<akim.juillerat@camptocamp.com>\>
- Juan Miguel Sánchez Arce <juan.sanchez@camptocamp.com>
- [Trobz](https://www.trobz.com):
- Tris Doan \<<tridm@trobz.com>\>
2 changes: 2 additions & 0 deletions partner_address_two_lines/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The migration of this module from 16.0 to 17.0 was financially supported
by Camptocamp
15 changes: 13 additions & 2 deletions partner_address_two_lines/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ <h1 class="title">Partner address in two lines</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -404,10 +405,20 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Thomas Nowicki &lt;<a class="reference external" href="mailto:thomas.nowicki&#64;camptocamp.com">thomas.nowicki&#64;camptocamp.com</a>&gt;</li>
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
<li>Juan Miguel Sánchez Arce <a class="reference external" href="mailto:juan.sanchez&#64;camptocamp.com">juan.sanchez&#64;camptocamp.com</a></li>
<li><a class="reference external" href="https://www.trobz.com">Trobz</a>:<ul>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The migration of this module from 16.0 to 17.0 was financially supported
by Camptocamp</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
1 change: 1 addition & 0 deletions partner_address_two_lines/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_res_partner
63 changes: 63 additions & 0 deletions partner_address_two_lines/tests/test_res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase

VALID_HASHES = {
"base.partner:_get_complete_name": ["bcff3ffbe5ffeaa8f71d1563f8dbd108"],
}


class TestBasePartnerTwoLine(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
partner_model = cls.env["res.partner"].with_context(
_two_lines_partner_address=True
)
partner = partner_model.create(
{"name": "Test Company Name", "company_type": "company"}
)
cls.child_partner_name = partner_model.create(
{
"name": "Test Partner Name",
"type": "invoice",
"parent_id": partner.id,
}
)
cls.child_partner_no_name = partner_model.create(
{
"name": "",
"type": "invoice",
"parent_id": partner.id,
}
)

partner_2 = partner_model.create(
{"name": "Test Company, LTD", "company_type": "company"}
)

cls.child_partner_name_2 = partner_model.create(
{
"name": "Test Partner Name 2",
"type": "invoice",
"parent_id": partner_2.id,
}
)

def test_get_name(self):
# Partner with name.
self.assertEqual(
self.child_partner_name.display_name, "Test Company Name\nTest Partner Name"
)

self.assertEqual(
self.child_partner_name_2.display_name,
"Test Company, LTD\nTest Partner Name 2",
)

# Partner without a name.
self.assertEqual(
self.child_partner_no_name.display_name,
"Test Company Name\nInvoice Address",
)

0 comments on commit 8ee5bab

Please sign in to comment.