mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-05 22:48:27 +00:00
fix: reverse debit credit for party gl entry in payment entry based on negative amount (#42367)
* fix: do not absolute the amount for party gl entries
* fix: reverse debit credit for party gl entry based on negative amount
* refactor: reduce nesting of if condition
---------
(cherry picked from commit a694390a12)
This commit is contained in:
@@ -37,7 +37,6 @@ from erpnext.accounts.utils import (
|
|||||||
get_account_currency,
|
get_account_currency,
|
||||||
get_balance_on,
|
get_balance_on,
|
||||||
get_outstanding_invoices,
|
get_outstanding_invoices,
|
||||||
get_party_types_from_account_type,
|
|
||||||
)
|
)
|
||||||
from erpnext.controllers.accounts_controller import (
|
from erpnext.controllers.accounts_controller import (
|
||||||
AccountsController,
|
AccountsController,
|
||||||
@@ -1119,12 +1118,16 @@ class PaymentEntry(AccountsController):
|
|||||||
self.make_advance_gl_entries(cancel=cancel)
|
self.make_advance_gl_entries(cancel=cancel)
|
||||||
|
|
||||||
def add_party_gl_entries(self, gl_entries):
|
def add_party_gl_entries(self, gl_entries):
|
||||||
if self.party_account:
|
if not self.party_account:
|
||||||
|
return
|
||||||
|
|
||||||
if self.payment_type == "Receive":
|
if self.payment_type == "Receive":
|
||||||
against_account = self.paid_to
|
against_account = self.paid_to
|
||||||
else:
|
else:
|
||||||
against_account = self.paid_from
|
against_account = self.paid_from
|
||||||
|
|
||||||
|
party_account_type = frappe.db.get_value("Party Type", self.party_type, "account_type")
|
||||||
|
|
||||||
party_gl_dict = self.get_gl_dict(
|
party_gl_dict = self.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": self.party_account,
|
"account": self.party_account,
|
||||||
@@ -1137,8 +1140,6 @@ class PaymentEntry(AccountsController):
|
|||||||
item=self,
|
item=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
|
|
||||||
|
|
||||||
for d in self.get("references"):
|
for d in self.get("references"):
|
||||||
# re-defining dr_or_cr for every reference in order to avoid the last value affecting calculation of reverse
|
# re-defining dr_or_cr for every reference in order to avoid the last value affecting calculation of reverse
|
||||||
dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
|
dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
|
||||||
@@ -1149,32 +1150,22 @@ class PaymentEntry(AccountsController):
|
|||||||
gle = party_gl_dict.copy()
|
gle = party_gl_dict.copy()
|
||||||
|
|
||||||
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
|
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
|
||||||
reverse_dr_or_cr = 0
|
|
||||||
|
|
||||||
if d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]:
|
|
||||||
is_return = frappe.db.get_value(d.reference_doctype, d.reference_name, "is_return")
|
|
||||||
payable_party_types = get_party_types_from_account_type("Payable")
|
|
||||||
receivable_party_types = get_party_types_from_account_type("Receivable")
|
|
||||||
if (
|
if (
|
||||||
is_return
|
d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]
|
||||||
and self.party_type in receivable_party_types
|
and d.allocated_amount < 0
|
||||||
and (self.payment_type == "Pay")
|
and (
|
||||||
|
(party_account_type == "Receivable" and self.payment_type == "Pay")
|
||||||
|
or (party_account_type == "Payable" and self.payment_type == "Receive")
|
||||||
|
)
|
||||||
):
|
):
|
||||||
reverse_dr_or_cr = 1
|
# reversing dr_cr because because it will get reversed in gl processing due to negative amount
|
||||||
elif (
|
|
||||||
is_return
|
|
||||||
and self.party_type in payable_party_types
|
|
||||||
and (self.payment_type == "Receive")
|
|
||||||
):
|
|
||||||
reverse_dr_or_cr = 1
|
|
||||||
|
|
||||||
if is_return and not reverse_dr_or_cr:
|
|
||||||
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
||||||
|
|
||||||
gle.update(
|
gle.update(
|
||||||
{
|
{
|
||||||
dr_or_cr: abs(allocated_amount_in_company_currency),
|
dr_or_cr: allocated_amount_in_company_currency,
|
||||||
dr_or_cr + "_in_account_currency": abs(d.allocated_amount),
|
dr_or_cr + "_in_account_currency": d.allocated_amount,
|
||||||
"against_voucher_type": d.reference_doctype,
|
"against_voucher_type": d.reference_doctype,
|
||||||
"against_voucher": d.reference_name,
|
"against_voucher": d.reference_name,
|
||||||
"cost_center": cost_center,
|
"cost_center": cost_center,
|
||||||
|
|||||||
Reference in New Issue
Block a user