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][FIX] account_move_template: Fixed tax and payment term errors while generating journal entries from template #1930

Merged

Conversation

ppyczko
Copy link

@ppyczko ppyczko commented Sep 3, 2024

While trying to create journal entries from a template (Accounting > Configuration > Journal Entry Templates) with an assigned tax amount we encounter the following error related to the invoice_tax_id field:
"ValueError: Invalid field account.tax.repartition.line.invoice_tax_id in leaf ('invoice_tax_id', 'in', [1])"

imagen

The same error occurs with the refund_tax_id field if we check the "Is a refund?" checkbox on one of the lines:
ValueError: Invalid field account.tax.repartition.line.refund_tax_id in leaf ('refund_tax_id', 'in', [1])

These errors are due to changes made in the Odoo core code, where both the invoice_tax_id and refund_tax_id fields were merged into the tax_id field, as seen in the following PR: odoo/odoo@e41f2f7#diff-1ee3fce434db0c4e897973eebf5c1be501196cbd413e6c250ecc973238f939b9L1243

Therefore, this PR replaces the obsolete fields with the correct tax_id field and removes the unnecessary is_refund field.

@ppyczko ppyczko changed the title [FIX] account_move_template: Fixed invoice_tax_id error while generating journal entries from template [17.0][FIX] account_move_template: Fixed invoice_tax_id error while generating journal entries from template Sep 3, 2024
@ppyczko
Copy link
Author

ppyczko commented Sep 3, 2024

Fix for module account_move_template 17.0

cc https://github.com/APSL 160052

@miquelalzanillas @lbarry-apsl @mpascuall @peluko00 @javierobcn @BernatObrador please review

@peluko00
Copy link

peluko00 commented Sep 3, 2024

I found this error with a template that have payment term:

Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 1781, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/opt/odoo/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/opt/odoo/odoo/http.py", line 1808, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/opt/odoo/odoo/http.py", line 2012, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 222, in _dispatch
    result = endpoint(**request.params)
  File "/opt/odoo/odoo/http.py", line 757, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/opt/odoo/addons/web/controllers/dataset.py", line 28, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/addons/web/controllers/dataset.py", line 20, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/mnt/data/odoo-addons-dir/account_move_template/wizard/account_move_template_run.py", line 181, in generate_move
    Command.create(self._prepare_move_line(line, amount))
  File "/mnt/data/odoo-addons-dir/account_move_template/wizard/account_move_template_run.py", line 212, in _prepare_move_line
    pterm_list = line.payment_term_id.compute(value=1, date_ref=self.date)
AttributeError: 'account.payment.term' object has no attribute 'compute'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://oca-account-financial-tools-17-0-pr1930-0618c580f717.runboat.odoo-community.org/web/assets/7d98aa2/web.assets_web.min.js:2888:163)
        at XMLHttpRequest.<anonymous> (http://oca-account-financial-tools-17-0-pr1930-0618c580f717.runboat.odoo-community.org/web/assets/7d98aa2/web.assets_web.min.js:2892:13)

Without it works good!

@ppyczko
Copy link
Author

ppyczko commented Sep 3, 2024

I found this error with a template that have payment term:

Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 1781, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/opt/odoo/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/opt/odoo/odoo/http.py", line 1808, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/opt/odoo/odoo/http.py", line 2012, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 222, in _dispatch
    result = endpoint(**request.params)
  File "/opt/odoo/odoo/http.py", line 757, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/opt/odoo/addons/web/controllers/dataset.py", line 28, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/addons/web/controllers/dataset.py", line 20, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/mnt/data/odoo-addons-dir/account_move_template/wizard/account_move_template_run.py", line 181, in generate_move
    Command.create(self._prepare_move_line(line, amount))
  File "/mnt/data/odoo-addons-dir/account_move_template/wizard/account_move_template_run.py", line 212, in _prepare_move_line
    pterm_list = line.payment_term_id.compute(value=1, date_ref=self.date)
AttributeError: 'account.payment.term' object has no attribute 'compute'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://oca-account-financial-tools-17-0-pr1930-0618c580f717.runboat.odoo-community.org/web/assets/7d98aa2/web.assets_web.min.js:2888:163)
        at XMLHttpRequest.<anonymous> (http://oca-account-financial-tools-17-0-pr1930-0618c580f717.runboat.odoo-community.org/web/assets/7d98aa2/web.assets_web.min.js:2892:13)

Without it works good!

Thank you for pointing this out @peluko00!

Hi @pedrobaeza, my name is Patryk and I work for APSL. I was checking this error related to the payment terms and it seems that it was already happening in the version 16, just checked in the runboat.

The method used earlier to compute the payment terms has seen major changes, as seen on the following link: odoo/odoo@d9057e3?diff=split&w=0#diff-1082eea1e176daccb75f95f20dbfed8f869328635fd041c2f6d6d082f5f05563L74

I'm guessing that all of the new parameters needed in the method call are intended to work with the account.move model, as it contains all of the needed fields: https://github.com/odoo/odoo/blob/17.0/addons/account/models/account_move.py#L416.

My proposition to resolve this error would be to delete the payment terms from this module. My reasoning for this conclusion is that we are generating journal entries, not invoices, therefore, the payment terms shouldn't be needed on each individual journal item.

Would love to hear what you think about this issue, thank you in advance!

@pedrobaeza
Copy link
Member

Well, I don't use this module, so I don't know the original intention of adding the payment term management in it. Your proposal seems reasonable, but it would be good that you blame the code to check which contributor added that code, and maybe discover the reason if they documented correctly, or ask them for details.

@ppyczko
Copy link
Author

ppyczko commented Sep 10, 2024

Thank you for the feedback @pedrobaeza. Searching through existing PR's I found this one already solving the problem: #1892 (with this related issue #1891).

I reached out to the author of the PR, but I haven't received a response. Therefore, I will cherry-pick that commit and supersede the mentioned PR.

@ppyczko ppyczko force-pushed the 17.0-fix-account_move_template-tax_error branch from 0618c58 to 8daf28c Compare September 10, 2024 06:36
@ppyczko ppyczko changed the title [17.0][FIX] account_move_template: Fixed invoice_tax_id error while generating journal entries from template [17.0][FIX] account_move_template: Fixed tax and payment term errors while generating journal entries from template Sep 10, 2024
Copy link

@mpascuall mpascuall left a comment

Choose a reason for hiding this comment

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

LGTM tested in runboat

Copy link

@peluko00 peluko00 left a comment

Choose a reason for hiding this comment

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

LGTM, good work!

Copy link

@BernatObrador BernatObrador left a comment

Choose a reason for hiding this comment

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

LGTM

@ppyczko
Copy link
Author

ppyczko commented Oct 9, 2024

Hi @pedrobaeza, sorry for ping directly, could you please ask maintainers if they can review and merge this PR? Thank you!

This PR superseedes: #1892 (with this related issue #1891).

@pedrobaeza pedrobaeza linked an issue Oct 9, 2024 that may be closed by this pull request
@@ -182,7 +182,7 @@ class AccountMoveTemplateLine(models.Model):
@api.depends("is_refund", "account_id", "tax_line_id")
def _compute_tax_repartition_line_id(self):
for record in self.filtered(lambda x: x.account_id and x.tax_line_id):
tax_repartition = "refund_tax_id" if record.is_refund else "invoice_tax_id"
tax_repartition = "tax_id"
Copy link
Member

Choose a reason for hiding this comment

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

Why removing the refund part?

Copy link
Author

Choose a reason for hiding this comment

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

I removed it as both the invoice_tax_id and refund_tax_id fields were merged into the tax_id field, as seen in the following PR: odoo/odoo@e41f2f7#diff-1ee3fce434db0c4e897973eebf5c1be501196cbd413e6c250ecc973238f939b9L1247

@pedrobaeza
Copy link
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-1930-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 602fd86 into OCA:17.0 Oct 9, 2024
10 of 11 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 2af6e46. Thanks a lot for contributing to OCA. ❤️

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.

account_move_template error V.17
6 participants