Merge pull request #41126 from frappe/mergify/bp/version-14-hotfix/pr-40812
fix: Multiple partial payment requests against Purchase Invoice (#40812)
This commit is contained in:
@@ -37,7 +37,7 @@ class PaymentRequest(Document):
|
|||||||
self.status = "Draft"
|
self.status = "Draft"
|
||||||
self.validate_reference_document()
|
self.validate_reference_document()
|
||||||
self.validate_payment_request_amount()
|
self.validate_payment_request_amount()
|
||||||
self.validate_currency()
|
# self.validate_currency()
|
||||||
self.validate_subscription_details()
|
self.validate_subscription_details()
|
||||||
|
|
||||||
def validate_reference_document(self):
|
def validate_reference_document(self):
|
||||||
@@ -276,21 +276,17 @@ class PaymentRequest(Document):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if party_account_currency == ref_doc.company_currency and party_account_currency != self.currency:
|
||||||
|
amount = payment_entry.base_paid_amount
|
||||||
|
else:
|
||||||
|
amount = self.grand_total
|
||||||
|
|
||||||
|
payment_entry.received_amount = amount
|
||||||
|
payment_entry.get("references")[0].allocated_amount = amount
|
||||||
|
|
||||||
for dimension in get_accounting_dimensions():
|
for dimension in get_accounting_dimensions():
|
||||||
payment_entry.update({dimension: self.get(dimension)})
|
payment_entry.update({dimension: self.get(dimension)})
|
||||||
|
|
||||||
if payment_entry.difference_amount:
|
|
||||||
company_details = get_company_defaults(ref_doc.company)
|
|
||||||
|
|
||||||
payment_entry.append(
|
|
||||||
"deductions",
|
|
||||||
{
|
|
||||||
"account": company_details.exchange_gain_loss_account,
|
|
||||||
"cost_center": company_details.cost_center,
|
|
||||||
"amount": payment_entry.difference_amount,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if submit:
|
if submit:
|
||||||
payment_entry.insert(ignore_permissions=True)
|
payment_entry.insert(ignore_permissions=True)
|
||||||
payment_entry.submit()
|
payment_entry.submit()
|
||||||
@@ -432,6 +428,12 @@ def make_payment_request(**args):
|
|||||||
pr = frappe.get_doc("Payment Request", draft_payment_request)
|
pr = frappe.get_doc("Payment Request", draft_payment_request)
|
||||||
else:
|
else:
|
||||||
pr = frappe.new_doc("Payment Request")
|
pr = frappe.new_doc("Payment Request")
|
||||||
|
|
||||||
|
if not args.get("payment_request_type"):
|
||||||
|
args["payment_request_type"] = (
|
||||||
|
"Outward" if args.get("dt") in ["Purchase Order", "Purchase Invoice"] else "Inward"
|
||||||
|
)
|
||||||
|
|
||||||
pr.update(
|
pr.update(
|
||||||
{
|
{
|
||||||
"payment_gateway_account": gateway_account.get("name"),
|
"payment_gateway_account": gateway_account.get("name"),
|
||||||
@@ -490,9 +492,9 @@ def get_amount(ref_doc, payment_account=None):
|
|||||||
elif dt in ["Sales Invoice", "Purchase Invoice"]:
|
elif dt in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
if not ref_doc.get("is_pos"):
|
if not ref_doc.get("is_pos"):
|
||||||
if ref_doc.party_account_currency == ref_doc.currency:
|
if ref_doc.party_account_currency == ref_doc.currency:
|
||||||
grand_total = flt(ref_doc.outstanding_amount)
|
grand_total = flt(ref_doc.grand_total)
|
||||||
else:
|
else:
|
||||||
grand_total = flt(ref_doc.outstanding_amount) / ref_doc.conversion_rate
|
grand_total = flt(ref_doc.base_grand_total) / ref_doc.conversion_rate
|
||||||
elif dt == "Sales Invoice":
|
elif dt == "Sales Invoice":
|
||||||
for pay in ref_doc.payments:
|
for pay in ref_doc.payments:
|
||||||
if pay.type == "Phone" and pay.account == payment_account:
|
if pay.type == "Phone" and pay.account == payment_account:
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class TestPaymentRequest(unittest.TestCase):
|
|||||||
pr = make_payment_request(
|
pr = make_payment_request(
|
||||||
dt="Purchase Invoice",
|
dt="Purchase Invoice",
|
||||||
dn=si_usd.name,
|
dn=si_usd.name,
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier USD",
|
||||||
recipient_id="user@example.com",
|
recipient_id="user@example.com",
|
||||||
mute_email=1,
|
mute_email=1,
|
||||||
payment_gateway_account="_Test Gateway - USD",
|
payment_gateway_account="_Test Gateway - USD",
|
||||||
@@ -98,6 +100,51 @@ class TestPaymentRequest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(pr.status, "Paid")
|
self.assertEqual(pr.status, "Paid")
|
||||||
|
|
||||||
|
def test_multiple_payment_entry_against_purchase_invoice(self):
|
||||||
|
purchase_invoice = make_purchase_invoice(
|
||||||
|
customer="_Test Supplier USD",
|
||||||
|
debit_to="_Test Payable USD - _TC",
|
||||||
|
currency="USD",
|
||||||
|
conversion_rate=50,
|
||||||
|
)
|
||||||
|
|
||||||
|
pr = make_payment_request(
|
||||||
|
dt="Purchase Invoice",
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier USD",
|
||||||
|
dn=purchase_invoice.name,
|
||||||
|
recipient_id="user@example.com",
|
||||||
|
mute_email=1,
|
||||||
|
payment_gateway_account="_Test Gateway - USD",
|
||||||
|
return_doc=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
pr.grand_total = pr.grand_total / 2
|
||||||
|
|
||||||
|
pr.submit()
|
||||||
|
pr.create_payment_entry()
|
||||||
|
|
||||||
|
purchase_invoice.load_from_db()
|
||||||
|
self.assertEqual(purchase_invoice.status, "Partly Paid")
|
||||||
|
|
||||||
|
pr = make_payment_request(
|
||||||
|
dt="Purchase Invoice",
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier USD",
|
||||||
|
dn=purchase_invoice.name,
|
||||||
|
recipient_id="user@example.com",
|
||||||
|
mute_email=1,
|
||||||
|
payment_gateway_account="_Test Gateway - USD",
|
||||||
|
return_doc=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
pr.save()
|
||||||
|
pr.submit()
|
||||||
|
pr.create_payment_entry()
|
||||||
|
|
||||||
|
purchase_invoice.load_from_db()
|
||||||
|
self.assertEqual(purchase_invoice.status, "Paid")
|
||||||
|
|
||||||
def test_payment_entry(self):
|
def test_payment_entry(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Company", "_Test Company", "exchange_gain_loss_account", "_Test Exchange Gain/Loss - _TC"
|
"Company", "_Test Company", "exchange_gain_loss_account", "_Test Exchange Gain/Loss - _TC"
|
||||||
|
|||||||
Reference in New Issue
Block a user