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
Conversation
2203306
to
1889475
Compare
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
def _get_contact_name(self, partner, name): | ||
def _get_complete_name(self): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()]) |
There was a problem hiding this comment.
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 beTROBZ CO.\nLTD\nTrí
which's different from expectedTROBZ 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() |
There was a problem hiding this comment.
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()
1889475
to
7b4eb80
Compare
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() |
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
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.
7b4eb80
to
8ee5bab
Compare
|
||
|
||
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"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8ee5bab
to
319efba
Compare
This change
|
28054d6
to
234aabf
Compare
Currently translated at 100.0% (2 of 2 strings) Translation: partner-contact-16.0/partner-contact-16.0-partner_address_two_lines Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_address_two_lines/it/
234aabf
to
38b03e3
Compare
pattern = r",\s(?=" + re.escape(name) + ")" | ||
partner.display_name = re.sub(pattern, "\n", partner.display_name) | ||
else: | ||
super()._compute_display_name() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Hi anh @nguyenminhchien, this PR is superseded by #2 |
Changes in version 17.0
get_contact_name
is removed._compute_display_name
is used instead ofname_get
due to this commit: Core: Remove name_get and use display_name instead odoo/odoo#122085_get_complete_name