Skip to content

Commit

Permalink
Merge pull request #2780 from resilient-tech/version-15-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit authored Nov 26, 2024
2 parents 367db37 + 2d3860a commit 5a5ee56
Show file tree
Hide file tree
Showing 26 changed files with 272 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:

- name: Upload coverage data
if: github.event.repository.name == 'india-compliance' || env.CODECOV_TOKEN != ''
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ env.CODECOV_TOKEN }}
with:
Expand Down
11 changes: 9 additions & 2 deletions india_compliance/audit_trail/overrides/test_customize_form.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re

import frappe
from frappe.custom.doctype.customize_form.test_customize_form import TestCustomizeForm
from frappe.tests.utils import FrappeTestCase


class TestCustomizeFormAuditTrail(TestCustomizeForm):
class TestCustomizeFormAuditTrail(FrappeTestCase):
def test_validate_customize_form(self):
customize_frm = self.get_customize_form()
customize_frm.doc_type = "Purchase Invoice"
Expand All @@ -19,3 +19,10 @@ def test_validate_customize_form(self):
customize_frm.save_customization,
)
frappe.db.set_single_value("Accounts Settings", "enable_audit_trail", 0)

def get_customize_form(self, doctype=None):
d = frappe.get_doc("Customize Form")
if doctype:
d.doc_type = doctype
d.run_method("fetch_to_customize")
return d
3 changes: 2 additions & 1 deletion india_compliance/gst_india/api_classes/taxpayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ def reset_auth_token(self):
{"auth_token": None},
)

frappe.db.commit() # nosemgrep - executed in after enqueue
if not frappe.flags.in_test:
frappe.db.commit() # nosemgrep - executed in after enqueue


class TaxpayerBaseAPI(TaxpayerAuthenticate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@ class StockEntryEwaybill extends EwaybillApplicability {
let message_list = [];
const is_return = this.frm.doc.is_return;

if (is_return && !this.frm.doc.bill_from_gstin) {
if (is_return && !this.frm.doc.bill_to_gstin) {
is_ewb_applicable = false;
message_list.push(
"Bill From GSTIN is not set. Ensure its set in Bill From Address."
"Bill To GSTIN is not set. Ensure its set in Bill To Address."
);
}

if (!is_return && !this.frm.doc.bill_to_gstin) {
if (!is_return && !this.frm.doc.bill_from_gstin) {
is_ewb_applicable = false;
message_list.push(
"Bill To GSTIN is not set. Ensure its set in Bill To Address."
"Bill From GSTIN is not set. Ensure its set in Bill From Address."
);
}

Expand Down
13 changes: 8 additions & 5 deletions india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ frappe.ui.form.on(DOCTYPE, {
on_change_set_address(
frm,
"supplier_address",
...get_field_and_label(frm, "party_field"),
__("Bill To")
...get_field_and_label(frm, "party_field")
);
},

Expand Down Expand Up @@ -88,8 +87,7 @@ frappe.ui.form.on(DOCTYPE, {
on_change_set_address(
frm,
"supplier_address",
...get_field_and_label(frm, "party_field"),
__("Bill To")
...get_field_and_label(frm, "party_field")
);
},

Expand Down Expand Up @@ -217,12 +215,17 @@ function get_field_and_label(frm, field) {
party_field: [
"bill_from_address",
__("Bill From (same as Supplier Address)"),
__("Bill From"),
],
company_field: ["bill_to_address", __("Bill To")],
};
} else {
field_label_dict = {
party_field: ["bill_to_address", __("Bill To (same as Supplier Address)")],
party_field: [
"bill_to_address",
__("Bill To (same as Supplier Address)"),
__("Bill To"),
],
company_field: ["bill_from_address", __("Bill From")],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ frappe.ui.form.on("GSTR 3B Report", {
let current_year = new Date().getFullYear();
let options = [current_year, current_year - 1, current_year - 2];
frm.set_df_property("year", "options", options);
frm.set_value("year", options[0]);

frappe.realtime.on("gstr3b_report_generation", function () {
frm.reload_doc();
Expand All @@ -60,7 +61,8 @@ frappe.ui.form.on("GSTR 3B Report", {
);

if (!frm.doc.company) return;
await india_compliance.set_gstin_options(frm);
const options = await india_compliance.set_gstin_options(frm);
frm.set_value("company_gstin", options[0]);
},

company: async function (frm) {
Expand All @@ -75,6 +77,8 @@ frappe.ui.form.on("GSTR 3B Report", {
});

function append_form(frm) {
if (frm.is_new()) return;

$(frm.fields_dict.gstr3b_form.wrapper).empty();
$(
frappe.render_template("gstr_3b_report", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "format:GSTR3B-{month}-{year}-{company_address}",
"autoname": "format:GSTR3B-{month_or_quarter}-{year}-{company_gstin}",
"creation": "2019-02-04 11:35:55.964639",
"doctype": "DocType",
"editable_grid": 1,
Expand Down Expand Up @@ -95,7 +95,7 @@
}
],
"links": [],
"modified": "2024-09-09 08:37:11.799168",
"modified": "2024-11-22 18:36:30.385643",
"modified_by": "Administrator",
"module": "GST India",
"name": "GSTR 3B Report",
Expand Down
5 changes: 4 additions & 1 deletion india_compliance/gst_india/overrides/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
validate_hsn_codes as _validate_hsn_codes,
)
from india_compliance.gst_india.overrides.transaction import validate_transaction
from india_compliance.gst_india.utils import is_api_enabled
from india_compliance.gst_india.utils import is_api_enabled, validate_invoice_number
from india_compliance.gst_india.utils.e_waybill import get_e_waybill_info


Expand Down Expand Up @@ -46,6 +46,9 @@ def validate(doc, method=None):
if validate_transaction(doc) is False:
return

if doc.is_reverse_charge and not doc.supplier_gstin:
validate_invoice_number(doc)

validate_hsn_codes(doc)
set_ineligibility_reason(doc)
update_itc_totals(doc)
Expand Down
32 changes: 27 additions & 5 deletions india_compliance/gst_india/overrides/subcontracting_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def onload(doc, method=None):


def validate(doc, method=None):
if ignore_gst_validations(doc):
if ignore_gst_validations_for_subcontracting(doc):
return

if not is_e_waybill_applicable(doc):
Expand Down Expand Up @@ -244,11 +244,18 @@ def validate_doc_references(doc):

def validate_transaction(doc, method=None):
if doc.doctype == "Stock Entry":
company_gstin_field = "bill_from_gstin"
party_gstin_field = "bill_to_gstin"
company_address_field = "bill_from_address"
gst_category_field = "bill_to_gst_category"
if not doc.is_return:
company_address_field = "bill_from_address"
company_gstin_field = "bill_from_gstin"
party_gstin_field = "bill_to_gstin"
gst_category_field = "bill_to_gst_category"
else:
company_address_field = "bill_to_address"
company_gstin_field = "bill_to_gstin"
party_gstin_field = "bill_from_gstin"
gst_category_field = "bill_from_gst_category"
else:
# Subcontracting Receipt and Subcontracting Order
company_gstin_field = "company_gstin"
party_gstin_field = "supplier_gstin"
company_address_field = "billing_address"
Expand Down Expand Up @@ -489,3 +496,18 @@ def is_e_waybill_applicable(doc):
return False

return True


def ignore_gst_validations_for_subcontracting(doc):
if ignore_gst_validations(doc):
return True

if doc.doctype != "Stock Entry":
return False

# ignore if company address is not set
if is_outward_stock_entry(doc) and not doc.bill_from_address:
return True

if doc.is_return and not doc.bill_to_address:
return True
26 changes: 26 additions & 0 deletions india_compliance/gst_india/overrides/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,29 @@ def test_itc_classification(self):
"Reverse Charge is not applicable on Import of Goods",
pinv.save,
)

def test_validate_invoice_length(self):
# No error for registered supplier
pinv = create_purchase_invoice(
supplier="_Test Registered Supplier",
is_reverse_charge=True,
do_not_save=True,
)
setattr(pinv, "__newname", "INV/2022/00001/asdfsadf") # NOQA
pinv.meta.autoname = "prompt"
pinv.save()

# Error for unregistered supplier
pinv = create_purchase_invoice(
supplier="_Test Unregistered Supplier",
is_reverse_charge=True,
do_not_save=True,
)
setattr(pinv, "__newname", "INV/2022/00001/asdfsadg") # NOQA
pinv.meta.autoname = "prompt"

self.assertRaisesRegex(
frappe.exceptions.ValidationError,
"Transaction Name must be 16 characters or fewer to meet GST requirements",
pinv.save,
)
25 changes: 19 additions & 6 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ def validate_for_invalid_account_type(self):
if self.is_sales_transaction:
company_address_field = "company_address"
elif self.doc.doctype == "Stock Entry":
company_address_field = "bill_from_address"
company_address_field = (
"bill_to_address" if self.doc.is_return else "bill_from_address"
)
else:
company_address_field = "billing_address"

Expand Down Expand Up @@ -673,11 +675,15 @@ def validate_place_of_supply(doc):


def is_inter_state_supply(doc):
gst_category = (
doc.bill_to_gst_category if doc.doctype == "Stock Entry" else doc.gst_category
)
if doc.doctype == "Stock Entry":
party_gst_category = (
doc.bill_from_gst_category if doc.is_return else doc.bill_to_gst_category
)

return gst_category == "SEZ" or (
else:
party_gst_category = doc.gst_category

return party_gst_category == "SEZ" or (
doc.place_of_supply[:2] != get_source_state_code(doc)
)

Expand All @@ -692,7 +698,14 @@ def get_source_state_code(doc):
return doc.company_gstin[:2]

if doc.doctype == "Stock Entry":
return doc.bill_from_gstin[:2]
if doc.bill_from_gst_category == "Unregistered" and doc.bill_from_address:
return frappe.db.get_value(
"Address",
doc.bill_from_address,
"gst_state_number",
)

return (doc.bill_from_gstin or doc.bill_to_gstin)[:2]

if doc.gst_category == "Overseas":
return "96"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,14 @@

class TestSalesRegisterBeta(FrappeTestCase):
@classmethod
@change_settings("GST Settings", {"enable_overseas_transactions": 1})
def setUpClass(cls):
super().setUpClass()
TestSalesRegisterBeta().create_sales_invoices()

def create_sales_invoices(self):
cls.create_test_records()

@classmethod
@change_settings("GST Settings", {"enable_overseas_transactions": 1})
def create_test_records(cls):
for invoice in INVOICES:
create_sales_invoice(**invoice)

Expand Down
2 changes: 2 additions & 0 deletions india_compliance/gst_india/report/gstr_1/gstr_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ def get_query_for_purchase_invoice(self):

additional_conditions = [
self.purchase_invoice.is_reverse_charge == 1,
IfNull(self.purchase_invoice.supplier_gstin, "") == "",
]
return self.build_query(
doctype=self.purchase_invoice,
Expand Down Expand Up @@ -2086,6 +2087,7 @@ def get_document_issued_summary_json(data):
"Invoices for outward supply": 1,
"Debit Note": 4,
"Credit Note": 5,
"Invoices for inward supply from unregistered person": 2,
}

document_lists = {document_type: [] for document_type in document_types}
Expand Down
36 changes: 35 additions & 1 deletion india_compliance/gst_india/report/gstr_1/test_gstr_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
format_data_to_dict,
get_json,
)
from india_compliance.gst_india.utils.tests import create_sales_invoice
from india_compliance.gst_india.utils.tests import (
create_purchase_invoice,
create_sales_invoice,
)

JSON_OUTPUT = {
"doc_det": [
Expand All @@ -27,6 +30,11 @@
"doc_typ": "Credit Note",
"docs": [],
},
{
"doc_num": 2,
"doc_typ": "Invoices for inward supply from unregistered person",
"docs": [],
},
]
}

Expand Down Expand Up @@ -80,6 +88,7 @@ def create_test_items():
invoices_for_outward_supply = JSON_OUTPUT["doc_det"][0]["docs"]
debit_notes = JSON_OUTPUT["doc_det"][1]["docs"]
credit_notes = JSON_OUTPUT["doc_det"][2]["docs"]
purchase_rcm = JSON_OUTPUT["doc_det"][3]["docs"]

# Sales Invoices
sales_invoices = create_sales_invoices(3)
Expand Down Expand Up @@ -160,12 +169,37 @@ def create_test_items():
}
)

# Purchase Invoices (RCM)

# Registered RCM
create_purchase_invoices(5)

# Unregistered RCM
purchases = create_purchase_invoices(5, supplier="_Test Unregistered Supplier")
purchase_rcm.append(
{
"num": 1,
"to": purchases[-1].name,
"from": purchases[0].name,
"totnum": 5,
"cancel": 0,
"net_issue": 5,
}
)


def create_sales_invoices(count, **kwargs):
"""Create a list of sales invoices."""
return [create_sales_invoice(**kwargs) for _ in range(count)]


def create_purchase_invoices(count, **kwargs):
"""Create a list of purchase invoices."""
return [
create_purchase_invoice(**kwargs, is_reverse_charge=True) for _ in range(count)
]


def create_opening_entry():
sales_invoice = frappe.new_doc("Sales Invoice")
sales_invoice.update(
Expand Down
Loading

0 comments on commit 5a5ee56

Please sign in to comment.