Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] partner_address_two_lines: Migration to 17.0 #1

Closed
wants to merge 14 commits into from

Conversation

trisdoan
Copy link
Owner

@trisdoan trisdoan commented Mar 9, 2024

Changes in version 17.0

  1. get_contact_name is removed. _compute_display_name is used instead of name_get due to this commit: Core: Remove name_get and use display_name instead odoo/odoo#122085
  2. Introduce _get_complete_name

@trisdoan trisdoan changed the title [17.0][MIG] partner_address_two_lines [17.0][MIG] partner_address_two_lines: Migration to 17.0 Mar 9, 2024
@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch 2 times, most recently from 2203306 to 1889475 Compare March 10, 2024 04:40


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

def _get_contact_name(self, partner, name):
def _get_complete_name(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
File "/home/chien/code/oca/partner-contact/17.0/partner_address_two_lines/tests/test_res_partner.py", line 35, in test_get_name
self.child_partner_name.display_name, "Test Company Name\nTest Partner Name"
File "/home/chien/code/odoo/odoo/17.0/odoo/fields.py", line 1206, in get
self.compute_value(recs)
File "/home/chien/code/odoo/odoo/17.0/odoo/fields.py", line 1388, in compute_value
records._compute_field_value(self)
File "/home/chien/code/odoo/odoo/17.0/odoo/models.py", line 4858, in _compute_field_value
fields.determine(field.compute, self)
File "/home/chien/code/odoo/odoo/17.0/odoo/fields.py", line 101, in determine
return needle(*args)
File "/home/chien/code/oca/partner-contact/17.0/partner_address_two_lines/models/res_partner.py", line 39, in _compute_display_name
name = rec._get_complete_name()
File "/home/chien/code/oca/partner-contact/17.0/partner_address_two_lines/models/res_partner.py", line 11, in _get_complete_name
res = super()._get_complete_name()
AttributeError: 'super' object has no attribute '_get_complete_name'

@@ -1,16 +1,40 @@
# Copyright 2020 Camptocamp SA
# Copyright 2024 Camptocamp SA

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change it
image

partner.commercial_company_name or partner.sudo().parent_id.name, name
)
splitted_names = res.split(", ")
return "\n".join([n for n in splitted_names if n.strip()])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's quite risky when using res.split(", "). Imaging that i have:

  • commercial_company_name = TROBZ CO., LTD
  • name = Trí
  • res will be TROBZ CO., LTD, Trí. So, the result will be TROBZ CO.\nLTD\nTrí which's different from expected TROBZ CO., LTD\n Trí

if self.env.context.get("_two_lines_partner_address"):
for rec in self:
name = rec._get_complete_name()
rec.display_name = name.strip()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

       if self.env.context.get("_two_lines_partner_address"):
           for rec in self:
               name = rec._get_complete_name()
               rec.display_name = name.strip()
       else:
           super()._compute_display_name()

@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch from 1889475 to 7b4eb80 Compare March 12, 2024 07:43
name = f"{self.commercial_company_name or self.sudo().parent_id.name}\n{name}" # noqa:E501
elif not self.is_company:
name = f"{self.commercial_company_name or self.sudo().parent_id.name}, {name}" # noqa:E501
return name.strip()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call super() in this function. Otherwise, it could lead to the conflict with other modules.

)

partner_2 = partner_model.create(
{"name": "TROBZ CO., LTD", "company_type": "company"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this, but in the past, people from OCA requested to replace a real company name by a non-existed one.

@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch from 7b4eb80 to 8ee5bab Compare March 12, 2024 10:11


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"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print the Quotation report (of sale.order), you can the Gemini Furniture and YourCompany were shown twice.
I checked v16 and saw that you should update this line to be: if (self.company_name or self.parent_id) and not self.is_company and self.env.context.get("_two_lines_partner_address"):
image

@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch from 8ee5bab to 319efba Compare March 12, 2024 10:57
@trisdoan trisdoan closed this Mar 13, 2024
@trisdoan trisdoan reopened this Apr 29, 2024
@trisdoan
Copy link
Owner Author

trisdoan commented Apr 29, 2024

This change

@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch 4 times, most recently from 28054d6 to 234aabf Compare May 1, 2024 10:15
@trisdoan trisdoan force-pushed the 17.0-mig-partner_address_two_lines branch from 234aabf to 38b03e3 Compare May 2, 2024 08:15
pattern = r",\s(?=" + re.escape(name) + ")"
partner.display_name = re.sub(pattern, "\n", partner.display_name)
else:
super()._compute_display_name()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super() has been called once at line 30

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah silly me 🤣. Thanks a

@@ -0,0 +1,6 @@
import setuptools

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run pre-commit to remove the setup folder. or, remove it manually

@trisdoan
Copy link
Owner Author

trisdoan commented May 8, 2024

Hi anh @nguyenminhchien, this PR is superseded by #2

@trisdoan trisdoan closed this May 8, 2024
@trisdoan trisdoan deleted the 17.0-mig-partner_address_two_lines branch May 24, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants