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

[16.0] [ADD] account_chart_update_multilang - new module #1957

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from

Conversation

edlopen
Copy link
Member

@edlopen edlopen commented Oct 25, 2024

This new module extends the functionality of account_chart_update so that if the tax or fiscal position template has translated fields, it is passed to the final tax or fiscal position when applying the chart of accounts.

https://www.loom.com/share/ddc5e524a5f540e3ae680dc7f40d0090?sid=872b10d1-9a61-4d52-8452-91546a77ccbe

Although I am working to improve, please bear with me because of my English.

@Shide @yajo @rafaelbn please review, if you can.

@moduon MT-7597

@edlopen
Copy link
Member Author

edlopen commented Oct 25, 2024

I'll address the test error on Monday. I have no clue of why is failing at the moment.

account_chart_update_multilang/__manifest__.py Outdated Show resolved Hide resolved
account_chart_update_multilang/__manifest__.py Outdated Show resolved Hide resolved
account_chart_update_multilang/__manifest__.py Outdated Show resolved Hide resolved
account_chart_update_multilang/readme/DESCRIPTION.md Outdated Show resolved Hide resolved
account_chart_update_multilang/readme/USAGE.md Outdated Show resolved Hide resolved
@edlopen edlopen force-pushed the 16.0-add-account_chart_update_multilang branch from b605539 to 36534e1 Compare October 28, 2024 09:46
@edlopen edlopen force-pushed the 16.0-add-account_chart_update_multilang branch 2 times, most recently from b6ffa87 to 6bfeb3d Compare October 31, 2024 16:11
@rafaelbn rafaelbn added this to the 16.0 milestone Oct 31, 2024
Comment on lines +786 to +787
@api.model
@tools.ormcache("name")
Copy link
Member

Choose a reason for hiding this comment

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

This is not an api.model function because it does need a record.

Besides, caching it won't save much time because the things it does are quite cheap.

return self.env["res.lang"].search([("code", "!=", self.lang)]).mapped("code")

def _update_other_langs(self, templates):
for _, tpl_xmlid in templates.get_external_id().items():
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for _, tpl_xmlid in templates.get_external_id().items():
for tpl_xmlid in templates.get_external_id().values():

Comment on lines +30 to +50
to_include = self.fields_to_include(template._name)
for key in template._fields:
if not template._fields[key].translate or key not in to_include:
continue
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: here you're iterating over all fields and then checking if they are in a list, which in turn loops behind the scenes to do that check.

It seems flipping the logic makes more sense:

Suggested change
to_include = self.fields_to_include(template._name)
for key in template._fields:
if not template._fields[key].translate or key not in to_include:
continue
to_include = self.fields_to_include(template._name)
for key in to_include:
if not template._fields[key].translate:
continue

Comment on lines +35 to +55
template_trans = getattr(template.with_context(lang=lang), key)
real_trans = getattr(real.with_context(lang=lang), key)
if template_trans != real_trans:
res[key] = template[key]
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Don't use getattr if you can avoid it, for security reasons. It was explained in some OXP security talk but I can't remember the year... In short, it makes sure the thing you're accessing is a field and not a method, property or something else.

Suggested change
template_trans = getattr(template.with_context(lang=lang), key)
real_trans = getattr(real.with_context(lang=lang), key)
if template_trans != real_trans:
res[key] = template[key]
template_trans = template.with_context(lang=lang)[key]
real_trans = real.with_context(lang=lang)[key]
if template_trans != real_trans:
res[key] = template[key]

@yajo
Copy link
Member

yajo commented Nov 1, 2024

I've diagnosed a bit more the problem of not being able to translate notes in fiscal positions. It's due to how the html translation algorithm works. Pushing a wip fix. Could you set this as draft please?

@yajo yajo force-pushed the 16.0-add-account_chart_update_multilang branch from e8c7b58 to 0806aaf Compare November 1, 2024 13:53
@yajo yajo force-pushed the 16.0-add-account_chart_update_multilang branch from 0806aaf to ff8e9ef Compare November 1, 2024 13:56
The algorithm to translate them is done by terms, which is a bit clunky for our use case.

However, since `account.fiscal.position.template`'s note field is Text, not Html, and that's the one we care about, we can predict that the Html version will just wrap it with a <p> tag.

Well, in short, it's ugly but works.

MT-7597
@yajo yajo force-pushed the 16.0-add-account_chart_update_multilang branch from ff8e9ef to e9dd1a3 Compare November 1, 2024 15:13
@yajo
Copy link
Member

yajo commented Nov 1, 2024

Last push should fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants