Skip to content

Commit

Permalink
Merge pull request #38145 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: v15 Release
  • Loading branch information
deepeshgarg007 authored Nov 17, 2023
2 parents 54a6fba + 20e15eb commit cb725dc
Show file tree
Hide file tree
Showing 42 changed files with 771 additions and 846 deletions.
19 changes: 12 additions & 7 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ def build_gl_map(self):
self.add_bank_gl_entries(gl_entries)
self.add_deductions_gl_entries(gl_entries)
self.add_tax_gl_entries(gl_entries)
add_regional_gl_entries(gl_entries, self)
return gl_entries

def make_gl_entries(self, cancel=0, adv_adj=0):
Expand Down Expand Up @@ -1054,9 +1055,9 @@ def add_party_gl_entries(self, gl_entries):
item=self,
)

dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"

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
dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
cost_center = self.cost_center
if d.reference_doctype == "Sales Invoice" and not cost_center:
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")
Expand All @@ -1072,11 +1073,9 @@ def add_party_gl_entries(self, gl_entries):
against_voucher_type = d.reference_doctype
against_voucher = d.reference_name

reverse_dr_or_cr, standalone_note = 0, 0
reverse_dr_or_cr = 0
if d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]:
is_return, return_against = frappe.db.get_value(
d.reference_doctype, d.reference_name, ["is_return", "return_against"]
)
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 is_return and self.party_type in receivable_party_types and (self.payment_type == "Pay"):
Expand All @@ -1086,7 +1085,7 @@ def add_party_gl_entries(self, gl_entries):
):
reverse_dr_or_cr = 1

if is_return and not return_against and not reverse_dr_or_cr:
if is_return and not reverse_dr_or_cr:
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"

gle.update(
Expand All @@ -1100,6 +1099,7 @@ def add_party_gl_entries(self, gl_entries):
)
gl_entries.append(gle)

dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
if self.unallocated_amount:
exchange_rate = self.get_exchange_rate()
base_unallocated_amount = self.unallocated_amount * exchange_rate
Expand Down Expand Up @@ -2611,3 +2611,8 @@ def set_missing_values(source, target):
)

return doclist


@erpnext.allow_regional
def add_regional_gl_entries(gl_entries, doc):
return
56 changes: 54 additions & 2 deletions erpnext/accounts/doctype/payment_entry/test_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,9 @@ def test_allocation_validation_for_sales_order(self):
self.assertEqual(so.advance_paid, so.rounded_total)

def test_receive_payment_from_payable_party_type(self):
"""
Checks GL entries generated while receiving payments from a Payable Party Type.
"""
pe = create_payment_entry(
party_type="Supplier",
party="_Test Supplier",
Expand All @@ -1261,8 +1264,57 @@ def test_receive_payment_from_payable_party_type(self):
)
self.voucher_no = pe.name
self.expected_gle = [
{"account": "_Test Cash - _TC", "debit": 1000.0, "credit": 0.0},
{"account": "Creditors - _TC", "debit": 0.0, "credit": 1000.0},
{"account": "_Test Cash - _TC", "debit": 1000.0, "credit": 0.0},
]
self.check_gl_entries()

def test_payment_against_partial_return_invoice(self):
"""
Checks GL entries generated for partial return invoice payments.
"""
si = create_sales_invoice(qty=10, rate=10, customer="_Test Customer")
credit_note = create_sales_invoice(
qty=-4, rate=10, customer="_Test Customer", is_return=1, return_against=si.name
)
pe = create_payment_entry(
party_type="Customer",
party="_Test Customer",
payment_type="Receive",
paid_from="Debtors - _TC",
paid_to="_Test Cash - _TC",
)
pe.set(
"references",
[
{
"reference_doctype": "Sales Invoice",
"reference_name": si.name,
"due_date": si.get("due_date"),
"total_amount": si.grand_total,
"outstanding_amount": si.outstanding_amount,
"allocated_amount": si.outstanding_amount,
},
{
"reference_doctype": "Sales Invoice",
"reference_name": credit_note.name,
"due_date": credit_note.get("due_date"),
"total_amount": credit_note.grand_total,
"outstanding_amount": credit_note.outstanding_amount,
"allocated_amount": credit_note.outstanding_amount,
},
],
)
pe.save()
pe.submit()
self.assertEqual(pe.total_allocated_amount, 60)
self.assertEqual(pe.unallocated_amount, 940)
self.voucher_no = pe.name
self.expected_gle = [
{"account": "Debtors - _TC", "debit": 40.0, "credit": 0.0},
{"account": "Debtors - _TC", "debit": 0.0, "credit": 940.0},
{"account": "Debtors - _TC", "debit": 0.0, "credit": 100.0},
{"account": "_Test Cash - _TC", "debit": 1000.0, "credit": 0.0},
]
self.check_gl_entries()

Expand All @@ -1276,7 +1328,7 @@ def check_gl_entries(self):
gle.credit,
)
.where((gle.voucher_no == self.voucher_no) & (gle.is_cancelled == 0))
.orderby(gle.account)
.orderby(gle.account, gle.debit, gle.credit, order=frappe.qb.desc)
).run(as_dict=True)
for row in range(len(self.expected_gle)):
for field in ["account", "debit", "credit"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"label": "Image"
},
{
"fetch_from": "item_code.image",
"fieldname": "image",
"fieldtype": "Attach",
"hidden": 1,
Expand Down Expand Up @@ -833,7 +834,7 @@
],
"istable": 1,
"links": [],
"modified": "2023-03-12 13:36:40.160468",
"modified": "2023-11-14 18:33:22.585715",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Invoice Item",
Expand Down
Loading

0 comments on commit cb725dc

Please sign in to comment.