Skip to content

Commit

Permalink
test: test-cases for regional_overrides (resilient-tech#2006)
Browse files Browse the repository at this point in the history
* fix: test-cases for regional_overrides

* refactor: test case placement and only required test cases

---------

Co-authored-by: Smit Vora <[email protected]>
(cherry picked from commit 35c48a2)

# Conflicts:
#	india_compliance/gst_india/overrides/test_advance_payment_entry.py
  • Loading branch information
Sanket322 authored and mergify[bot] committed Apr 11, 2024
1 parent b380005 commit bbdd4ef
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 2 deletions.
58 changes: 58 additions & 0 deletions india_compliance/gst_india/overrides/test_advance_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
101 changes: 99 additions & 2 deletions india_compliance/gst_india/overrides/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit bbdd4ef

Please sign in to comment.