Skip to content

Commit

Permalink
[FIX] partner_display_name_line_break: Do not split with empty name
Browse files Browse the repository at this point in the history
Do not split on two lines if name is empty as it would display
the address type on a new line in the report.
This happens because Odoo splits the display_name on \n character
and discards the first element to get the address from the
display_name. In which case, the address type would appear as
part of the address.

In case this is still needed, an added context key allows to still
display the address type.
  • Loading branch information
grindtildeath committed Oct 28, 2024
1 parent f53d667 commit ec621ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions partner_display_name_line_break/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def _compute_display_name(self): # pylint: disable=W8110
super()._compute_display_name()
if self.env.context.get("_two_lines_partner_address"):
for partner in self:
# Do not split on two lines if name is empty as it would display
# the address type on a new line in the report.
# This happens because Odoo splits the display_name on \n character
# and discards the first element to get the address from the
# display_name. In which case, the address type would appear as
# part of the address.
if not partner.name and not self.env.context.get(
"_keep_partner_address_type"
):
continue
displayed_types = partner._complete_name_displayed_types
type_description = dict(
partner._fields["type"]._description_selection(partner.env)
Expand Down
6 changes: 6 additions & 0 deletions partner_display_name_line_break/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,11 @@ def test_get_name(self):
# Partner without a name.
self.assertEqual(
self.child_partner_no_name.display_name,
"Test Company Name, Invoice Address",
)
self.assertEqual(
self.child_partner_no_name.with_context(
_keep_partner_address_type=True
).display_name,
"Test Company Name\nInvoice Address",
)

0 comments on commit ec621ad

Please sign in to comment.