[FIX] account_statement_import_online_paypal: force observance of "Allow Empty Statements" provider setting

Empty statements should only be created if "Allow Empty Statements" is checked. This commit adds a check for the state of the allow_empty_statements field.
This commit is contained in:
Ken Woychesko
2023-05-03 17:06:06 -04:00
committed by Stefan
parent 48a03bdd71
commit 6cce830d7e
5 changed files with 121 additions and 34 deletions

View File

@@ -2,10 +2,13 @@
Online Bank Statements: PayPal.com
==================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:26af4e5288afb6f7af8bd84132925bd6dea1bf3bbb77c739000c747423e4dc9e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
@@ -19,11 +22,11 @@ Online Bank Statements: PayPal.com
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-15-0/bank-statement-import-15-0-account_statement_import_online_paypal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/174/15.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=15.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|
This module provides online bank statements from
`PayPal.com <https://paypal.com/>`__.
@@ -105,7 +108,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_online_paypal%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.

View File

@@ -4,7 +4,7 @@
{
"name": "Online Bank Statements: PayPal.com",
"version": "15.0.1.1.0",
"version": "15.0.1.1.1",
"author": "CorporateHub, Odoo Community Association (OCA)",
"maintainers": ["alexey-pelykh"],
"website": "https://github.com/OCA/bank-statement-import",

View File

@@ -206,8 +206,11 @@ class OnlineBankStatementProviderPayPal(models.Model):
token, currency, date_since, date_until
)
if not transactions:
balance = self._paypal_get_balance(token, currency, date_since)
return [], {"balance_start": balance, "balance_end_real": balance}
if self.allow_empty_statements:
balance = self._paypal_get_balance(token, currency, date_since)
return [], {"balance_start": balance, "balance_end_real": balance}
else:
return None
# Normalize transactions, sort by date, and get lines
transactions = list(

View File

@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Online Bank Statements: PayPal.com</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
@@ -366,27 +366,29 @@ ul.auto-toc {
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:26af4e5288afb6f7af8bd84132925bd6dea1bf3bbb77c739000c747423e4dc9e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/15.0/account_statement_import_online_paypal"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/bank-statement-import-15-0/bank-statement-import-15-0-account_statement_import_online_paypal"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/174/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/15.0/account_statement_import_online_paypal"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-15-0/bank-statement-import-15-0-account_statement_import_online_paypal"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provides online bank statements from
<a class="reference external" href="https://paypal.com/">PayPal.com</a>.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>You will need a <em>Client ID</em> and <em>Secret</em> from PayPal to communicate with the PayPal API. To obtain your PayPal API
<em>Client ID</em> and <em>Secret</em>:</p>
<ol class="arabic simple">
@@ -427,7 +429,7 @@ for Business</em> account. When configuring the provider-specific settings, ente
<a class="reference external" href="https://api.sandbox.paypal.com">https://api.sandbox.paypal.com</a></p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To pull historical bank statements:</p>
<ol class="arabic simple">
<li>Go to <em>Invoicing &gt; Configuration &gt; Accounting &gt; Journals</em>.</li>
@@ -437,7 +439,7 @@ for Business</em> account. When configuring the provider-specific settings, ente
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Only transactions for the previous three years are retrieved, historical data
can be imported manually, see <tt class="docutils literal">account_bank_statement_import_paypal</tt>. See
@@ -453,23 +455,23 @@ behaviour in case #06650320 (private).</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_online_paypal%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>CorporateHub</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://corporatehub.eu/">CorporateHub</a><ul>
<li>Alexey Pelykh &lt;<a class="reference external" href="mailto:alexey.pelykh&#64;corphub.eu">alexey.pelykh&#64;corphub.eu</a>&gt;</li>
@@ -480,14 +482,14 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/alexey-pelykh"><img alt="alexey-pelykh" src="https://github.com/alexey-pelykh.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/alexey-pelykh"><img alt="alexey-pelykh" src="https://github.com/alexey-pelykh.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/15.0/account_statement_import_online_paypal">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>

View File

@@ -275,7 +275,7 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase):
self.now,
)
self.assertEqual(data, ([], {"balance_start": 0.75, "balance_end_real": 0.75}))
self.assertEqual(data, None)
def test_error_handling_1(self):
journal = self.AccountJournal.create(
@@ -331,7 +331,10 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase):
with self.assertRaises(UserError):
provider._paypal_retrieve("https://url", "")
def test_empty_pull(self):
def test_dont_create_empty_paypal_statements(self):
"""Test the default behavior of not creating empty PayPal
statements ('Allow empty statements' field is unchecked).
"""
journal = self.AccountJournal.create(
{
"name": "Bank",
@@ -401,6 +404,82 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase):
self.now,
)
self.assertEqual(data, None)
def test_create_empty_paypal_statements(self):
"""Test creating empty PayPal statements
('Allow empty statements' field is checked).
"""
journal = self.AccountJournal.create(
{
"name": "Bank",
"type": "bank",
"code": "BANK",
"currency_id": self.currency_eur.id,
"bank_statements_source": "online",
"online_bank_statement_provider": "paypal",
}
)
provider = journal.online_bank_statement_provider_id
provider.allow_empty_statements = True
mocked_response_1 = json.loads(
"""{
"transaction_details": [],
"account_number": "1234567890",
"start_date": "%s",
"end_date": "%s",
"last_refreshed_datetime": "%s",
"page": 1,
"total_items": 0,
"total_pages": 0
}"""
% (
self.now_isoformat,
self.now_isoformat,
self.now_isoformat,
),
parse_float=Decimal,
)
mocked_response_2 = json.loads(
"""{
"balances": [
{
"currency": "EUR",
"primary": true,
"total_balance": {
"currency_code": "EUR",
"value": "0.75"
},
"available_balance": {
"currency_code": "EUR",
"value": "0.75"
},
"withheld_balance": {
"currency_code": "EUR",
"value": "0.00"
}
}
],
"account_id": "1234567890",
"as_of_time": "%s",
"last_refresh_time": "%s"
}"""
% (
self.now_isoformat,
self.now_isoformat,
),
parse_float=Decimal,
)
with mock.patch(
_provider_class + "._paypal_retrieve",
side_effect=[mocked_response_1, mocked_response_2],
), self.mock_token():
data = provider._obtain_statement_data(
self.now - relativedelta(hours=1),
self.now,
)
self.assertEqual(data, ([], {"balance_start": 0.75, "balance_end_real": 0.75}))
def test_ancient_pull(self):