blob: 40b98ed19aae5e28ad398662e9a5a9e4407ce707 [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
Nabin Hait49b41e42019-01-24 17:55:44 +05308from frappe.permissions import add_permission, update_permission_property
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05309from erpnext.regional.india import states
Zarrar7f8024c2018-08-01 17:45:05 +053010from erpnext.accounts.utils import get_fiscal_year
11from frappe.utils import today
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012
Rushabh Mehta01659272017-06-27 18:05:17 +053013def setup(company=None, patch=True):
Prateeksha Singhdabf3492018-11-13 15:56:15 +053014 setup_company_independent_fixtures()
Prateeksha Singh39b87652018-11-12 17:19:56 +053015 if not patch:
16 update_address_template()
Prateeksha Singhdabf3492018-11-13 15:56:15 +053017 make_fixtures(company)
Prateeksha Singh39b87652018-11-12 17:19:56 +053018
19# TODO: for all countries
20def setup_company_independent_fixtures():
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053021 make_custom_fields()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053022 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053023 add_custom_roles_for_reports()
Nabin Haitc3144852017-09-28 18:55:40 +053024 frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
Nabin Hait852cb642017-07-05 12:58:19 +053025 add_print_formats()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053026
27def update_address_template():
28 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
29 html = f.read()
30
31 address_template = frappe.db.get_value('Address Template', 'India')
32 if address_template:
33 frappe.db.set_value('Address Template', 'India', 'template', html)
34 else:
35 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053036 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053037 doctype='Address Template',
38 country='India',
39 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053040 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053041
Nabin Hait1a609312017-07-13 12:16:04 +053042def add_hsn_sac_codes():
43 # HSN codes
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053044 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
45 hsn_codes = json.loads(f.read())
46
Nabin Hait1a609312017-07-13 12:16:04 +053047 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053048
Nabin Hait1a609312017-07-13 12:16:04 +053049 # SAC Codes
50 with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
51 sac_codes = json.loads(f.read())
52 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053053
Nabin Hait1a609312017-07-13 12:16:04 +053054def create_hsn_codes(data, code_field):
55 for d in data:
Rushabh Mehtaf702d722017-09-27 15:31:30 +053056 hsn_code = frappe.new_doc('GST HSN Code')
57 hsn_code.description = d["description"]
58 hsn_code.hsn_code = d[code_field]
59 hsn_code.name = d[code_field]
60 try:
Nabin Hait1a609312017-07-13 12:16:04 +053061 hsn_code.db_insert()
Rushabh Mehtaf702d722017-09-27 15:31:30 +053062 except frappe.DuplicateEntryError:
63 pass
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053064
Rushabh Mehta919a74a2017-06-22 16:37:04 +053065def add_custom_roles_for_reports():
66 for report_name in ('GST Sales Register', 'GST Purchase Register',
rohitwaghchaure8cca61f2018-08-20 17:53:56 +053067 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'):
Rushabh Mehta919a74a2017-06-22 16:37:04 +053068
Rushabh Mehta919a74a2017-06-22 16:37:04 +053069 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
70 frappe.get_doc(dict(
71 doctype='Custom Role',
72 report=report_name,
73 roles= [
74 dict(role='Accounts User'),
75 dict(role='Accounts Manager')
76 ]
77 )).insert()
78
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053079def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053080 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053081 add_permission(doctype, 'All', 0)
Nabin Hait49b41e42019-01-24 17:55:44 +053082 add_permission(doctype, 'Accounts Manager', 0)
83 update_permission_property(doctype, 'Accounts Manager', 0, 'write', 1)
84 update_permission_property(doctype, 'Accounts Manager', 0, 'create', 1)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053085
Nabin Hait852cb642017-07-05 12:58:19 +053086def add_print_formats():
87 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +053088 frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
89
90 frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
91 name in('GST POS Invoice', 'GST Tax Invoice') """)
Nabin Hait852cb642017-07-05 12:58:19 +053092
Rushabh Mehta69fa8082018-07-17 18:22:51 +053093def make_custom_fields(update=True):
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053094 hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
Nabin Haitd34bfa82018-11-13 18:19:58 +053095 fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description',
Nabin Haitf4af6082019-04-01 11:51:54 +053096 allow_on_submit=1, print_hide=1, fetch_if_empty=1)
Deepesh Garg22b61602019-03-21 20:47:47 +053097 nil_rated_exempt = dict(fieldname='is_nil_exempt', label='Is nil rated or exempted',
98 fieldtype='Check', fetch_from='item_code.is_nil_exempt', insert_after='gst_hsn_code',
99 print_hide=1)
100 is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST',
101 fieldtype='Check', fetch_from='item_code.is_non_gst', insert_after='is_nil_exempt',
102 print_hide=1)
103
104 purchase_invoice_gst_category = [
Nabin Hait879e1622017-08-21 08:28:55 +0530105 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
vishdha109b4082018-01-30 12:11:13 +0530106 insert_after='language', print_hide=1, collapsible=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530107 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530108 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530109 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530110 fetch_from='supplier.gst_category', fetch_if_empty=1)
Deepesh Garg22b61602019-03-21 20:47:47 +0530111 ]
112
113 sales_invoice_gst_category = [
114 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
115 insert_after='language', print_hide=1, collapsible=1),
116 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530117 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530118 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530119 fetch_from='customer.gst_category', fetch_if_empty=1)
Deepesh Garg22b61602019-03-21 20:47:47 +0530120 ]
121
122 invoice_gst_fields = [
Nabin Hait879e1622017-08-21 08:28:55 +0530123 dict(fieldname='invoice_copy', label='Invoice Copy',
Deepesh Garg22b61602019-03-21 20:47:47 +0530124 fieldtype='Select', insert_after='gst_category', print_hide=1, allow_on_submit=1,
Nabin Hait879e1622017-08-21 08:28:55 +0530125 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
126 dict(fieldname='reverse_charge', label='Reverse Charge',
127 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
128 options='Y\nN', default='N'),
Nabin Hait879e1622017-08-21 08:28:55 +0530129 dict(fieldname='export_type', label='Export Type',
Deepesh Garg22b61602019-03-21 20:47:47 +0530130 fieldtype='Select', insert_after='reverse_charge', print_hide=1,
131 depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
Nabin Hait879e1622017-08-21 08:28:55 +0530132 options='\nWith Payment of Tax\nWithout Payment of Tax'),
133 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530134 fieldtype='Data', insert_after='export_type', print_hide=1),
Nabin Haite6d65bc2018-02-14 17:44:06 +0530135 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530136 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
Nabin Haitb02c1092018-02-05 16:09:51 +0530137 fieldtype='Select', insert_after='gst_col_break', print_hide=1,
Nabin Haite6d65bc2018-02-14 17:44:06 +0530138 depends_on='eval:doc.is_return==1',
Nabin Haita8d10b72018-02-12 16:54:13 +0530139 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 +0530140 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530141
Nabin Hait879e1622017-08-21 08:28:55 +0530142 purchase_invoice_gst_fields = [
143 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
144 fieldtype='Data', insert_after='supplier_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530145 fetch_from='supplier_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530146 dict(fieldname='company_gstin', label='Company GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530147 fieldtype='Data', insert_after='shipping_address_display',
148 fetch_from='shipping_address.gstin', print_hide=1),
Nabin Haitb02c1092018-02-05 16:09:51 +0530149 dict(fieldname='place_of_supply', label='Place of Supply',
150 fieldtype='Data', insert_after='shipping_address',
151 print_hide=1, read_only=0),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530152 ]
153
154 purchase_invoice_itc_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530155 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
156 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530157 options='Input Service Distributor\nImport Of Service\nImport Of Capital Goods\nIneligible\nAll Other ITC', default="All Other ITC"),
vishdha98e33c32018-01-29 13:57:34 +0530158 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
159 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
160 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
161 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
162 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
163 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
164 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
165 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530166 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530167
Nabin Hait879e1622017-08-21 08:28:55 +0530168 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530169 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
170 fieldtype='Data', insert_after='customer_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530171 fetch_from='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530172 dict(fieldname='customer_gstin', label='Customer GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530173 fieldtype='Data', insert_after='shipping_address_name',
174 fetch_from='shipping_address_name.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530175 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530176 fieldtype='Data', insert_after='customer_gstin',
177 print_hide=1, read_only=0),
Nabin Hait879e1622017-08-21 08:28:55 +0530178 dict(fieldname='company_gstin', label='Company GSTIN',
179 fieldtype='Data', insert_after='company_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530180 fetch_from='company_address.gstin', print_hide=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530181 ]
182
183 sales_invoice_shipping_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530184 dict(fieldname='port_code', label='Port Code',
185 fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530186 depends_on="eval:doc.gst_category=='Overseas' "),
vishdha98e33c32018-01-29 13:57:34 +0530187 dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
188 fieldtype='Data', insert_after='port_code', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530189 depends_on="eval:doc.gst_category=='Overseas' "),
vishdha98e33c32018-01-29 13:57:34 +0530190 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
191 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530192 depends_on="eval:doc.gst_category=='Overseas' "),
Nabin Hait879e1622017-08-21 08:28:55 +0530193 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530194
Shreya Shah4fa600a2018-06-05 11:27:53 +0530195 inter_state_gst_field = [
196 dict(fieldname='is_inter_state', label='Is Inter State',
197 fieldtype='Check', insert_after='disabled', print_hide=1)
198 ]
199
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530200 ewaybill_fields = [
201 {
202 'fieldname': 'distance',
203 'label': 'Distance (in km)',
204 'fieldtype': 'Float',
205 'insert_after': 'vehicle_no',
206 'print_hide': 1
207 },
208 {
209 'fieldname': 'gst_transporter_id',
210 'label': 'GST Transporter ID',
211 'fieldtype': 'Data',
Nabin Hait34c551d2019-07-03 10:34:31 +0530212 'insert_after': 'transporter',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530213 'fetch_from': 'transporter.gst_transporter_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530214 'print_hide': 1,
215 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530216 },
217 {
218 'fieldname': 'mode_of_transport',
219 'label': 'Mode of Transport',
220 'fieldtype': 'Select',
221 'options': '\nRoad\nAir\nRail\nShip',
222 'default': 'Road',
Nabin Hait34c551d2019-07-03 10:34:31 +0530223 'insert_after': 'transporter_name',
224 'print_hide': 1,
225 'translatable': 0
226 },
227 {
228 'fieldname': 'gst_vehicle_type',
229 'label': 'GST Vehicle Type',
230 'fieldtype': 'Select',
231 'options': 'Regular\nOver Dimensional Cargo (ODC)',
232 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
233 'default': 'Regular',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530234 'insert_after': 'lr_date',
Nabin Hait34c551d2019-07-03 10:34:31 +0530235 'print_hide': 1,
236 'translatable': 0
237 }
238 ]
239
240 si_ewaybill_fields = [
241 {
242 'fieldname': 'transporter_info',
243 'label': 'Transporter Info',
244 'fieldtype': 'Section Break',
245 'insert_after': 'terms',
246 'collapsible': 1,
247 'collapsible_depends_on': 'transporter',
248 'print_hide': 1
249 },
250 {
251 'fieldname': 'transporter',
252 'label': 'Transporter',
253 'fieldtype': 'Link',
254 'insert_after': 'transporter_info',
255 'options': 'Supplier',
256 'print_hide': 1
257 },
258 {
259 'fieldname': 'gst_transporter_id',
260 'label': 'GST Transporter ID',
261 'fieldtype': 'Data',
262 'insert_after': 'transporter',
263 'fetch_from': 'transporter.gst_transporter_id',
264 'print_hide': 1,
265 'translatable': 0
266 },
267 {
268 'fieldname': 'driver',
269 'label': 'Driver',
270 'fieldtype': 'Link',
271 'insert_after': 'gst_transporter_id',
272 'options': 'Driver',
273 'print_hide': 1
274 },
275 {
276 'fieldname': 'lr_no',
277 'label': 'Transport Receipt No',
278 'fieldtype': 'Data',
279 'insert_after': 'driver',
280 'print_hide': 1,
281 'translatable': 0
282 },
283 {
284 'fieldname': 'vehicle_no',
285 'label': 'Vehicle No',
286 'fieldtype': 'Data',
287 'insert_after': 'lr_no',
288 'print_hide': 1,
289 'translatable': 0
290 },
291 {
292 'fieldname': 'distance',
293 'label': 'Distance (in km)',
294 'fieldtype': 'Float',
295 'insert_after': 'vehicle_no',
296 'print_hide': 1
297 },
298 {
299 'fieldname': 'transporter_col_break',
300 'fieldtype': 'Column Break',
301 'insert_after': 'distance'
302 },
303 {
304 'fieldname': 'transporter_name',
305 'label': 'Transporter Name',
306 'fieldtype': 'Data',
307 'insert_after': 'transporter_col_break',
308 'fetch_from': 'transporter.name',
309 'read_only': 1,
310 'print_hide': 1,
311 'translatable': 0
312 },
313 {
314 'fieldname': 'mode_of_transport',
315 'label': 'Mode of Transport',
316 'fieldtype': 'Select',
317 'options': '\nRoad\nAir\nRail\nShip',
318 'default': 'Road',
319 'insert_after': 'transporter_name',
320 'print_hide': 1,
321 'translatable': 0
322 },
323 {
324 'fieldname': 'driver_name',
325 'label': 'Driver Name',
326 'fieldtype': 'Data',
327 'insert_after': 'mode_of_transport',
328 'fetch_from': 'driver.full_name',
329 'print_hide': 1,
330 'translatable': 0
331 },
332 {
333 'fieldname': 'lr_date',
334 'label': 'Transport Receipt Date',
335 'fieldtype': 'Date',
336 'insert_after': 'driver_name',
337 'default': 'Today',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530338 'print_hide': 1
339 },
340 {
341 'fieldname': 'gst_vehicle_type',
342 'label': 'GST Vehicle Type',
343 'fieldtype': 'Select',
Nabin Hait34c551d2019-07-03 10:34:31 +0530344 'options': 'Regular\nOver Dimensional Cargo (ODC)',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530345 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
Nabin Hait34c551d2019-07-03 10:34:31 +0530346 'default': 'Regular',
347 'insert_after': 'lr_date',
348 'print_hide': 1,
349 'translatable': 0
350 },
351 {
352 'fieldname': 'ewaybill',
353 'label': 'e-Way Bill No.',
354 'fieldtype': 'Data',
355 'depends_on': 'eval:(doc.docstatus === 1)',
356 'allow_on_submit': 1,
deepeshgarg007a85db662019-07-14 18:15:19 +0530357 'insert_after': 'tax_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530358 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530359 }
360 ]
361
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530362 custom_fields = {
363 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530364 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
365 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530366 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530367 options='\n'.join(states), insert_after='gstin'),
368 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait562d9422018-09-07 16:14:44 +0530369 fieldtype='Data', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530370 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530371 'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530372 'Purchase Order': purchase_invoice_gst_fields,
373 'Purchase Receipt': purchase_invoice_gst_fields,
Nabin Hait34c551d2019-07-03 10:34:31 +0530374 'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields,
375 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530376 'Sales Order': sales_invoice_gst_fields,
Shreya Shah4fa600a2018-06-05 11:27:53 +0530377 'Sales Taxes and Charges Template': inter_state_gst_field,
378 'Purchase Taxes and Charges Template': inter_state_gst_field,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530379 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530380 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530381 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
Deepesh Garg22b61602019-03-21 20:47:47 +0530382 dict(fieldname='is_nil_exempt', label='Is nil rated or exempted',
383 fieldtype='Check', insert_after='gst_hsn_code'),
384 dict(fieldname='is_non_gst', label='Is Non GST ',
385 fieldtype='Check', insert_after='is_nil_exempt')
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530386 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530387 'Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
388 'Supplier Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
389 'Sales Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
390 'Delivery Note Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
391 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
392 'Purchase Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
393 'Purchase Receipt Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
394 'Purchase Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Himanshu Warekar656d8e42019-04-01 19:38:43 +0530395 'Material Request Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Pawan Mehtaf4196352018-04-05 14:54:51 +0530396 'Employee': [
397 dict(fieldname='ifsc_code', label='IFSC Code',
Rushabh Mehta369afce2018-04-26 10:10:03 +0530398 fieldtype='Data', insert_after='bank_ac_no', print_hide=1,
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530399 depends_on='eval:doc.salary_mode == "Bank"')
400 ],
401 'Company': [
402 dict(fieldname='hra_section', label='HRA Settings',
Anurag Mishraa5527222019-06-14 15:25:57 +0530403 fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530404 dict(fieldname='basic_component', label='Basic Component',
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530405 fieldtype='Link', options='Salary Component', insert_after='hra_section'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530406 dict(fieldname='hra_component', label='HRA Component',
407 fieldtype='Link', options='Salary Component', insert_after='basic_component'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530408 dict(fieldname='arrear_component', label='Arrear Component',
Mangesh-Khairnar9215de02019-05-06 16:24:10 +0530409 fieldtype='Link', options='Salary Component', insert_after='hra_component'),
410 dict(fieldname='bank_remittance_section', label='Bank Remittance Settings',
411 fieldtype='Section Break', collapsible=1, insert_after='arrear_component'),
412 dict(fieldname='client_code', label='Client Code', fieldtype='Data',
413 insert_after='bank_remittance_section'),
414 dict(fieldname='remittance_column_break', fieldtype='Column Break',
415 insert_after='client_code'),
416 dict(fieldname='product_code', label='Product Code', fieldtype='Data',
417 insert_after='remittance_column_break'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530418 ],
419 'Employee Tax Exemption Declaration':[
420 dict(fieldname='hra_section', label='HRA Exemption',
421 fieldtype='Section Break', insert_after='declarations'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530422 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530423 fieldtype='Currency', insert_after='hra_section'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530424 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530425 fieldtype='Check', insert_after='monthly_house_rent', depends_on='monthly_house_rent'),
426 dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure',
427 fieldtype='Currency', insert_after='rented_in_metro_city', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530428 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530429 insert_after='salary_structure_hra', depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530430 dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530431 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530432 dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530433 fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1, depends_on='monthly_house_rent')
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530434 ],
435 'Employee Tax Exemption Proof Submission': [
436 dict(fieldname='hra_section', label='HRA Exemption',
437 fieldtype='Section Break', insert_after='tax_exemption_proofs'),
438 dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount',
439 fieldtype='Currency', insert_after='hra_section'),
440 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530441 fieldtype='Check', insert_after='house_rent_payment_amount', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530442 dict(fieldname='rented_from_date', label='Rented From Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530443 fieldtype='Date', insert_after='rented_in_metro_city', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530444 dict(fieldname='rented_to_date', label='Rented To Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530445 fieldtype='Date', insert_after='rented_from_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530446 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530447 insert_after='rented_to_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530448 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530449 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530450 dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530451 fieldtype='Currency', insert_after='monthly_house_rent', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530452 dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530453 fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1, depends_on='house_rent_payment_amount')
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530454 ],
455 'Supplier': [
456 {
457 'fieldname': 'gst_transporter_id',
458 'label': 'GST Transporter ID',
459 'fieldtype': 'Data',
460 'insert_after': 'supplier_type',
461 'depends_on': 'eval:doc.is_transporter'
Deepesh Garg22b61602019-03-21 20:47:47 +0530462 },
463 {
464 'fieldname': 'gst_category',
465 'label': 'GST Category',
466 'fieldtype': 'Select',
467 'insert_after': 'gst_transporter_id',
468 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders',
469 'default': 'Unregistered'
470 }
471 ],
472 'Customer': [
473 {
474 'fieldname': 'gst_category',
475 'label': 'GST Category',
476 'fieldtype': 'Select',
477 'insert_after': 'customer_type',
478 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
479 'default': 'Unregistered'
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530480 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530481 ]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530482 }
Deepesh Garg22b61602019-03-21 20:47:47 +0530483 create_custom_fields(custom_fields, update=update)
Nabin Hait9c421612017-07-20 13:32:01 +0530484
Saurabh2d8a7ee2018-05-11 13:16:16 +0530485def make_fixtures(company=None):
486 docs = []
487 company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
488
489 set_salary_components(docs)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530490 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530491
492 for d in docs:
493 try:
494 doc = frappe.get_doc(d)
495 doc.flags.ignore_permissions = True
496 doc.insert()
497 except frappe.NameError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530498 frappe.clear_messages()
Zarrar7f8024c2018-08-01 17:45:05 +0530499 except frappe.DuplicateEntryError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530500 frappe.clear_messages()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530501
Zarrar7f8024c2018-08-01 17:45:05 +0530502 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530503 set_tax_withholding_category(company)
504
Saurabh2d8a7ee2018-05-11 13:16:16 +0530505def set_salary_components(docs):
506 docs.extend([
507 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
508 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
509 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
510 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
511 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
512 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
513 ])
514
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530515def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +0530516 accounts = []
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530517 abbr = frappe.get_value("Company", company, "abbr")
518 tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
Saurabh2d8a7ee2018-05-11 13:16:16 +0530519
520 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530521 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +0530522
Nabin Haitafef9c12019-02-12 11:28:20 +0530523 fiscal_year = get_fiscal_year(today(), company=company)[0]
Zarrar7f8024c2018-08-01 17:45:05 +0530524 docs = get_tds_details(accounts, fiscal_year)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530525
Zarrar7f8024c2018-08-01 17:45:05 +0530526 for d in docs:
527 try:
528 doc = frappe.get_doc(d)
529 doc.flags.ignore_permissions = True
Nabin Haitafef9c12019-02-12 11:28:20 +0530530 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +0530531 doc.insert()
532 except frappe.DuplicateEntryError:
533 doc = frappe.get_doc("Tax Withholding Category", d.get("name"))
Zarrar963d62b2019-03-23 10:30:12 +0530534
535 if accounts:
536 doc.append("accounts", accounts[0])
Zarrar7f8024c2018-08-01 17:45:05 +0530537
538 # if fiscal year don't match with any of the already entered data, append rate row
539 fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
540 if not fy_exist:
541 doc.append("rates", d.get('rates')[0])
542
543 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530544
545def set_tds_account(docs, company):
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530546 abbr = frappe.get_value("Company", company, "abbr")
Nabin Haitf77cd542018-11-20 16:46:25 +0530547 parent_account = frappe.db.get_value("Account", filters = {"account_name": "Duties and Taxes", "company": company})
548 if parent_account:
549 docs.extend([
550 {
551 "doctype": "Account",
552 "account_name": "TDS Payable",
553 "account_type": "Tax",
554 "parent_account": parent_account,
555 "company": company
556 }
557 ])
Zarrar7f8024c2018-08-01 17:45:05 +0530558
559def get_tds_details(accounts, fiscal_year):
560 # bootstrap default tax withholding sections
561 return [
562 dict(name="TDS - 194C - Company",
563 category_name="Payment to Contractors (Single / Aggregate)",
564 doctype="Tax Withholding Category", accounts=accounts,
565 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
566 "single_threshold": 30000, "cumulative_threshold": 100000}]),
567 dict(name="TDS - 194C - Individual",
568 category_name="Payment to Contractors (Single / Aggregate)",
569 doctype="Tax Withholding Category", accounts=accounts,
570 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
571 "single_threshold": 30000, "cumulative_threshold": 100000}]),
572 dict(name="TDS - 194C - No PAN / Invalid PAN",
573 category_name="Payment to Contractors (Single / Aggregate)",
574 doctype="Tax Withholding Category", accounts=accounts,
575 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
576 "single_threshold": 30000, "cumulative_threshold": 100000}]),
577 dict(name="TDS - 194D - Company",
578 category_name="Insurance Commission",
579 doctype="Tax Withholding Category", accounts=accounts,
580 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
581 "single_threshold": 15000, "cumulative_threshold": 0}]),
582 dict(name="TDS - 194D - Company Assessee",
583 category_name="Insurance Commission",
584 doctype="Tax Withholding Category", accounts=accounts,
585 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
586 "single_threshold": 15000, "cumulative_threshold": 0}]),
587 dict(name="TDS - 194D - Individual",
588 category_name="Insurance Commission",
589 doctype="Tax Withholding Category", accounts=accounts,
590 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
591 "single_threshold": 15000, "cumulative_threshold": 0}]),
592 dict(name="TDS - 194D - No PAN / Invalid PAN",
593 category_name="Insurance Commission",
594 doctype="Tax Withholding Category", accounts=accounts,
595 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
596 "single_threshold": 15000, "cumulative_threshold": 0}]),
597 dict(name="TDS - 194DA - Company",
598 category_name="Non-exempt payments made under a life insurance policy",
599 doctype="Tax Withholding Category", accounts=accounts,
600 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
601 "single_threshold": 100000, "cumulative_threshold": 0}]),
602 dict(name="TDS - 194DA - Individual",
603 category_name="Non-exempt payments made under a life insurance policy",
604 doctype="Tax Withholding Category", accounts=accounts,
605 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
606 "single_threshold": 100000, "cumulative_threshold": 0}]),
607 dict(name="TDS - 194DA - No PAN / Invalid PAN",
608 category_name="Non-exempt payments made under a life insurance policy",
609 doctype="Tax Withholding Category", accounts=accounts,
610 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
611 "single_threshold": 100000, "cumulative_threshold": 0}]),
612 dict(name="TDS - 194H - Company",
613 category_name="Commission / Brokerage",
614 doctype="Tax Withholding Category", accounts=accounts,
615 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
616 "single_threshold": 15000, "cumulative_threshold": 0}]),
617 dict(name="TDS - 194H - Individual",
618 category_name="Commission / Brokerage",
619 doctype="Tax Withholding Category", accounts=accounts,
620 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
621 "single_threshold": 15000, "cumulative_threshold": 0}]),
622 dict(name="TDS - 194H - No PAN / Invalid PAN",
623 category_name="Commission / Brokerage",
624 doctype="Tax Withholding Category", accounts=accounts,
625 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
626 "single_threshold": 15000, "cumulative_threshold": 0}]),
627 dict(name="TDS - 194I - Rent - Company",
628 category_name="Rent",
629 doctype="Tax Withholding Category", accounts=accounts,
630 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
631 "single_threshold": 180000, "cumulative_threshold": 0}]),
632 dict(name="TDS - 194I - Rent - Individual",
633 category_name="Rent",
634 doctype="Tax Withholding Category", accounts=accounts,
635 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
636 "single_threshold": 180000, "cumulative_threshold": 0}]),
637 dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
638 category_name="Rent",
639 doctype="Tax Withholding Category", accounts=accounts,
640 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
641 "single_threshold": 180000, "cumulative_threshold": 0}]),
642 dict(name="TDS - 194I - Rent/Machinery - Company",
643 category_name="Rent-Plant / Machinery",
644 doctype="Tax Withholding Category", accounts=accounts,
645 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
646 "single_threshold": 180000, "cumulative_threshold": 0}]),
647 dict(name="TDS - 194I - Rent/Machinery - Individual",
648 category_name="Rent-Plant / Machinery",
649 doctype="Tax Withholding Category", accounts=accounts,
650 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
651 "single_threshold": 180000, "cumulative_threshold": 0}]),
652 dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
653 category_name="Rent-Plant / Machinery",
654 doctype="Tax Withholding Category", accounts=accounts,
655 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
656 "single_threshold": 180000, "cumulative_threshold": 0}]),
657 dict(name="TDS - 194J - Professional Fees - Company",
658 category_name="Professional Fees",
659 doctype="Tax Withholding Category", accounts=accounts,
660 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
661 "single_threshold": 30000, "cumulative_threshold": 0}]),
662 dict(name="TDS - 194J - Professional Fees - Individual",
663 category_name="Professional Fees",
664 doctype="Tax Withholding Category", accounts=accounts,
665 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
666 "single_threshold": 30000, "cumulative_threshold": 0}]),
667 dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
668 category_name="Professional Fees",
669 doctype="Tax Withholding Category", accounts=accounts,
670 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
671 "single_threshold": 30000, "cumulative_threshold": 0}]),
672 dict(name="TDS - 194J - Director Fees - Company",
673 category_name="Director Fees",
674 doctype="Tax Withholding Category", accounts=accounts,
675 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
676 "single_threshold": 0, "cumulative_threshold": 0}]),
677 dict(name="TDS - 194J - Director Fees - Individual",
678 category_name="Director Fees",
679 doctype="Tax Withholding Category", accounts=accounts,
680 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
681 "single_threshold": 0, "cumulative_threshold": 0}]),
682 dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
683 category_name="Director Fees",
684 doctype="Tax Withholding Category", accounts=accounts,
685 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
686 "single_threshold": 0, "cumulative_threshold": 0}]),
687 dict(name="TDS - 194 - Dividends - Company",
688 category_name="Dividends",
689 doctype="Tax Withholding Category", accounts=accounts,
690 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
691 "single_threshold": 2500, "cumulative_threshold": 0}]),
692 dict(name="TDS - 194 - Dividends - Individual",
693 category_name="Dividends",
694 doctype="Tax Withholding Category", accounts=accounts,
695 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
696 "single_threshold": 2500, "cumulative_threshold": 0}]),
697 dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
698 category_name="Dividends",
699 doctype="Tax Withholding Category", accounts=accounts,
700 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
701 "single_threshold": 2500, "cumulative_threshold": 0}])
Mangesh-Khairnar9215de02019-05-06 16:24:10 +0530702 ]