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][FIX] account_statement_import_online_gocardless: IBAN comparison #686

Conversation

ljsalvatierra-factorlibre
Copy link
Contributor

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre commented Apr 23, 2024

It is possible that, when making the request to the requisitions endpoint, the IBAN bank account comes with a lower alphanumeric string. When comparing with the sanitized bank account (stored with upper) fails.

self.journal_id.bank_account_id.sanitized_acc_number == account_data["iban"]

to

self.journal_id.bank_account_id.sanitized_acc_number == account_data["iban"].upper()

I did refactor the method _gocardless_finish_requisition to be able to mock the requests made inside and create a unit test.

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre changed the title [WIP][16.0][FIX] account_statement_import_online_gocardless: IBAN comparison [16.0][FIX] account_statement_import_online_gocardless: IBAN comparison Apr 24, 2024
@ljsalvatierra-factorlibre ljsalvatierra-factorlibre marked this pull request as ready for review April 25, 2024 07:09
@ljsalvatierra-factorlibre
Copy link
Contributor Author

Hi @pedrobaeza could you take a look please? I've seen that you have recently contributed to the same addon.

@pedrobaeza
Copy link
Member

Please don't put [WIP] in the title, but use Draft status, as now, although you remove it, on mails, it still puts the WIP subject, so this makes people think that is not ready yet:

imagen

Can you please expose the problem this is handling? It should be always put on the initial comment, and also on the commit message.

@pedrobaeza pedrobaeza added this to the 16.0 milestone Apr 25, 2024
@ljsalvatierra-factorlibre
Copy link
Contributor Author

Please don't put [WIP] in the title, but use Draft status, as now, although you remove it, on mails, it still puts the WIP subject, so this makes people think that is not ready yet:

imagen

Can you please expose the problem this is handling? It should be always put on the initial comment, and also on the commit message.

I am aware, won't happen again, thank you.
I've updated the description, sorry for the confussion.

@ljsalvatierra-factorlibre
Copy link
Contributor Author

Hi @pedrobaeza is it ok to merge?

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.

And please put the same explanation of the main comment in the commit expanded message (third line after a blank line and following)

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre force-pushed the 16.0-fix-account_statement_import_online_gocardless branch from 871e9ae to eaac361 Compare April 26, 2024 09:09
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.

Sorry for asking for more modifications, but thinking twice, I think we can refactor this better, having only one method:

    def _gocardless_request(self, path):
        response = requests.get(
            f"{GOCARDLESS_ENDPOINT}/path",
            headers=self._gocardless_get_headers(),
            timeout=REQUESTS_TIMEOUT,
        )
        if response.status_code == 200:
            return json.loads(response.text)
        return {}

and calling it with the multiple variants:

self._gorcardless_request(f"requisitions/{self.gocardless_requisition_id}/")
self._gorcardless_request(f"accounts/{account_id}/")
...

My only doubt is the mock for working properly.

@ljsalvatierra-factorlibre
Copy link
Contributor Author

Sorry for asking for more modifications, but thinking twice, I think we can refactor this better, having only one method:

    def _gocardless_request(self, path):
        response = requests.get(
            f"{GOCARDLESS_ENDPOINT}/path",
            headers=self._gocardless_get_headers(),
            timeout=REQUESTS_TIMEOUT,
        )
        if response.status_code == 200:
            return json.loads(response.text)
        return {}

and calling it with the multiple variants:

self._gorcardless_request(f"requisitions/{self.gocardless_requisition_id}/")
self._gorcardless_request(f"accounts/{account_id}/")
...

My only doubt is the mock for working properly.

I'll take a look thank you, I think it would be possible rewriting the side_effect method returning a different value depending on the arguments.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza
Copy link
Member

Any news on this?

@ljsalvatierra-factorlibre
Copy link
Contributor Author

Any news on this?

Hi, It's in my queue, but currently drowned on more urgent work, I'll try to take a look this week, sorry for the inconvenience.

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre force-pushed the 16.0-fix-account_statement_import_online_gocardless branch from eaac361 to 7354077 Compare August 7, 2024 13:11
@ljsalvatierra-factorlibre
Copy link
Contributor Author

Any news on this?

Hi @pedrobaeza sorry for the delay, please take a look and tell me what you think.

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre force-pushed the 16.0-fix-account_statement_import_online_gocardless branch from 7354077 to c89b0ce Compare August 8, 2024 07:20
@pedrobaeza
Copy link
Member

Please squash comments into one. It's better to amend the previous comment than adding one extra. And finally, [UPD] is not a valid commit tag.

It is possible that, when making the request to the requisitions endpoint,
the IBAN bank account comes with a lower alphanumeric string.
When comparing with the sanitized bank account (stored with upper) fails.

self.journal_id.bank_account_id.sanitized_acc_number == account_data["iban"]

to

self.journal_id.bank_account_id.sanitized_acc_number == account_data["iban"].upper()

Refactor method _gocardless_finish_requisition to be able to mock the requests made inside and create a unit test.
Refactor requests methods.
@ljsalvatierra-factorlibre ljsalvatierra-factorlibre force-pushed the 16.0-fix-account_statement_import_online_gocardless branch from c89b0ce to cd01ed0 Compare August 8, 2024 07:26
@ljsalvatierra-factorlibre
Copy link
Contributor Author

Please squash comments into one. It's better to amend the previous comment than adding one extra. And finally, [UPD] is not a valid commit tag.

Done

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.

Thanks for the refactoring:

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-686-by-pedrobaeza-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 9ca805b into OCA:16.0 Aug 8, 2024
6 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

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

@ljsalvatierra-factorlibre ljsalvatierra-factorlibre deleted the 16.0-fix-account_statement_import_online_gocardless branch August 9, 2024 07:18
pedrobaeza added a commit to Tecnativa/bank-statement-import that referenced this pull request Aug 9, 2024
…ctoring

After the refactoring in OCA#686, this doesn't work anymore:

- The API URL didn't end in "/", so the join_url doesn't do correctly
  the join.
- There's an infinite loop when getting the headers for getting the
  token.
pedrobaeza added a commit to Tecnativa/bank-statement-import that referenced this pull request Aug 9, 2024
…ctoring

After the refactoring in OCA#686, this doesn't work anymore:

- The API URL didn't end in "/", so the join_url doesn't do correctly
  the join.
- There's an infinite loop when getting the headers for getting the
  token.
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.

5 participants