blob: 385d33946f50e439605050f5b966a8eb4261ed0a [file] [log] [blame]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5
6import frappe, os, json
Rushabh Mehtaf0569742017-09-13 12:52:30 +05307from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05308from frappe.permissions import add_permission
9from erpnext.regional.india import states
10
Rushabh Mehta01659272017-06-27 18:05:17 +053011def setup(company=None, patch=True):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012 make_custom_fields()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053013 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053014 add_custom_roles_for_reports()
Nabin Haitc3144852017-09-28 18:55:40 +053015 frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
Nabin Hait852cb642017-07-05 12:58:19 +053016 add_print_formats()
Rushabh Mehta01659272017-06-27 18:05:17 +053017 if not patch:
Nabin Hait1a609312017-07-13 12:16:04 +053018 update_address_template()
Rushabh Mehta01659272017-06-27 18:05:17 +053019 make_fixtures()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053020
21def update_address_template():
22 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
23 html = f.read()
24
25 address_template = frappe.db.get_value('Address Template', 'India')
26 if address_template:
27 frappe.db.set_value('Address Template', 'India', 'template', html)
28 else:
29 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053030 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053031 doctype='Address Template',
32 country='India',
33 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053034 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053035
Nabin Hait1a609312017-07-13 12:16:04 +053036def add_hsn_sac_codes():
37 # HSN codes
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053038 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
39 hsn_codes = json.loads(f.read())
40
Nabin Hait1a609312017-07-13 12:16:04 +053041 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053042
Nabin Hait1a609312017-07-13 12:16:04 +053043 # SAC Codes
44 with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
45 sac_codes = json.loads(f.read())
46 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053047
Nabin Hait1a609312017-07-13 12:16:04 +053048def create_hsn_codes(data, code_field):
49 for d in data:
Rushabh Mehtaf702d722017-09-27 15:31:30 +053050 hsn_code = frappe.new_doc('GST HSN Code')
51 hsn_code.description = d["description"]
52 hsn_code.hsn_code = d[code_field]
53 hsn_code.name = d[code_field]
54 try:
Nabin Hait1a609312017-07-13 12:16:04 +053055 hsn_code.db_insert()
Rushabh Mehtaf702d722017-09-27 15:31:30 +053056 except frappe.DuplicateEntryError:
57 pass
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053058
Rushabh Mehta919a74a2017-06-22 16:37:04 +053059def add_custom_roles_for_reports():
60 for report_name in ('GST Sales Register', 'GST Purchase Register',
61 'GST Itemised Sales Register', 'GST Itemised Purchase Register'):
62
Rushabh Mehta919a74a2017-06-22 16:37:04 +053063 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
64 frappe.get_doc(dict(
65 doctype='Custom Role',
66 report=report_name,
67 roles= [
68 dict(role='Accounts User'),
69 dict(role='Accounts Manager')
70 ]
71 )).insert()
72
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053073def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053074 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053075 add_permission(doctype, 'All', 0)
76
Nabin Hait852cb642017-07-05 12:58:19 +053077def add_print_formats():
78 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +053079 frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
80
81 frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
82 name in('GST POS Invoice', 'GST Tax Invoice') """)
Nabin Hait852cb642017-07-05 12:58:19 +053083
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053084def make_custom_fields():
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053085 hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
Nabin Haite5716e32017-09-11 19:21:37 +053086 fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description',
87 allow_on_submit=1, print_hide=1)
Nabin Hait879e1622017-08-21 08:28:55 +053088 invoice_gst_fields = [
89 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
90 insert_after='select_print_heading', print_hide=1, collapsible=1),
91 dict(fieldname='invoice_copy', label='Invoice Copy',
92 fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
93 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
94 dict(fieldname='reverse_charge', label='Reverse Charge',
95 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
96 options='Y\nN', default='N'),
97 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='reverse_charge'),
98 dict(fieldname='invoice_type', label='Invoice Type',
99 fieldtype='Select', insert_after='reverse_charge', print_hide=1,
100 options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
101 dict(fieldname='export_type', label='Export Type',
102 fieldtype='Select', insert_after='invoice_type', print_hide=1,
103 depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
104 options='\nWith Payment of Tax\nWithout Payment of Tax'),
105 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530106 fieldtype='Data', insert_after='export_type', print_hide=1),
107 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
108 fieldtype='Select', insert_after='ecommerce_gstin', print_hide=1,
109 depends_on='eval:doc.is_return==1',
vishdha98e33c32018-01-29 13:57:34 +0530110 options='\n01-Sales Return\n02-Post Sale Discount\n03-Deficiency in services\n04-Correction in Invoice\n05-Change in POS\n06-Finalization of Provisional assessment\n07-Others')
Nabin Hait879e1622017-08-21 08:28:55 +0530111 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530112
Nabin Hait879e1622017-08-21 08:28:55 +0530113 purchase_invoice_gst_fields = [
114 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
115 fieldtype='Data', insert_after='supplier_address',
116 options='supplier_address.gstin', print_hide=1),
117 dict(fieldname='company_gstin', label='Company GSTIN',
118 fieldtype='Data', insert_after='shipping_address',
vishdha98e33c32018-01-29 13:57:34 +0530119 options='shipping_address.gstin', print_hide=1),
120 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
121 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
122 options='input\ninput service\ncapital goods\nineligible', default="ineligible"),
123 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
124 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
125 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
126 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
127 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
128 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
129 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
130 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530131 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530132
Nabin Hait879e1622017-08-21 08:28:55 +0530133 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530134 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
135 fieldtype='Data', insert_after='customer_address',
136 options='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530137 dict(fieldname='customer_gstin', label='Customer GSTIN',
138 fieldtype='Data', insert_after='shipping_address',
139 options='shipping_address_name.gstin', print_hide=1),
140 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530141 fieldtype='Data', insert_after='customer_gstin',
142 print_hide=1, read_only=0),
Nabin Hait879e1622017-08-21 08:28:55 +0530143 dict(fieldname='company_gstin', label='Company GSTIN',
144 fieldtype='Data', insert_after='company_address',
vishdha98e33c32018-01-29 13:57:34 +0530145 options='company_address.gstin', print_hide=1),
146 dict(fieldname='port_code', label='Port Code',
147 fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
148 depends_on="eval:doc.invoice_type=='Export' "),
149 dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
150 fieldtype='Data', insert_after='port_code', print_hide=1,
151 depends_on="eval:doc.invoice_type=='Export' "),
152 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
153 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
154 depends_on="eval:doc.invoice_type=='Export' ")
Nabin Hait879e1622017-08-21 08:28:55 +0530155 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530156
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530157 custom_fields = {
158 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530159 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
160 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530161 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530162 options='\n'.join(states), insert_after='gstin'),
163 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait1b363362017-07-07 14:05:33 +0530164 fieldtype='Int', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530165 ],
Nabin Hait879e1622017-08-21 08:28:55 +0530166 'Purchase Invoice': purchase_invoice_gst_fields + invoice_gst_fields,
167 'Sales Invoice': sales_invoice_gst_fields + invoice_gst_fields,
168 "Delivery Note": sales_invoice_gst_fields,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530169 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530170 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530171 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
172 ],
Nabin Hait9c421612017-07-20 13:32:01 +0530173 'Quotation Item': [hsn_sac_field],
174 'Supplier Quotation Item': [hsn_sac_field],
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530175 'Sales Order Item': [hsn_sac_field],
176 'Delivery Note Item': [hsn_sac_field],
177 'Sales Invoice Item': [hsn_sac_field],
178 'Purchase Order Item': [hsn_sac_field],
179 'Purchase Receipt Item': [hsn_sac_field],
180 'Purchase Invoice Item': [hsn_sac_field]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530181 }
182
Rushabh Mehtaf0569742017-09-13 12:52:30 +0530183 create_custom_fields(custom_fields)
Nabin Hait9c421612017-07-20 13:32:01 +0530184
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530185def make_fixtures():
186 docs = [
187 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
188 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
189 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
190 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
191 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
192 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
193 ]
194
195 for d in docs:
196 try:
197 doc = frappe.get_doc(d)
198 doc.flags.ignore_permissions = True
199 doc.insert()
200 except frappe.NameError:
201 pass