forked from OCA/partner-contact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] partner_address_two_lines: Migration to 17.0
- Loading branch information
Showing
8 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |