Skip to content

Commit

Permalink
feat: RCM for Sales Transaction (#2063)
Browse files Browse the repository at this point in the history
* fix: rename "Reverse Charge" to "Purchase Reverse Charge"

* fix: new gst account type "Sales Reverse Charge"

* fix: modify test casess

* fix: use both rcm accounts in item tax template validation

* refactor: validate gst accounts and rcm validation

* fix: changes as per review

* fix: test case and get_applicable_gst_accounts

* fix: patch updated to use database value

* fix: e-Invoice and e-Waybill trials for rcm

* fix: changes as per review

* fix: refactor

* fix: resolve conflicts and refactor gst account validation

* fix: correct field name

* fix: validate rcm transaction

* fix: better validation for tax rate in item tax template

---------

Co-authored-by: Smit Vora <smitvora203@gmail.com>
  • Loading branch information
ljain112 and vorasmit committed Jul 2, 2024
1 parent 795370e commit 7458c97
Show file tree
Hide file tree
Showing 21 changed files with 602 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ async function fetch_and_update_missing_gst_accounts(frm) {
}

async function get_tax_rate_for_account(frm, account) {
const gst_rate = frm.doc.gst_rate;
let gst_rate = frm.doc.gst_rate;
if (!gst_rate) return 0;

const gst_accounts = await get_gst_accounts(frm);
if (!gst_accounts) return null;

const [_, intra_state_accounts, inter_state_accounts] = gst_accounts;
const [_, intra_state_accounts, inter_state_accounts, negative_rate_accounts] =
gst_accounts;

if (negative_rate_accounts.includes(account)) gst_rate = gst_rate * -1;

if (intra_state_accounts.includes(account)) return gst_rate / 2;
else if (inter_state_accounts.includes(account)) return gst_rate;
Expand All @@ -83,7 +86,7 @@ async function get_gst_accounts(frm) {
if (!frm._company_gst_accounts?.[company]) {
frm._company_gst_accounts = frm._company_gst_accounts || {};
const { message } = await frappe.call({
method: "india_compliance.gst_india.overrides.transaction.get_valid_gst_accounts",
method: "india_compliance.gst_india.overrides.item_tax_template.get_valid_gst_accounts",
args: { company: company },
});

Expand Down
186 changes: 186 additions & 0 deletions india_compliance/gst_india/data/tax_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@
"tax_rate": 18.0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": -9.0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": -9.0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": -18.0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -118,6 +136,24 @@
"tax_rate": 5.0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": -2.5
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": -2.5
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": -5.0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -182,6 +218,24 @@
"tax_rate": 12.0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": -6.0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": -6.0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": -12.0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -246,6 +300,24 @@
"tax_rate": 28.0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": -14.0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": -14.0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": -28.0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -310,6 +382,24 @@
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -374,6 +464,24 @@
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -438,6 +546,24 @@
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax SGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax CGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Output Tax IGST RCM",
"tax_rate": 0
}
},
{
"tax_type": {
"account_name": "Input Tax SGST",
Expand Down Expand Up @@ -516,6 +642,66 @@
}
],
"tax_category": "Out-State"
},
{
"title": "Output GST RCM In-state",
"taxes": [
{
"account_head": {
"account_name": "Output Tax SGST",
"tax_rate": 9.0,
"account_type": "Tax"
},
"description": "SGST"
},
{
"account_head": {
"account_name": "Output Tax CGST",
"tax_rate": 9.0,
"account_type": "Tax"
},
"description": "CGST"
},
{
"account_head": {
"account_name": "Output Tax SGST RCM",
"tax_rate": -9.0,
"account_type": "Tax"
},
"description": "SGST RCM"
},
{
"account_head": {
"account_name": "Output Tax CGST RCM",
"tax_rate": -9.0,
"account_type": "Tax"
},
"description": "CGST RCM"
}
],
"tax_category": "Reverse Charge In-State"
},
{
"title": "Output GST RCM Out-state",
"taxes": [
{
"account_head": {
"account_name": "Output Tax IGST",
"tax_rate": 18.0,
"account_type": "Tax"
},
"description": "IGST"
},
{
"account_head": {
"account_name": "Output Tax IGST RCM",
"tax_rate": -18.0,
"account_type": "Tax"
},
"description": "IGST RCM"
}
],
"tax_category": "Reverse Charge Out-State"
}
],
"purchase_tax_templates": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
update_valuation_rate,
)
from india_compliance.gst_india.overrides.transaction import (
GSTAccounts,
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 Down Expand Up @@ -289,7 +289,7 @@ def validate_taxes(self):
).format(tax.idx)
)

validate_charge_type_for_cess_non_advol_accounts(tax)
GSTAccounts.validate_charge_type_for_cess_non_advol_accounts(tax)

if tax.charge_type != "Actual":
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Account Type",
"options": "Input\nOutput\nReverse Charge",
"options": "Input\nOutput\nPurchase Reverse Charge\nSales Reverse Charge",
"reqd": 1
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_validate_duplicate_account_type_for_each_company(self):
for row in doc.gst_accounts:
if (
row.company == "_Test Indian Registered Company"
and row.account_type == "Reverse Charge"
and row.account_type == "Purchase Reverse Charge"
):
row.account_type = "Output"
self.assertRaisesRegex(
Expand Down
30 changes: 25 additions & 5 deletions india_compliance/gst_india/overrides/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def modify_tax_defaults(default_taxes, gst_rate):
for row in tax.get("taxes"):
rate = (
gst_rate
if row["account_head"]["tax_rate"] == 18
if abs(row["account_head"]["tax_rate"]) == 18
else flt(gst_rate / 2, 3)
)

Expand All @@ -103,7 +103,16 @@ def update_gst_settings(company):
# Will only add default GST accounts if present
input_account_names = ["Input Tax CGST", "Input Tax SGST", "Input Tax IGST"]
output_account_names = ["Output Tax CGST", "Output Tax SGST", "Output Tax IGST"]
rcm_accounts = ["Input Tax CGST RCM", "Input Tax SGST RCM", "Input Tax IGST RCM"]
purchase_rcm_accounts = [
"Input Tax CGST RCM",
"Input Tax SGST RCM",
"Input Tax IGST RCM",
]
sales_rcm_accounts = [
"Output Tax CGST RCM",
"Output Tax SGST RCM",
"Output Tax IGST RCM",
]
gst_settings = frappe.get_single("GST Settings")
existing_account_list = []

Expand All @@ -118,7 +127,10 @@ def update_gst_settings(company):
"company": company,
"account_name": (
"in",
input_account_names + output_account_names + rcm_accounts,
input_account_names
+ output_account_names
+ purchase_rcm_accounts
+ sales_rcm_accounts,
),
},
["account_name", "name"],
Expand All @@ -144,11 +156,19 @@ def update_gst_settings(company):
)
add_accounts_in_gst_settings(
company,
rcm_accounts,
purchase_rcm_accounts,
gst_accounts,
existing_account_list,
gst_settings,
"Purchase Reverse Charge",
)
add_accounts_in_gst_settings(
company,
sales_rcm_accounts,
gst_accounts,
existing_account_list,
gst_settings,
"Reverse Charge",
"Sales Reverse Charge",
)

# Ignore mandatory during install, some values may not be set by post install patch
Expand Down
Loading

0 comments on commit 7458c97

Please sign in to comment.