diff --git a/india_compliance/gst_india/report/gstr_1/gstr_1.py b/india_compliance/gst_india/report/gstr_1/gstr_1.py index 666273a45b..9b5d5e5cbb 100644 --- a/india_compliance/gst_india/report/gstr_1/gstr_1.py +++ b/india_compliance/gst_india/report/gstr_1/gstr_1.py @@ -11,7 +11,7 @@ from frappe.query_builder.functions import Date, IfNull, Sum from frappe.utils import cint, flt, formatdate, getdate -from india_compliance.gst_india.constants.__init__ import GST_TAX_TYPES +from india_compliance.gst_india.constants import GST_TAX_TYPES from india_compliance.gst_india.report.hsn_wise_summary_of_outward_supplies.hsn_wise_summary_of_outward_supplies import ( get_columns as get_hsn_columns, ) @@ -26,12 +26,10 @@ get_escaped_name, get_gst_accounts_by_type, get_gstin_list, + validate_invoice_number, ) -from india_compliance.gst_india.utils.__init__ import validate_invoice_number from india_compliance.gst_india.utils.exporter import ExcelExporter -from india_compliance.gst_india.utils.gstr_1 import SUPECOM - -B2C_LIMIT = 2_50_000 +from india_compliance.gst_india.utils.gstr_1 import SUPECOM, get_b2c_limit TYPES_OF_BUSINESS = { "B2B": "b2b", @@ -260,7 +258,8 @@ def is_b2cl_cdn(self, invoice): grand_total = invoice.return_against_invoice_total or abs( invoice.base_grand_total ) - return grand_total > B2C_LIMIT + + return grand_total > get_b2c_limit(invoice.posting_date) def get_row_data_for_invoice(self, invoice_details, tax_rate, item_detail): """ @@ -379,20 +378,36 @@ def get_conditions(self): ) if self.filters.get("type_of_business") == "B2C Large": - conditions += """ AND ifnull(SUBSTR(place_of_supply, 1, 2),'') != ifnull(SUBSTR(company_gstin, 1, 2),'') - AND grand_total > {0} AND is_return != 1 AND is_debit_note !=1 + # get_b2c_limit hardcoded + conditions += """ + AND ifnull(SUBSTR(place_of_supply, 1, 2),'') != ifnull(SUBSTR(company_gstin, 1, 2),'') + AND grand_total > ( + CASE + WHEN posting_date <= '2024-07-31' THEN 250000 + ELSE 100000 + END + ) + AND is_return != 1 + AND is_debit_note !=1 AND IFNULL(gst_category, "") in ('Unregistered', 'Overseas') - AND SUBSTR(place_of_supply, 1, 2) != '96'""".format( - B2C_LIMIT - ) + AND SUBSTR(place_of_supply, 1, 2) != '96' + """ elif self.filters.get("type_of_business") == "B2C Small": - conditions += """ AND ( - SUBSTR(place_of_supply, 1, 2) = SUBSTR(company_gstin, 1, 2) - OR grand_total <= {0}) AND IFNULL(gst_category, "") in ('Unregistered', 'Overseas') - AND SUBSTR(place_of_supply, 1, 2) != '96' """.format( - B2C_LIMIT - ) + # get_b2c_limit hardcoded + conditions += """ + AND ( + SUBSTR(place_of_supply, 1, 2) = SUBSTR(company_gstin, 1, 2) + OR grand_total <= ( + CASE + WHEN posting_date <= '2024-07-31' THEN 250000 + ELSE 100000 + END + ) + ) + AND IFNULL(gst_category, "") in ('Unregistered', 'Overseas') + AND SUBSTR(place_of_supply, 1, 2) != '96' + """ elif self.filters.get("type_of_business") == "CDNR-REG": conditions += """ AND (is_return = 1 OR is_debit_note = 1) AND IFNULL(gst_category, '') not in ('Unregistered', 'Overseas')""" diff --git a/india_compliance/gst_india/utils/gstr_1/__init__.py b/india_compliance/gst_india/utils/gstr_1/__init__.py index c4fd2e4924..d0070ba4b4 100644 --- a/india_compliance/gst_india/utils/gstr_1/__init__.py +++ b/india_compliance/gst_india/utils/gstr_1/__init__.py @@ -1,5 +1,7 @@ from enum import Enum +from frappe.utils import getdate + class GSTR1_Category(Enum): """ @@ -333,3 +335,20 @@ class GSTR1_B2B_InvoiceType(Enum): GSTR1_SubCategory.B2B_REVERSE_CHARGE.value, *SUBCATEGORIES_NOT_CONSIDERED_IN_TOTAL_TAXABLE_VALUE, ] + + +B2C_LIMIT = [ + ("2024-07-31", 2_50_000), + ("2099-03-31", 1_00_000), +] + + +def get_b2c_limit(date): + if isinstance(date, str): + date = getdate(date) + + for limit_date, limit in B2C_LIMIT: + if date <= getdate(limit_date): + return limit + + return B2C_LIMIT[-1][1] diff --git a/india_compliance/gst_india/utils/gstr_1/gstr_1_data.py b/india_compliance/gst_india/utils/gstr_1/gstr_1_data.py index a421e52342..60166b28ef 100644 --- a/india_compliance/gst_india/utils/gstr_1/gstr_1_data.py +++ b/india_compliance/gst_india/utils/gstr_1/gstr_1_data.py @@ -14,10 +14,9 @@ GSTR1_B2B_InvoiceType, GSTR1_Category, GSTR1_SubCategory, + get_b2c_limit, ) -B2C_LIMIT = 2_50_000 - CATEGORY_CONDITIONS = { GSTR1_Category.B2B.value: { "category": "is_b2b_invoice", @@ -234,11 +233,15 @@ def is_b2cl_cn_dn(self, invoice): else invoice.invoice_total ) - return (abs(invoice_total) > B2C_LIMIT) and self.is_inter_state(invoice) + return ( + abs(invoice_total) > get_b2c_limit(invoice.posting_date) + ) and self.is_inter_state(invoice) @cache_invoice_condition def is_b2cl_inv(self, invoice): - return abs(invoice.invoice_total) > B2C_LIMIT and self.is_inter_state(invoice) + return abs(invoice.invoice_total) > get_b2c_limit( + invoice.posting_date + ) and self.is_inter_state(invoice) class GSTR1CategoryConditions(GSTR1Conditions):