Skip to content

Commit

Permalink
fix: Unable to create payment request against purchase invoice (frapp…
Browse files Browse the repository at this point in the history
…e#34762)

fix: Unable to create payment request against purchase invoice (frappe#34762)

(cherry picked from commit 91a2660)

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
  • Loading branch information
mergify[bot] and deepeshgarg007 authored Apr 6, 2023
1 parent 915c481 commit a1f7e35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def get_amount(ref_doc, payment_account=None):
if dt in ["Sales Order", "Purchase Order"]:
grand_total = flt(ref_doc.rounded_total) or flt(ref_doc.grand_total)
elif dt in ["Sales Invoice", "Purchase Invoice"]:
if not ref_doc.is_pos:
if not ref_doc.get("is_pos"):
if ref_doc.party_account_currency == ref_doc.currency:
grand_total = flt(ref_doc.outstanding_amount)
else:
Expand Down
24 changes: 24 additions & 0 deletions erpnext/accounts/doctype/payment_request/test_payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import frappe

from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.setup.utils import get_exchange_rate
Expand Down Expand Up @@ -74,6 +75,29 @@ def test_payment_request_linkings(self):
self.assertEqual(pr.reference_name, si_usd.name)
self.assertEqual(pr.currency, "USD")

def test_payment_entry_against_purchase_invoice(self):
si_usd = 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",
dn=si_usd.name,
recipient_id="user@example.com",
mute_email=1,
payment_gateway_account="_Test Gateway - USD",
submit_doc=1,
return_doc=1,
)

pe = pr.create_payment_entry()
pr.load_from_db()

self.assertEqual(pr.status, "Paid")

def test_payment_entry(self):
frappe.db.set_value(
"Company", "_Test Company", "exchange_gain_loss_account", "_Test Exchange Gain/Loss - _TC"
Expand Down

0 comments on commit a1f7e35

Please sign in to comment.