Skip to content

Commit

Permalink
Merge branch 'resilient-tech:develop' into itc_04_filing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninad1306 authored Jun 24, 2024
2 parents fddcc72 + f3133e3 commit eb3dc17
Show file tree
Hide file tree
Showing 37 changed files with 518 additions and 573 deletions.
3 changes: 2 additions & 1 deletion india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import frappe
from frappe import _
from frappe.utils import sbool
from frappe.utils.scheduler import is_scheduler_disabled

from india_compliance.exceptions import GatewayTimeoutError, GSPServerError
from india_compliance.gst_india.utils import is_api_enabled
Expand Down Expand Up @@ -290,7 +291,7 @@ def check_scheduler_status():
if frappe.flags.in_test or frappe.conf.developer_mode:
return

if frappe.utils.scheduler.is_scheduler_disabled():
if is_scheduler_disabled():
frappe.throw(
_(
"The Scheduler is currently disabled, which needs to be enabled to use e-Invoicing and e-Waybill features. "
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/gst_india/client_scripts/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ frappe.ui.form.on(DOCTYPE, {
frm.set_query("autofield", "bank_details_for_printing", (_, cdt, cdn) => {
return {
query: "india_compliance.gst_india.overrides.company.get_default_print_options",
params : {for_bank : true}
params : {for_bank : 1}
}
});
frm.set_query("autofield", "registration_details_for_printing", (_, cdt, cdn) => {
return {
query: "india_compliance.gst_india.overrides.company.get_default_print_options",
params : {for_bank : false}
params : {for_bank : 0}
}
});
},
Expand Down
4 changes: 4 additions & 0 deletions india_compliance/gst_india/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

GST_TAX_TYPES = tuple(field[:-8] for field in GST_ACCOUNT_FIELDS)

GST_RCM_TAX_TYPES = tuple(tax_type + "_rcm" for tax_type in GST_TAX_TYPES)

TAX_TYPES = (*GST_TAX_TYPES, *GST_RCM_TAX_TYPES)

GST_PARTY_TYPES = ("Customer", "Supplier", "Company")

# Map for e-Invoice Supply Type
Expand Down
14 changes: 14 additions & 0 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,20 @@
"translatable": 0,
},
],
(
"Sales Taxes and Charges",
"Purchase Taxes and Charges",
"Advance Taxes and Charges",
): [
{
"fieldname": "gst_tax_type",
"label": "GST Tax Type",
"fieldtype": "Data",
"insert_after": "rate",
"read_only": 1,
"translatable": 0,
},
],
"Purchase Invoice": [
{
"fieldname": "gst_section",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.controllers.taxes_and_totals import get_round_off_applicable_accounts

from india_compliance.gst_india.constants import GST_TAX_TYPES
from india_compliance.gst_india.overrides.ineligible_itc import (
update_landed_cost_voucher_for_gst_expense,
update_regional_gl_entries,
Expand All @@ -21,6 +22,7 @@
from india_compliance.gst_india.overrides.transaction import (
ItemGSTDetails,
ItemGSTTreatment,
set_gst_tax_type,
validate_charge_type_for_cess_non_advol_accounts,
)
from india_compliance.gst_india.utils import get_gst_accounts_by_type
Expand All @@ -41,12 +43,11 @@ def set_item_wise_tax_details(self):
if (
not row.tax_amount
or not row.item_wise_tax_rates
or row.account_head not in self.gst_account_map
or row.gst_tax_type not in GST_TAX_TYPES
):
continue

account_type = self.gst_account_map[row.account_head]
tax = account_type[:-8]
tax = row.gst_tax_type
tax_rate_field = f"{tax}_rate"
tax_amount_field = f"{tax}_amount"

Expand Down Expand Up @@ -113,6 +114,7 @@ def onload(self):

def before_validate(self):
self.set_taxes_and_totals()
set_gst_tax_type(self)

def before_save(self):
update_gst_details(self)
Expand Down Expand Up @@ -287,9 +289,7 @@ def validate_taxes(self):
).format(tax.idx)
)

validate_charge_type_for_cess_non_advol_accounts(
[input_accounts.cess_non_advol_account], tax
)
validate_charge_type_for_cess_non_advol_accounts(tax)

if tax.charge_type != "Actual":
continue
Expand All @@ -306,9 +306,7 @@ def validate_taxes(self):

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

for item, rate in item_wise_tax_rates.items():
multiplier = (
Expand Down Expand Up @@ -516,6 +514,7 @@ def set_missing_values(source, target):
"charge_type": "On Net Total",
"account_head": input_igst_account,
"rate": rate,
"gst_tax_type": "igst",
"description": description,
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"account_head",
"section_break_10",
"rate",
"gst_tax_type",
"column_break_pipk",
"tax_amount",
"total",
Expand Down Expand Up @@ -89,11 +90,17 @@
"fieldtype": "Code",
"hidden": 1,
"label": "Item Wise Tax Rates"
},
{
"fieldname": "gst_tax_type",
"fieldtype": "Data",
"label": "GST Tax Type",
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2024-03-29 11:36:18.468715",
"modified": "2024-06-12 18:03:36.955731",
"modified_by": "Administrator",
"module": "GST India",
"name": "Bill of Entry Taxes",
Expand Down
2 changes: 2 additions & 0 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,8 @@ async function set_default_company_gstin(frm) {
frm.set_value("company_gstin", "");

const company = frm.doc.company;
if (!company) return;

const { message: gstin_list } = await frappe.call(
"india_compliance.gst_india.utils.get_gstin_list",
{ party: company }
Expand Down
46 changes: 27 additions & 19 deletions india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from india_compliance.gst_india.report.gstr_3b_details.gstr_3b_details import (
IneligibleITC,
)
from india_compliance.gst_india.utils import get_gst_accounts_by_type

VALUES_TO_UPDATE = ["iamt", "camt", "samt", "csamt"]

Expand Down Expand Up @@ -121,24 +120,33 @@ def get_itc_reversal_entries(self):
self.update_itc_reversal_from_bill_of_entry()

def update_itc_reversal_from_purchase_invoice(self):
self.update_itc_reversal_for_purchase_us_17_4()
self.update_itc_reversal_for_purchase_due_to_pos()

def update_itc_reversal_for_purchase_due_to_pos(self):
ineligible_credit = IneligibleITC(
self.company, self.gst_details.get("gstin"), self.month_no, self.year
).get_ineligible_itc_us_17_5_for_purchase(group_by="ineligibility_reason")
).get_for_purchase(
"ITC restricted due to PoS rules", group_by="ineligibility_reason"
)

ineligible_credit_due_to_pos = IneligibleITC(
self.company, self.gst_details.get("gstin"), self.month_no, self.year
).get_ineligible_itc_due_to_pos_for_purchase(group_by="ineligibility_reason")
self.process_ineligible_credit(ineligible_credit)

ineligible_credit.extend(ineligible_credit_due_to_pos)
def update_itc_reversal_for_purchase_us_17_4(self):
ineligible_credit = IneligibleITC(
self.company, self.gst_details.get("gstin"), self.month_no, self.year
).get_for_purchase(
"Ineligible As Per Section 17(5)", group_by="ineligibility_reason"
)

return self.process_ineligible_credit(ineligible_credit)
self.process_ineligible_credit(ineligible_credit)

def update_itc_reversal_from_bill_of_entry(self):
ineligible_credit = IneligibleITC(
self.company, self.gst_details.get("gstin"), self.month_no, self.year
).get_for_bill_of_entry()

return self.process_ineligible_credit(ineligible_credit)
self.process_ineligible_credit(ineligible_credit)

def process_ineligible_credit(self, ineligible_credit):
if not ineligible_credit:
Expand Down Expand Up @@ -230,7 +238,6 @@ def get_itc_details(self):
def update_imports_from_bill_of_entry(self, itc_details):
boe = frappe.qb.DocType("Bill of Entry")
boe_taxes = frappe.qb.DocType("Bill of Entry Taxes")
gst_accounts = get_gst_accounts_by_type(self.company, "Input")

def _get_tax_amount(account_type):
return (
Expand All @@ -245,12 +252,12 @@ def _get_tax_amount(account_type):
)
& boe.company_gstin.eq(self.gst_details.get("gstin"))
& boe.docstatus.eq(1)
& boe_taxes.account_head.eq(gst_accounts[account_type])
& boe_taxes.gst_tax_type.eq(account_type)
)
.run()
)[0][0] or 0

igst, cess = _get_tax_amount("igst_account"), _get_tax_amount("cess_account")
igst, cess = _get_tax_amount("igst"), _get_tax_amount("cess")
itc_details.setdefault("Import Of Goods", {"iamt": 0, "csamt": 0})
itc_details["Import Of Goods"]["iamt"] += igst
itc_details["Import Of Goods"]["csamt"] += cess
Expand Down Expand Up @@ -317,12 +324,13 @@ def get_invoice_item_wise_tax_details(self, doctype):
def set_item_wise_tax_details(self, docs):
self.invoice_item_wise_tax_details = {}
item_wise_details = {}
account_head_gst_map = {}

for key, values in self.account_heads.items():
for value in values:
if value is not None:
account_head_gst_map[value] = key
gst_tax_type_map = {
"cgst": "camt",
"sgst": "samt",
"igst": "iamt",
"cess": "csamt",
"cess_non_advol": "csamt",
}

item_defaults = frappe._dict(
{
Expand Down Expand Up @@ -358,7 +366,7 @@ def set_item_wise_tax_details(self, docs):

# Process tax details
for tax in details["taxes"]:
gst_tax_type = account_head_gst_map.get(tax.account_head)
gst_tax_type = gst_tax_type_map.get(tax.gst_tax_type)

if not gst_tax_type:
continue
Expand Down Expand Up @@ -452,7 +460,7 @@ def get_outward_tax_details(self, doctype):
tax_details = frappe.db.sql(
f"""
SELECT
parent, account_head, item_wise_tax_detail
parent, item_wise_tax_detail, gst_tax_type
FROM `tab{tax_template}`
WHERE
parenttype = %s and docstatus = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
from frappe.utils import add_months, format_date, getdate, rounded

from india_compliance.gst_india.constants import GST_TAX_TYPES
from india_compliance.gst_india.utils import (
get_escaped_name,
get_gst_accounts_by_type,
get_party_for_gstin,
)
from india_compliance.gst_india.utils import get_party_for_gstin
from india_compliance.gst_india.utils.gstr_2 import IMPORT_CATEGORY, ReturnType


Expand Down Expand Up @@ -454,10 +450,8 @@ def get_query(self, additional_fields=None, is_return=False):
return query

def get_fields(self, additional_fields=None, is_return=False):
gst_accounts = get_gst_accounts_by_type(self.company, "Input")
tax_fields = [
self.query_tax_amount(account).as_(tax[:-8])
for tax, account in gst_accounts.items()
self.query_tax_amount(tax_type).as_(tax_type) for tax_type in GST_TAX_TYPES
]

fields = [
Expand Down Expand Up @@ -490,13 +484,12 @@ def get_fields(self, additional_fields=None, is_return=False):

return fields

def query_tax_amount(self, account):
account = get_escaped_name(account)
def query_tax_amount(self, gst_tax_type):
return Abs(
Sum(
Case()
.when(
self.PI_TAX.account_head == account,
self.PI_TAX.gst_tax_type == gst_tax_type,
self.PI_TAX.base_tax_amount_after_discount_amount,
)
.else_(0)
Expand Down Expand Up @@ -600,10 +593,8 @@ def get_query(self, additional_fields=None):
return query

def get_fields(self, additional_fields=None):
gst_accounts = get_gst_accounts_by_type(self.company, "Input")
tax_fields = [
self.query_tax_amount(account).as_(tax[:-8])
for tax, account in gst_accounts.items()
self.query_tax_amount(tax_type).as_(tax_type) for tax_type in GST_TAX_TYPES
]

fields = [
Expand Down Expand Up @@ -638,13 +629,12 @@ def get_fields(self, additional_fields=None):

return fields

def query_tax_amount(self, account):
account = get_escaped_name(account)
def query_tax_amount(self, gst_tax_type):
return Abs(
Sum(
Case()
.when(
self.BOE_TAX.account_head == account,
self.BOE_TAX.gst_tax_type == gst_tax_type,
self.BOE_TAX.tax_amount,
)
.else_(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ const ALERT_HTML = `
</div>
${
api_enabled
? `<button
id="download-gstr2b-button"
type="button"
class="btn btn-dark btn-xs"
aria-label="Download"
style="outline: 0px solid black !important"
>
Download 2B
</button>`
? `<a id="download-gstr2b-button" href="#" class="alert-link">
Download 2B
</a>`
: ""
}
</div>
Expand Down Expand Up @@ -1465,6 +1459,7 @@ async function fetch_date_range(frm, field_prefix, method) {

function set_date_range_description(frm, field_prefixs) {
if (!field_prefixs) field_prefixs = ["inward_supply", "purchase"];
else field_prefixs = [field_prefixs];

field_prefixs.forEach(prefix => {
const period_field = prefix + "_period";
Expand Down
Loading

0 comments on commit eb3dc17

Please sign in to comment.