Skip to content

Commit

Permalink
Merge pull request #2012 from resilient-tech/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
vorasmit authored Apr 11, 2024
2 parents a3830b9 + b316e5f commit e2983f7
Show file tree
Hide file tree
Showing 25 changed files with 1,302 additions and 140 deletions.
29 changes: 18 additions & 11 deletions india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def _make_request(
raise e

finally:
log.output = response_json.copy()
if response_json:
log.output = response_json.copy()

self.mask_sensitive_info(log)

enqueue_integration_request(**log)
Expand Down Expand Up @@ -252,21 +254,26 @@ def generate_request_id(self, length=12):
return frappe.generate_hash(length=length)

def mask_sensitive_info(self, log):
request_headers = log.request_headers
output = log.output
data = log.data
request_body = data and data.get("body")

for key in self.SENSITIVE_INFO:
if key in log.request_headers:
log.request_headers[key] = "*****"
if key in request_headers:
request_headers[key] = "*****"

if key in log.output:
log.output[key] = "*****"
if output and key in output:
output[key] = "*****"

if not log.data:
return
if not data:
continue

if key in log.get("data", {}):
log.data[key] = "*****"
if key in data:
data[key] = "*****"

if key in log.get("data", {}).get("body", {}):
log.data["body"][key] = "*****"
if request_body and key in request_body:
request_body[key] = "*****"


def get_public_ip():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function is_e_invoice_applicable(frm, show_message = false) {
) {
is_einv_applicable = false;
message_list.push(
"At least one item must be taxable or transaction is categorized as export."
"All items are either Nil-Rated/Exempted/Non-GST. At least one item must be taxable or the transaction should be categorised as export."
);
}

Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/client_scripts/expense_claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ frappe.ui.form.on("Expense Taxes and Charges", {
});

function toggle_gstin_for_expense_claim(frm) {
toggle_company_gstin(frm, taxes_table="taxes", account_field="account_head");
toggle_company_gstin(frm, "taxes", "account_head");
}
2 changes: 1 addition & 1 deletion india_compliance/gst_india/client_scripts/journal_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ frappe.ui.form.on("Journal Entry Account", {
});

function toggle_gstin_for_journal_entry(frm) {
toggle_company_gstin(frm, taxes_table="accounts", account_head="account");
toggle_company_gstin(frm, "accounts", "account");
}

async function toggle_company_gstin(frm, taxes_table, account_head) {
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"Lakshadweep Islands": (682, 682),
"Kerala": (670, 695),
"Tamil Nadu": (600, 643),
"Puducherry": ((533, 533), (605, 605), (607, 607), (609, 609)),
"Puducherry": ((533, 533), (605, 605), (607, 607), (609, 609), (673, 673)),
"Andaman and Nicobar Islands": (744, 744),
"Andhra Pradesh": (500, 535),
}
Expand Down
58 changes: 35 additions & 23 deletions india_compliance/gst_india/doctype/bill_of_entry/bill_of_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ def validate_purchase_invoice(self):
def validate_taxes(self):
input_accounts = get_gst_accounts_by_type(self.company, "Input", throw=True)
taxable_value_map = {}
item_qty_map = {}

for row in self.get("items"):
taxable_value_map[row.name] = row.taxable_value
item_qty_map[row.name] = row.qty

for tax in self.taxes:
if not tax.tax_amount:
Expand All @@ -278,33 +280,43 @@ def validate_taxes(self):
[input_accounts.cess_non_advol_account], tax
)

if tax.charge_type == "Actual":
if tax.charge_type != "Actual":
continue

item_wise_tax_rates = json.loads(tax.item_wise_tax_rates)
if not item_wise_tax_rates:
frappe.throw(
_(
"Tax Row #{0}: Charge Type is set to Actual. However, this would"
" not compute item taxes, and your further reporting will be affected."
).format(tax.idx),
title=_("Invalid Charge Type"),
)
item_wise_tax_rates = json.loads(tax.item_wise_tax_rates)
if not item_wise_tax_rates:
frappe.throw(
_(
"Tax Row #{0}: Charge Type is set to Actual. However, this would"
" not compute item taxes, and your further reporting will be affected."
).format(tax.idx),
title=_("Invalid Charge Type"),
)

# validating total tax
total_tax = 0
is_non_cess_advol = (
tax.account_head == input_accounts.cess_non_advol_account
)

# validating total tax
total_tax = 0
for item, rate in item_wise_tax_rates.items():
item_taxable_value = taxable_value_map.get(item, 0)
total_tax += item_taxable_value * rate / 100
for item, rate in item_wise_tax_rates.items():
multiplier = (
item_qty_map.get(item, 0)
if is_non_cess_advol
else taxable_value_map.get(item, 0) / 100
)
total_tax += multiplier * rate

tax_difference = abs(total_tax - tax.tax_amount)
tax_difference = abs(total_tax - tax.tax_amount)

if tax_difference > 1:
frappe.throw(
_(
"Tax Row #{0}: Charge Type is set to Actual. However, Tax Amount {1}"
" is incorrect. Try setting the Charge Type to On Net Total."
).format(row.idx, tax.tax_amount)
)
if tax_difference > 1:
column = "On Item Quantity" if is_non_cess_advol else "On Net Total"
frappe.throw(
_(
"Tax Row #{0}: Charge Type is set to Actual. However, Tax Amount {1}"
" is incorrect. Try setting the Charge Type to {2}."
).format(row.idx, tax.tax_amount, column)
)

def get_gl_entries(self):
# company_currency is required by get_gl_dict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_create_bill_of_entry(self):
pi = create_purchase_invoice(supplier="_Test Foreign Supplier", update_stock=1)

# Create BOE

boe = make_bill_of_entry(pi.name)
boe.items[0].customs_duty = 100
boe.bill_of_entry_no = "123"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class TestPurchaseReconciliationTool(FrappeTestCase):
def setUpClass(cls):
super().setUpClass()

# create 2023-2024 fiscal year
fiscal_year = frappe.new_doc("Fiscal Year")
fiscal_year.update(
{
"year_start_date": "2023-04-01",
"year_end_date": "2024-03-31",
"year": "2023-2024",
}
).insert(ignore_if_duplicate=True)

cls.test_data = frappe.get_file_json(
frappe.get_app_path(
"india_compliance",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#EC864B",
"creation": "2023-07-25 18:33:55.452360",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -12,7 +13,7 @@
"is_standard": 1,
"label": "Active e-Invoice, Cancelled Invoice",
"method": "",
"modified": "2024-02-23 11:37:11.634469",
"modified": "2024-04-09 11:46:37.126752",
"modified_by": "Administrator",
"module": "GST India",
"name": "Invoice Cancelled But Not e-Invoice",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#ECAD4B",
"color": "#EC864B",
"creation": "2023-07-25 15:10:39.976867",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -14,7 +14,7 @@
"is_standard": 1,
"label": "Pending e-Invoices",
"method": "",
"modified": "2024-02-23 11:37:43.073988",
"modified": "2024-04-09 11:45:32.550901",
"modified_by": "Administrator",
"module": "GST India",
"name": "Pending e-Invoices",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aggregate_function_based_on": "",
"color": "#e02f2f",
"color": "#EC864B",
"creation": "2023-08-04 11:30:55.485885",
"docstatus": 0,
"doctype": "Number Card",
Expand All @@ -12,7 +12,7 @@
"is_public": 1,
"is_standard": 1,
"label": "Pending e-Waybills",
"modified": "2023-10-12 17:16:39.286029",
"modified": "2024-04-09 11:46:27.074636",
"modified_by": "Administrator",
"module": "GST India",
"name": "Pending e-Waybill",
Expand Down
54 changes: 54 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 @@ -7,9 +7,15 @@
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,
)
from erpnext.controllers.accounts_controller import (
get_advance_payment_entries_for_regional,
)
from erpnext.controllers.stock_controller import show_accounting_ledger_preview

from india_compliance.gst_india.utils.tests import create_transaction
Expand Down Expand Up @@ -453,6 +459,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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
{"item_code": "Test Service Item", "qty": 3, "rate": 500},
{"item_code": "Test Ineligible Service Item", "qty": 2, "rate": 499},
{"item_code": "_Test Trading Goods 1", "qty": 1, "rate": 100},
]
# Item Total
# 20 * 5 + 19 * 3 + 1000 * 1 + 999 * 1 + 500 * 3 + 499 * 2 + 100 * 1 (Default) = 4754
Expand Down
Loading

0 comments on commit e2983f7

Please sign in to comment.