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

fix: changes signature of get_total_allocated_amount (backport #144) #145

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name: CI

on:
schedule:
- cron: "42 4 * * *"
push:
branches:
- version-14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,38 @@ def get_linked_payments(
from_reference_date,
to_reference_date,
)
return subtract_allocations(gl_account, matching)
subtract_allocations(gl_account, matching)

return matching


def subtract_allocations(gl_account, vouchers):
"Look up & subtract any existing Bank Transaction allocations"
copied = []
"""Look up & subtract any existing Bank Transaction allocations.

For example, assume `vouchers` contains a Payment Entry of 300 that already
has 100 allocated to some Bank Transaction. This function will subtract 100
from the Payment Entry's outstanding amount, so that the remaining amount
for reconciliation will be 200.

This does not affect "unpaid" vouchers (e.g. unpaid invoices) since they
are never directly allocated to a Bank Transaction.
"""
rows = get_total_allocated_amount([
(voucher.get("doctype"), voucher.get("name"))
for voucher in vouchers
])

if not rows:
return

for voucher in vouchers:
rows = get_total_allocated_amount(voucher.get("doctype"), voucher.get("name"))
amount = None
for row in rows:
if row["gl_account"] == gl_account:
amount = row["total"]
break

if amount:
voucher["paid_amount"] -= amount

copied.append(voucher)
return copied
for (doctype, name), values in rows.items():
if doctype != voucher.get("doctype") or name != voucher.get("name"):
continue

for value in values:
if value["gl_account"] == gl_account:
voucher["paid_amount"] -= value["total"]


def check_matching(
Expand Down
8 changes: 0 additions & 8 deletions banking/klarna_kosma_integration/test_kosma.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def test_transactions_creation(self):
def test_bank_consent_set_get(self):
from banking.klarna_kosma_integration.utils import (
get_consent_data,
get_consent_start_date,
)
from erpnext.accounts.utils import get_fiscal_year

session_data = session_response.session_data
create_session_doc(session_data, session_response.flow_data)
Expand All @@ -227,12 +225,6 @@ def test_bank_consent_set_get(self):
self.assertEqual(consent_id, consent_response.get("consent_id"))
self.assertEqual(consent_token, consent_response.get("consent_token"))

start_date = get_consent_start_date(session_data.get("session_id_short"))
current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)

# check if consent start date is start of fiscal year
self.assertEqual(getdate(start_date), current_fiscal_year.year_start_date)


def get_formatted_consent():
return {
Expand Down
Loading