Skip to content

Commit

Permalink
[MIG] account_statement_import_online_paypal: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-tecnativa committed Oct 18, 2023
1 parent 6e1d6ae commit ee75acc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 84 deletions.
2 changes: 1 addition & 1 deletion account_statement_import_online_paypal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Online Bank Statements: PayPal.com",
"version": "15.0.1.1.1",
"version": "16.0.1.1.1",
"author": "CorporateHub, Odoo Community Association (OCA)",
"maintainers": ["alexey-pelykh"],
"website": "https://github.com/OCA/bank-statement-import",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,8 @@ def _obtain_statement_data(self, date_since, date_until):
token, currency, date_since, date_until
)
if not transactions:
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
balance = self._paypal_get_balance(token, currency, date_since)
return [], {"balance_start": balance, "balance_end_real": balance}

# Normalize transactions, sort by date, and get lines
transactions = list(
Expand Down Expand Up @@ -416,7 +413,6 @@ def _paypal_get_transactions(self, token, currency, since, until):
interval_start.weekday() == 0
and (datetime.utcnow() - interval_start).total_seconds() < 28800,
)

data = self.with_context(
invalid_data_workaround=invalid_data_workaround,
)._paypal_retrieve(url, token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def test_no_data_on_monday(self):
self.now,
)

self.assertEqual(data, None)
self.assertEqual(data, ([], {"balance_start": 0.75, "balance_end_real": 0.75}))

def test_error_handling_1(self):
journal = self.AccountJournal.create(
Expand Down Expand Up @@ -331,81 +331,6 @@ def test_error_handling_2(self):
with self.assertRaises(UserError):
provider._paypal_retrieve("https://url", "")

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",
"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
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, None)

def test_create_empty_paypal_statements(self):
"""Test creating empty PayPal statements
('Allow empty statements' field is checked).
Expand All @@ -422,7 +347,6 @@ def test_create_empty_paypal_statements(self):
)

provider = journal.online_bank_statement_provider_id
provider.allow_empty_statements = True
mocked_response_1 = json.loads(
"""{
"transaction_details": [],
Expand Down

0 comments on commit ee75acc

Please sign in to comment.