Skip to content

[16.0][FIX] account_payment_return: Post-install test + fallback to load CoA #803

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

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

victoralmau
Copy link
Member

Since odoo/odoo@d0342c8, the default existing company is not getting a CoA automatically, provoking than the current tests fail with the error:

odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale

Thus, we put tests post-install for being sure localization modules are installed, the same as AccountTestInvoicingCommon does, but we don't inherit from it, as it creates an overhead creating 2 new companies and loading their CoA and some more stuff, while we don't need all of that.

Besides, if you don't have l10n_generic_coa installed, you can't use another CoA (like l10n_es) easily, so we put little code to select the first available CoA.

@Tecnativa

Since odoo/odoo@d0342c8, the default existing company is not getting a
CoA automatically, provoking than the current tests fail with the error:

odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale

Thus, we put tests post-install for being sure localization modules are
installed, the same as AccountTestInvoicingCommon does, but we don't
inherit from it, as it creates an overhead creating 2 new companies and
loading their CoA and some more stuff, while we don't need all of that.

Besides, if you don't have `l10n_generic_coa` installed, you can't use
another CoA (like `l10n_es`) easily, so we put little code to select the
first available CoA.
…load CoA

Since odoo/odoo@d0342c8, the default existing company is not getting a
CoA automatically, provoking than the current tests fail with the error:

odoo.exceptions.UserError: No journal could be found in company My Company (San Francisco) for any of those types: sale

Thus, we put tests post-install for being sure localization modules are
installed, the same as AccountTestInvoicingCommon does, but we don't
inherit from it, as it creates an overhead creating 2 new companies and
loading their CoA and some more stuff, while we don't need all of that.

Besides, if you don't have `l10n_generic_coa` installed, you can't use
another CoA (like `l10n_es`) easily, so we put little code to select the
first available CoA.
@pedrobaeza pedrobaeza added this to the 16.0 milestone Feb 25, 2025
@victoralmau victoralmau force-pushed the 16.0-fix-account_payment_return-coa branch 2 times, most recently from 0cac721 to af495de Compare February 25, 2025 15:41
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

This still seems incorrect. You should call super when the file is not a XML one.

@victoralmau
Copy link
Member Author

Sorry, but why block this if the fix in this related case “Post-install test + fallback to load CoA” is clear?

I at least am not going to defend why this is this way

try:
_logger.debug(
"Try parsing as a CAMT Bank to Customer " "Debit Credit Notification."
)
return camt_parser.parse(data_file)
except ValueError:
try:
_logger.debug("Try parsing as a PAIN Direct Debit Unpaid " "Report.")
return pain_parser.parse(data_file)
except ValueError:
_logger.debug(
"Payment return file is not a ISO20022 " "supported file.",
exc_info=True,
)
return super()._parse_file(data_file)
because it will be for something, and changing the behavior I BELIEVE is not the right thing to do.

@pedrobaeza
Copy link
Member

It's not changing the behavior, but fixing the behavior in the proper way. All of this have been because passing to post-install has uncovered a problem, and the problem is that the architecture, as it's though, it's not being respected in the iso20022 module, as instead of calling super when the file is not an XML to let the CSV parser to act, it's just aborting the import process. What you have done with the concatenated try/reraise is to play with the exception types to bypass it, but it's not the proper fix.

Look that this same scheme is done on the statement import, and how is handled in N43 format:

https://github.com/OCA/l10n-spain/blob/aaab375c85e33dff2708396690bf00995f69d166/l10n_es_account_statement_import_n43/wizards/account_statement_import_n43.py#L361

so what you have to do is to catch that a file is not XML (or even not the expected XSD format), and if not, call super for letting the rest of the parsers to act.

@victoralmau
Copy link
Member Author

The error in the tests detected was precisely because in

root = etree.fromstring(data, parser=etree.XMLParser(recover=True))
there was no try/except, therefore, the test failed because it did not return a UserError.

With the current change it ends up calling super() in

and for that reason UserError is returned.

The code is not pretty and/or readable, yes, but I guess, that would be another debate.

@pedrobaeza
Copy link
Member

Well, let me do it the changes I have in mind by myself and check the current test suite. Maybe that one is not correct as well.

… chain

Each extra importer shouldn't stop the parsing chain. This wasn't be
detected before, because the base test was already executed before
installing this module, but now in post-install, this is highlighted.

The fix is to catch any possible error and continue calling super.
@pedrobaeza pedrobaeza force-pushed the 16.0-fix-account_payment_return-coa branch from af495de to 65cab8c Compare February 26, 2025 19:02
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

@victoralmau you can see now what I was talking about. You have to call super, but in the proper method that is doing the iteration.

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 16.0-ocabot-merge-pr-803-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot
Copy link
Contributor

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

@OCA-git-bot OCA-git-bot merged commit e1146fd into OCA:16.0 Feb 26, 2025
5 of 7 checks passed
@pedrobaeza pedrobaeza deleted the 16.0-fix-account_payment_return-coa branch February 26, 2025 19:24
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