From bbdd4ef5244c67c13ff1cec0582f9ea34e3938e1 Mon Sep 17 00:00:00 2001 From: Sanket322 <113279972+Sanket322@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:17:51 +0530 Subject: [PATCH] test: test-cases for regional_overrides (#2006) * fix: test-cases for regional_overrides * refactor: test case placement and only required test cases --------- Co-authored-by: Smit Vora (cherry picked from commit 35c48a293abc97f186f431ac31495e8529bfb189) # Conflicts: # india_compliance/gst_india/overrides/test_advance_payment_entry.py --- .../overrides/test_advance_payment_entry.py | 58 ++++++++++ .../gst_india/overrides/test_transaction.py | 101 +++++++++++++++++- 2 files changed, 157 insertions(+), 2 deletions(-) diff --git a/india_compliance/gst_india/overrides/test_advance_payment_entry.py b/india_compliance/gst_india/overrides/test_advance_payment_entry.py index 6335e39fbd..1556fac102 100644 --- a/india_compliance/gst_india/overrides/test_advance_payment_entry.py +++ b/india_compliance/gst_india/overrides/test_advance_payment_entry.py @@ -6,9 +6,19 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import ( get_outstanding_reference_documents, ) +from erpnext.accounts.doctype.payment_reconciliation.payment_reconciliation import ( + adjust_allocations_for_taxes, +) from erpnext.accounts.doctype.unreconcile_payment.unreconcile_payment import ( create_unreconcile_doc_for_selection, ) +<<<<<<< HEAD +======= +from erpnext.controllers.accounts_controller import ( + get_advance_payment_entries_for_regional, +) +from erpnext.controllers.stock_controller import show_accounting_ledger_preview +>>>>>>> 35c48a29 (test: test-cases for regional_overrides (#2006)) from india_compliance.gst_india.utils.tests import create_transaction @@ -359,6 +369,54 @@ def assertPLEntries(self, payment_doc, expected_pl_entries): self.assertEqual(out_str, expected_out_str) +class TestRegionalOverrides(TestAdvancePaymentEntry): + def test_get_advance_payment_entries_for_regional(self): + payment_doc = self._create_payment_entry() + invoice_doc = self._create_sales_invoice(payment_doc) + + conditions = frappe._dict({"company": invoice_doc.get("company")}) + + payment_entry = get_advance_payment_entries_for_regional( + party_type="Customer", + party=invoice_doc.customer, + party_account=[invoice_doc.debit_to], + order_list=[], + order_doctype="Sales Order", + include_unallocated=True, + condition=conditions, + ) + + payment_entry_amount = payment_entry[0].get("amount") + self.assertNotEqual(400, payment_entry_amount) + + def test_adjust_allocations_for_taxes(self): + payment_doc = self._create_payment_entry() + invoice_doc = self._create_sales_invoice() + + pr = frappe.get_doc("Payment Reconciliation") + pr.company = "_Test Indian Registered Company" + pr.party_type = "Customer" + pr.party = invoice_doc.customer + pr.receivable_payable_account = invoice_doc.debit_to + + pr.get_unreconciled_entries() + invoices = [ + row.as_dict() + for row in pr.invoices + if row.invoice_number == invoice_doc.name + ] + payments = [ + row.as_dict() + for row in pr.payments + if row.reference_name == payment_doc.name + ] + pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments})) + pr.allocation[0].allocated_amount = 50 + + adjust_allocations_for_taxes(pr) + self.assertEqual(pr.allocation[0].allocated_amount, 42.37) # 50 / 1.18 + + def make_payment_reconciliation(payment_doc, invoice_doc, amount): pr = frappe.get_doc("Payment Reconciliation") pr.company = "_Test Indian Registered Company" diff --git a/india_compliance/gst_india/overrides/test_transaction.py b/india_compliance/gst_india/overrides/test_transaction.py index c280188f9f..3e16fcc995 100644 --- a/india_compliance/gst_india/overrides/test_transaction.py +++ b/india_compliance/gst_india/overrides/test_transaction.py @@ -6,16 +6,27 @@ import frappe from frappe.tests.utils import FrappeTestCase, change_settings from frappe.utils import today +from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import ( + make_regional_gl_entries, +) from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return -from erpnext.accounts.party import _get_party_details -from erpnext.controllers.accounts_controller import update_child_qty_rate +from erpnext.accounts.party import _get_party_details, get_regional_address_details +from erpnext.controllers.accounts_controller import ( + update_child_qty_rate, + update_gl_dict_with_regional_fields, +) +from erpnext.controllers.taxes_and_totals import get_regional_round_off_accounts from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice +from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( + update_regional_gl_entries, +) from india_compliance.gst_india.constants import SALES_DOCTYPES from india_compliance.gst_india.overrides.transaction import DOCTYPES_WITH_GST_DETAIL from india_compliance.gst_india.utils.tests import ( _append_taxes, append_item, + create_purchase_invoice, create_transaction, ) @@ -908,6 +919,92 @@ def create_tax_accounts(account_name): ).insert(ignore_if_duplicate=True) +class TestRegionalOverrides(FrappeTestCase): + @change_settings( + "GST Settings", + {"round_off_gst_values": 1}, + ) + def test_get_regional_round_off_accounts(self): + + data = get_regional_round_off_accounts("_Test Indian Registered Company", []) + self.assertListEqual( + data, + [ + "Input Tax CGST - _TIRC", + "Input Tax SGST - _TIRC", + "Input Tax IGST - _TIRC", + "Output Tax CGST - _TIRC", + "Output Tax SGST - _TIRC", + "Output Tax IGST - _TIRC", + "Input Tax CGST RCM - _TIRC", + "Input Tax SGST RCM - _TIRC", + "Input Tax IGST RCM - _TIRC", + ], + ) + + @change_settings( + "GST Settings", + {"round_off_gst_values": 0}, + ) + def test_get_regional_round_off_accounts_with_round_off_unchecked(self): + + data = get_regional_round_off_accounts("_Test Indian Registered Company", []) + self.assertListEqual(data, []) + + def test_update_gl_dict_with_regional_fields(self): + + doc = frappe.get_doc( + {"doctype": "Sales Invoice", "company_gstin": "29AAHCM7727Q1ZI"} + ) + gl_entry = {} + update_gl_dict_with_regional_fields(doc, gl_entry) + + self.assertEqual(gl_entry.get("company_gstin", ""), "29AAHCM7727Q1ZI") + + def test_make_regional_gl_entries(self): + pi = create_purchase_invoice() + pi._has_ineligible_itc_items = True + + gl_entries = {"company_gstin": "29AAHCM7727Q1ZI"} + frappe.flags.through_repost_accounting_ledger = True + + make_regional_gl_entries(gl_entries, pi) + + frappe.flags.through_repost_accounting_ledger = False + self.assertEqual(pi._has_ineligible_itc_items, False) + + def test_update_regional_gl_entries(self): + gl_entry = {"company_gstin": "29AAHCM7727Q1ZI"} + doc = frappe.get_doc( + { + "doctype": "Sales Invoice", + "is_opening": "Yes", + "company_gstin": "29AAHCM7727Q1ZI", + } + ) + return_entry = update_regional_gl_entries(gl_entry, doc) + self.assertDictEqual(return_entry, gl_entry) + + def test_get_regional_address_details(self): + doctype = "Sales Order" + company = "_Test Indian Registered Company" + party_details = { + "customer": "_Test Registered Customer", + "customer_address": "_Test Registered Customer-Billing", + "billing_address_gstin": "24AANFA2641L1ZF", + "gst_category": "Registered Regular", + "company_gstin": "24AAQCA8719H1ZC", + } + + get_regional_address_details(party_details, doctype, company) + + self.assertEqual( + party_details.get("taxes_and_charges"), "Output GST In-state - _TIRC" + ) + self.assertEqual(party_details.get("place_of_supply"), "24-Gujarat") + self.assertTrue(party_details.get("taxes")) + + class TestItemUpdate(FrappeTestCase): DATA = { "customer": "_Test Unregistered Customer",