From 206313d69bfc591afd59ee56b656717543bfd1c1 Mon Sep 17 00:00:00 2001 From: GangaManoj Date: Mon, 7 Jun 2021 06:11:57 +0530 Subject: [PATCH] fix(Purchase Invoice): Add test for exchange rate difference handling --- .../purchase_invoice/test_purchase_invoice.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 2f5d36c8fa..7f350e7ed5 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -230,6 +230,23 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertEqual(expected_values[gle.account][1], gle.debit) self.assertEqual(expected_values[gle.account][2], gle.credit) + def test_purchase_invoice_with_exchange_rate_difference(self): + set_gst_settings() + pr = make_purchase_receipt(currency = "USD", conversion_rate = 70) + pi = make_purchase_invoice(currency = "USD", conversion_rate = 80, do_not_save = "True") + + for item in pi.items: + item.purchase_receipt = pr.name + + pi.insert() + pi.submit() + + # fetching the latest GL Entry with 'Exchange Gain/Loss - _TC' account + gl_entries = frappe.get_all('GL Entry', filters = {'account': 'Exchange Gain/Loss - _TC'}) + voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no') + + self.assertEqual(pi.name, voucher_no) + def test_purchase_invoice_change_naming_series(self): pi = frappe.copy_doc(test_records[1]) pi.insert() @@ -1050,6 +1067,24 @@ def update_tax_witholding_category(company, account, date): 'account': account }) tds_category.save() +def set_gst_settings(): + gst_settings = frappe.get_doc("GST Settings") + + gst_account = frappe.get_all( + "GST Account", + fields=["cgst_account", "sgst_account", "igst_account"], + filters = {"company": "_Test Company"} + ) + + if not gst_account: + gst_settings.append("gst_accounts", { + "company": "_Test Company", + "cgst_account": "CGST - _TC", + "sgst_account": "SGST - _TC", + "igst_account": "IGST - _TC", + }) + + gst_settings.save() def unlink_payment_on_cancel_of_invoice(enable=1): accounts_settings = frappe.get_doc("Accounts Settings")