diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index df9aef69bd05b5ca2ca9a5337a70e3e802d6d861..fcfebb3007435b74f6f987244ed422840c539058 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1721,6 +1721,27 @@ class PaymentEntry(AccountsController): return current_tax_fraction + def add_payment_gateway_fees(self, account, cost_center, fees): + self.add_deductions(account, cost_center, fees) + + def add_payment_gateway_taxes(self, account, cost_center, taxes): + self.add_deductions(account, cost_center, taxes) + + def add_deductions(self, account, cost_center, amount): + self.append( + "deductions", + { + "account": account, + "cost_center": cost_center, + "amount": amount, + }, + ) + + def deduct_fees_from_paid_amount(self, fees): + self.paid_amount = flt(self.paid_amount) - fees + self.received_amount = flt(self.received_amount) - fees + + def validate_inclusive_tax(tax, doc): def _on_previous_row_error(row_range): throw( diff --git a/erpnext/accounts/page/bank_reconciliation/stancer_reconciliation.py b/erpnext/accounts/page/bank_reconciliation/stancer_reconciliation.py index 361440a02b76b4b6d69b71315e19f08b662242c3..34a3bffcd8058dda60e1929931878ebbd6cdc857 100644 --- a/erpnext/accounts/page/bank_reconciliation/stancer_reconciliation.py +++ b/erpnext/accounts/page/bank_reconciliation/stancer_reconciliation.py @@ -3,12 +3,19 @@ import re +from typing import TYPE_CHECKING + + import frappe from payments.payment_gateways.doctype.stancer_settings.api import StancerPaymentsAPI, StancerPayoutsAPI from erpnext.accounts.page.bank_reconciliation.bank_reconciliation import BankReconciliation +if TYPE_CHECKING: + from erpnext.accounts.doctype.payment_entry.payment_entry import PaymentEntry + + def reconcile_stancer_payouts(bank_transactions): stancer_transactions = [ transaction @@ -87,9 +94,10 @@ class StancerReconciliation: found_reference = re.search( r"Ild78-Trans-(?:.*?)Stancer (?:.*?)No(.*?)of", self.bank_transaction.get("description") ) + payments_api = self.stancer_settings.get_payments_api() if found_reference: reference = found_reference.group(1).strip() - payouts_api = StancerPayoutsAPI(self.stancer_settings) + payouts_api = self.stancer_settings.get_payouts_api() for payment_reference in self.payment_references: payouts = payouts_api.get_list(params={"payment": payment_reference}) for payout in payouts.get("payouts", []): @@ -98,13 +106,22 @@ class StancerReconciliation: break if payout_number: - payments = StancerPaymentsAPI(self.stancer_settings).get_list( - params={"payout": payout_number, "limit": 100} - ) + payments = payments_api.get_list(params={"payout": payout_number, "limit": 100}) for payment in payments.get("payments"): - self.payments.append(payment.get("id")) + self.payments.append( + {"id": payment.get("id"), "amount": payment.get("amount"), "fees": payment.get("fees")} + ) def get_payment_references(self): for payment in self.payments: - self.documents.append(frappe.get_doc("Payment Entry", self.payment_references[payment]).as_dict()) + if docname := frappe.db.get_value( + "Payment Entry", dict(docstatus=1, reference_no=self.payment_references[payment]("id")) + ): + doc: PaymentEntry = frappe.get_doc("Payment Entry", docname) # type: ignore + if doc.paid_amount == self.payment_references[payment]("amount") and self.payment_references[ + payment + ]("fees"): + doc = self.stancer_settings.amend_payment_with_fees(doc.name) + + self.documents.append(frappe.get_doc("Payment Entry", docname).as_dict()) # type: ignore