[wip] GST for India. Pending reports

This commit is contained in:
Rushabh Mehta
2017-06-21 17:22:38 +05:30
parent 2cb598f644
commit b3c8f44b3e
27 changed files with 51050 additions and 105 deletions

View File

@@ -0,0 +1,76 @@
states = [
'',
'Andhra Pradesh',
'Arunachal Pradesh',
'Assam',
'Bihar',
'Chandigarh',
'Chattisgarh',
'Dadra and Nagar Haveli',
'Daman and Diu',
'Delhi',
'Goa',
'Gujarat',
'Haryana',
'Himachal Pradesh',
'Jammu and Kashmir',
'Jharkhand',
'Karnataka',
'Kerala',
'Lakshadweep Islands',
'Madhya Pradesh',
'Maharashtra',
'Manipur',
'Meghalaya',
'Mizoram',
'Nagaland',
'Odisha',
'Pondicherry',
'Punjab',
'Rajasthan',
'Sikkim',
'Tamil Nadu',
'Telangana',
'Tripura',
'Uttar Pradesh',
'Uttarakhand',
'West Bengal',
]
state_numbers = {
"Andhra Pradesh": "37",
"Arunachal Pradesh": "12",
"Assam": "18",
"Bihar": "10",
"Chandigarh": "04",
"Chattisgarh": "22",
"Dadra and Nagar Haveli": "26",
"Daman and Diu": "25",
"Delhi": "07",
"Goa": "30",
"Gujarat": "24",
"Haryana": "06",
"Himachal Pradesh": "02",
"Jammu and Kashmir": "01",
"Jharkhand": "20",
"Karnataka": "29",
"Kerala": "32",
"Lakshadweep Islands": "31",
"Madhya Pradesh": "23",
"Maharashtra": "27",
"Manipur": "14",
"Meghalaya": "17",
"Mizoram": "15",
"Nagaland": "13",
"Odisha": "21",
"Pondicherry": "34",
"Punjab": "03",
"Rajasthan": "08",
"Sikkim": "11",
"Tamil Nadu": "33",
"Telangana": "36",
"Tripura": "16",
"Uttar Pradesh": "35",
"Uttarakhand": "36",
"West Bengal": "37"
}

View File

@@ -0,0 +1,177 @@
[
{
"state_number": "33",
"state_code": "TN",
"state_name": "Tamil Nadu"
},
{
"state_number": "35",
"state_code": "UP",
"state_name": "Uttar Pradesh"
},
{
"state_number": "36",
"state_code": "UT",
"state_name": "Uttarakhand"
},
{
"state_number": "37",
"state_code": "WB",
"state_name": "West Bengal"
},
{
"state_number": "16",
"state_code": "TR",
"state_name": "Tripura"
},
{
"state_number": "36",
"state_code": "TS",
"state_name": "Telangana"
},
{
"state_number": "11",
"state_code": "SK",
"state_name": "Sikkim"
},
{
"state_number": "08",
"state_code": "RJ",
"state_name": "Rajasthan"
},
{
"state_number": "03",
"state_code": "PB",
"state_name": "Punjab"
},
{
"state_number": "34",
"state_code": "PY",
"state_name": "Pondicherry"
},
{
"state_number": "21",
"state_code": "OR",
"state_name": "Odisha"
},
{
"state_number": "13",
"state_code": "NL",
"state_name": "Nagaland"
},
{
"state_number": "15",
"state_code": "MI",
"state_name": "Mizoram"
},
{
"state_number": "17",
"state_code": "ME",
"state_name": "Meghalaya"
},
{
"state_number": "14",
"state_code": "MN",
"state_name": "Manipur"
},
{
"state_number": "27",
"state_code": "MH",
"state_name": "Maharashtra"
},
{
"state_number": "23",
"state_code": "MP",
"state_name": "Madhya Pradesh"
},
{
"state_number": "31",
"state_code": "LD",
"state_name": "Lakshadweep Islands"
},
{
"state_number": "32",
"state_code": "KL",
"state_name": "Kerala"
},
{
"state_number": "29",
"state_code": "KA",
"state_name": "Karnataka"
},
{
"state_number": "20",
"state_code": "JH",
"state_name": "Jharkhand"
},
{
"state_number": "01",
"state_code": "JK",
"state_name": "Jammu and Kashmir"
},
{
"state_number": "02",
"state_code": "HP",
"state_name": "Himachal Pradesh"
},
{
"state_number": "06",
"state_code": "HR",
"state_name": "Haryana"
},
{
"state_number": "24",
"state_code": "GJ",
"state_name": "Gujarat"
},
{
"state_number": "30",
"state_code": "GA",
"state_name": "Goa"
},
{
"state_number": "07",
"state_code": "DL",
"state_name": "Delhi"
},
{
"state_number": "25",
"state_code": "DD",
"state_name": "Daman and Diu"
},
{
"state_number": "26",
"state_code": "DN",
"state_name": "Dadra and Nagar Haveli"
},
{
"state_number": "22",
"state_code": "CT",
"state_name": "Chattisgarh"
},
{
"state_number": "04",
"state_code": "CH",
"state_name": "Chandigarh"
},
{
"state_number": "10",
"state_code": "BH",
"state_name": "Bihar"
},
{
"state_number": "18",
"state_code": "AS",
"state_name": "Assam"
},
{
"state_number": "12",
"state_code": "AR",
"state_name": "Arunachal Pradesh"
},
{
"state_number": "37",
"state_code": "AD",
"state_name": "Andhra Pradesh (New)"
}
]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,89 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, os, json
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.permissions import add_permission
from erpnext.regional.india import states
def install(company):
make_custom_fields()
make_fixtures()
add_permissions()
add_hsn_codes()
def add_hsn_codes():
with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
hsn_codes = json.loads(f.read())
frappe.db.sql('truncate `tabGST HSN Code`')
for d in hsn_codes:
hsn_code = frappe.new_doc('GST HSN Code')
hsn_code.update(d)
hsn_code.name = hsn_code.hsn_code
hsn_code.db_insert()
def add_permissions():
for doctype in ('GST HSN Code',):
add_permission(doctype, 'Accounts Manager', 0)
add_permission(doctype, 'All', 0)
def make_custom_fields():
custom_fields = {
'Address': [
dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data', insert_after='fax'),
dict(fieldname='gst_state', label='GST State', fieldtype='Select',
options='\n'.join(states), insert_after='gstin')
],
'Purchase Invoice': [
dict(fieldname='supplier_gstin', label='Supplier GSTIN',
fieldtype='Data', insert_after='supplier_address', options='supplier_address.gstin'),
dict(fieldname='company_gstin', label='Company GSTIN',
fieldtype='Data', insert_after='fax', options='shipping_address.gstin'),
],
'Sales Invoice': [
dict(fieldname='customer_gstin', label='Customer GSTIN',
fieldtype='Data', insert_after='shipping_address', options='shipping_address.gstin'),
dict(fieldname='company_address', label='Company Address',
fieldtype='Link', insert_after='shipping_address', options='Address'),
dict(fieldname='company_gstin', label='Company GSTIN',
fieldtype='Data', insert_after='fax', options='company_address.gstin'),
],
'Item': [
dict(fieldname='gst_hsn_code', label='GST HSN Code',
fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
],
'Sales Invoice Item': [
dict(fieldname='gst_hsn_code', label='GST HSN Code',
fieldtype='Data', options='item_code.gst_hsn_code', insert_after='income_account'),
],
'Purchase Invoice Item': [
dict(fieldname='gst_hsn_code', label='GST HSN Code',
fieldtype='Data', options='item_code.gst_hsn_code', insert_after='expense_account'),
]
}
for doctype, fields in custom_fields.items():
for df in fields:
create_custom_field(doctype, df)
def make_fixtures():
docs = [
{'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
{'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
{'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
{'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
]
for d in docs:
try:
doc = frappe.get_doc(d)
doc.flags.ignore_permissions = True
doc.insert()
except frappe.NameError:
pass

View File

@@ -0,0 +1,21 @@
import frappe, re
from frappe import _
from erpnext.regional.india import states, state_numbers
def validate_gstin_for_india(doc, method):
if not hasattr(doc, 'gstin'):
return
if doc.gstin:
p = re.compile("[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}")
if not p.match(doc.gstin):
frappe.throw(_("Invalid GSTIN"))
if not doc.gst_state:
if doc.state in states:
doc.gst_state = doc.state
if doc.gst_state:
state_number = state_numbers[doc.gst_state]
if state_number != doc.gstin[:2]:
frappe.throw(_("First 2 digits of GSTIN should match with State number {0}").format(state_number))