blob: 7c25ce12f57a7d6152547c4633a50b526b7d48ce [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
Sagar Vora4c31fbb2021-04-01 15:32:37 +05308from frappe.custom.doctype.property_setter.property_setter import make_property_setter
Nabin Hait49b41e42019-01-24 17:55:44 +05309from frappe.permissions import add_permission, update_permission_property
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053010from erpnext.regional.india import states
Anuja Pawar4569e522021-01-14 19:24:30 +053011from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
Zarrar7f8024c2018-08-01 17:45:05 +053012from frappe.utils import today
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053013
Rushabh Mehta01659272017-06-27 18:05:17 +053014def setup(company=None, patch=True):
Prateeksha Singhdabf3492018-11-13 15:56:15 +053015 setup_company_independent_fixtures()
Prateeksha Singh39b87652018-11-12 17:19:56 +053016 if not patch:
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()
Sagar Vora4c31fbb2021-04-01 15:32:37 +053022 make_property_setters()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053023 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053024 add_custom_roles_for_reports()
Nabin Haitc3144852017-09-28 18:55:40 +053025 frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
Anurag Mishra25c35682020-08-18 14:13:54 +053026 create_gratuity_rule()
Nabin Hait852cb642017-07-05 12:58:19 +053027 add_print_formats()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053028
Nabin Hait1a609312017-07-13 12:16:04 +053029def add_hsn_sac_codes():
30 # HSN codes
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053031 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
32 hsn_codes = json.loads(f.read())
33
Nabin Hait1a609312017-07-13 12:16:04 +053034 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053035
Nabin Hait1a609312017-07-13 12:16:04 +053036 # SAC Codes
37 with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
38 sac_codes = json.loads(f.read())
39 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053040
Nabin Hait1a609312017-07-13 12:16:04 +053041def create_hsn_codes(data, code_field):
42 for d in data:
Rushabh Mehtaf702d722017-09-27 15:31:30 +053043 hsn_code = frappe.new_doc('GST HSN Code')
44 hsn_code.description = d["description"]
45 hsn_code.hsn_code = d[code_field]
46 hsn_code.name = d[code_field]
47 try:
Nabin Hait1a609312017-07-13 12:16:04 +053048 hsn_code.db_insert()
Rushabh Mehtaf702d722017-09-27 15:31:30 +053049 except frappe.DuplicateEntryError:
50 pass
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053051
Rushabh Mehta919a74a2017-06-22 16:37:04 +053052def add_custom_roles_for_reports():
53 for report_name in ('GST Sales Register', 'GST Purchase Register',
rohitwaghchaure8cca61f2018-08-20 17:53:56 +053054 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'):
Rushabh Mehta919a74a2017-06-22 16:37:04 +053055
Rushabh Mehta919a74a2017-06-22 16:37:04 +053056 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
57 frappe.get_doc(dict(
58 doctype='Custom Role',
59 report=report_name,
60 roles= [
61 dict(role='Accounts User'),
62 dict(role='Accounts Manager')
63 ]
64 )).insert()
65
Anurag Mishra289c8222020-06-19 19:17:57 +053066 for report_name in ('Professional Tax Deductions', 'Provident Fund Deductions'):
67
68 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
69 frappe.get_doc(dict(
70 doctype='Custom Role',
71 report=report_name,
72 roles= [
73 dict(role='HR User'),
74 dict(role='HR Manager'),
75 dict(role='Employee')
76 ]
77 )).insert()
78
Anurag Mishra54cd1942020-09-03 13:51:26 +053079 for report_name in ('HSN-wise-summary of outward supplies', 'GSTR-1', 'GSTR-2'):
80
81 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
82 frappe.get_doc(dict(
83 doctype='Custom Role',
84 report=report_name,
85 roles= [
86 dict(role='Accounts User'),
87 dict(role='Accounts Manager'),
88 dict(role='Auditor')
89 ]
90 )).insert()
91
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053092def add_permissions():
Saqib6d74f5b2020-12-25 10:26:43 +053093 for doctype in ('GST HSN Code', 'GST Settings', 'GSTR 3B Report', 'Lower Deduction Certificate', 'E Invoice Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053094 add_permission(doctype, 'All', 0)
Deepesh Garg6c8efde2020-04-04 20:05:17 +053095 for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
Saqib5e6ce882020-02-03 15:40:35 +053096 add_permission(doctype, role, 0)
97 update_permission_property(doctype, role, 0, 'write', 1)
98 update_permission_property(doctype, role, 0, 'create', 1)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053099
Deepesh Garg6c8efde2020-04-04 20:05:17 +0530100 if doctype == 'GST HSN Code':
101 for role in ('Item Manager', 'Stock Manager'):
102 add_permission(doctype, role, 0)
103 update_permission_property(doctype, role, 0, 'write', 1)
104 update_permission_property(doctype, role, 0, 'create', 1)
105
Nabin Hait852cb642017-07-05 12:58:19 +0530106def add_print_formats():
107 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +0530108 frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
Saqib6d74f5b2020-12-25 10:26:43 +0530109 frappe.reload_doc("accounts", "print_format", "GST E-Invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +0530110
barredterra1521b312021-03-03 12:33:48 +0100111 frappe.db.set_value("Print Format", "GST POS Invoice", "disabled", 0)
112 frappe.db.set_value("Print Format", "GST Tax Invoice", "disabled", 0)
113 frappe.db.set_value("Print Format", "GST E-Invoice", "disabled", 0)
Nabin Hait852cb642017-07-05 12:58:19 +0530114
Sagar Vora4c31fbb2021-04-01 15:32:37 +0530115def make_property_setters():
116 # GST rules do not allow for an invoice no. bigger than 16 characters
117 make_property_setter('Sales Invoice', 'naming_series', 'options', 'SINV-.YY.-\nSRET-.YY.-', '')
118 make_property_setter('Purchase Invoice', 'naming_series', 'options', 'PINV-.YY.-\nPRET-.YY.-', '')
119
Rushabh Mehta69fa8082018-07-17 18:22:51 +0530120def make_custom_fields(update=True):
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530121 hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
Nabin Haitd34bfa82018-11-13 18:19:58 +0530122 fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description',
Nabin Haitf4af6082019-04-01 11:51:54 +0530123 allow_on_submit=1, print_hide=1, fetch_if_empty=1)
Marica9942acd2020-04-21 13:13:39 +0530124 nil_rated_exempt = dict(fieldname='is_nil_exempt', label='Is Nil Rated or Exempted',
Deepesh Garg22b61602019-03-21 20:47:47 +0530125 fieldtype='Check', fetch_from='item_code.is_nil_exempt', insert_after='gst_hsn_code',
126 print_hide=1)
127 is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST',
128 fieldtype='Check', fetch_from='item_code.is_non_gst', insert_after='is_nil_exempt',
129 print_hide=1)
130
131 purchase_invoice_gst_category = [
Nabin Hait879e1622017-08-21 08:28:55 +0530132 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
vishdha109b4082018-01-30 12:11:13 +0530133 insert_after='language', print_hide=1, collapsible=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530134 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530135 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530136 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530137 fetch_from='supplier.gst_category', fetch_if_empty=1),
138 dict(fieldname='export_type', label='Export Type',
139 fieldtype='Select', insert_after='gst_category', print_hide=1,
140 depends_on='eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
141 options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='supplier.export_type',
142 fetch_if_empty=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530143 ]
144
145 sales_invoice_gst_category = [
146 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
147 insert_after='language', print_hide=1, collapsible=1),
148 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530149 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530150 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530151 fetch_from='customer.gst_category', fetch_if_empty=1),
152 dict(fieldname='export_type', label='Export Type',
153 fieldtype='Select', insert_after='gst_category', print_hide=1,
154 depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
155 options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='customer.export_type',
156 fetch_if_empty=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530157 ]
158
Deepesh Garg29997412021-03-29 19:49:52 +0530159 delivery_note_gst_category = [
160 dict(fieldname='gst_category', label='GST Category',
161 fieldtype='Select', insert_after='gst_vehicle_type', print_hide=1,
162 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
163 fetch_from='customer.gst_category', fetch_if_empty=1),
164 ]
165
Deepesh Garg22b61602019-03-21 20:47:47 +0530166 invoice_gst_fields = [
Nabin Hait879e1622017-08-21 08:28:55 +0530167 dict(fieldname='invoice_copy', label='Invoice Copy',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530168 fieldtype='Select', insert_after='export_type', print_hide=1, allow_on_submit=1,
Nabin Hait879e1622017-08-21 08:28:55 +0530169 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
170 dict(fieldname='reverse_charge', label='Reverse Charge',
171 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
172 options='Y\nN', default='N'),
Nabin Hait879e1622017-08-21 08:28:55 +0530173 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530174 fieldtype='Data', insert_after='export_type', print_hide=1),
Nabin Haite6d65bc2018-02-14 17:44:06 +0530175 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530176 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
Nabin Haitb02c1092018-02-05 16:09:51 +0530177 fieldtype='Select', insert_after='gst_col_break', print_hide=1,
Nabin Haite6d65bc2018-02-14 17:44:06 +0530178 depends_on='eval:doc.is_return==1',
Nabin Haita8d10b72018-02-12 16:54:13 +0530179 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 +0530180 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530181
Nabin Hait879e1622017-08-21 08:28:55 +0530182 purchase_invoice_gst_fields = [
183 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
184 fieldtype='Data', insert_after='supplier_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530185 fetch_from='supplier_address.gstin', print_hide=1, read_only=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530186 dict(fieldname='company_gstin', label='Company GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530187 fieldtype='Data', insert_after='shipping_address_display',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530188 fetch_from='shipping_address.gstin', print_hide=1, read_only=1),
Nabin Haitb02c1092018-02-05 16:09:51 +0530189 dict(fieldname='place_of_supply', label='Place of Supply',
190 fieldtype='Data', insert_after='shipping_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530191 print_hide=1, read_only=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530192 ]
193
194 purchase_invoice_itc_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530195 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
196 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530197 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 +0530198 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
199 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
200 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
201 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
202 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
203 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
204 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
205 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530206 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530207
Nabin Hait879e1622017-08-21 08:28:55 +0530208 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530209 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530210 fieldtype='Data', insert_after='customer_address', read_only=1,
Shreya Shah4fa600a2018-06-05 11:27:53 +0530211 fetch_from='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530212 dict(fieldname='customer_gstin', label='Customer GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530213 fieldtype='Data', insert_after='shipping_address_name',
214 fetch_from='shipping_address_name.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530215 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530216 fieldtype='Data', insert_after='customer_gstin',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530217 print_hide=1, read_only=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530218 dict(fieldname='company_gstin', label='Company GSTIN',
219 fieldtype='Data', insert_after='company_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530220 fetch_from='company_address.gstin', print_hide=1, read_only=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530221 ]
222
223 sales_invoice_shipping_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530224 dict(fieldname='port_code', label='Port Code',
225 fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530226 depends_on="eval:doc.gst_category=='Overseas' "),
vishdha98e33c32018-01-29 13:57:34 +0530227 dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
228 fieldtype='Data', insert_after='port_code', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530229 depends_on="eval:doc.gst_category=='Overseas' "),
vishdha98e33c32018-01-29 13:57:34 +0530230 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
231 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530232 depends_on="eval:doc.gst_category=='Overseas' "),
Nabin Hait879e1622017-08-21 08:28:55 +0530233 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530234
Shreya Shah4fa600a2018-06-05 11:27:53 +0530235 inter_state_gst_field = [
236 dict(fieldname='is_inter_state', label='Is Inter State',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530237 fieldtype='Check', insert_after='disabled', print_hide=1),
238 dict(fieldname='tax_category_column_break', fieldtype='Column Break',
239 insert_after='is_inter_state'),
240 dict(fieldname='gst_state', label='Source State', fieldtype='Select',
241 options='\n'.join(states), insert_after='company')
Shreya Shah4fa600a2018-06-05 11:27:53 +0530242 ]
243
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530244 ewaybill_fields = [
245 {
246 'fieldname': 'distance',
247 'label': 'Distance (in km)',
248 'fieldtype': 'Float',
249 'insert_after': 'vehicle_no',
250 'print_hide': 1
251 },
252 {
253 'fieldname': 'gst_transporter_id',
254 'label': 'GST Transporter ID',
255 'fieldtype': 'Data',
Nabin Hait34c551d2019-07-03 10:34:31 +0530256 'insert_after': 'transporter',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530257 'fetch_from': 'transporter.gst_transporter_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530258 'print_hide': 1,
259 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530260 },
261 {
262 'fieldname': 'mode_of_transport',
263 'label': 'Mode of Transport',
264 'fieldtype': 'Select',
265 'options': '\nRoad\nAir\nRail\nShip',
266 'default': 'Road',
Nabin Hait34c551d2019-07-03 10:34:31 +0530267 'insert_after': 'transporter_name',
268 'print_hide': 1,
269 'translatable': 0
270 },
271 {
272 'fieldname': 'gst_vehicle_type',
273 'label': 'GST Vehicle Type',
274 'fieldtype': 'Select',
275 'options': 'Regular\nOver Dimensional Cargo (ODC)',
276 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
277 'default': 'Regular',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530278 'insert_after': 'lr_date',
Nabin Hait34c551d2019-07-03 10:34:31 +0530279 'print_hide': 1,
280 'translatable': 0
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530281 },
282 {
283 'fieldname': 'ewaybill',
284 'label': 'E-Way Bill No.',
285 'fieldtype': 'Data',
286 'depends_on': 'eval:(doc.docstatus === 1)',
287 'allow_on_submit': 1,
288 'insert_after': 'customer_name_in_arabic',
289 'translatable': 0,
Deepesh Garg29997412021-03-29 19:49:52 +0530290 }
Nabin Hait34c551d2019-07-03 10:34:31 +0530291 ]
292
293 si_ewaybill_fields = [
294 {
295 'fieldname': 'transporter_info',
296 'label': 'Transporter Info',
297 'fieldtype': 'Section Break',
298 'insert_after': 'terms',
299 'collapsible': 1,
300 'collapsible_depends_on': 'transporter',
301 'print_hide': 1
302 },
303 {
304 'fieldname': 'transporter',
305 'label': 'Transporter',
306 'fieldtype': 'Link',
307 'insert_after': 'transporter_info',
308 'options': 'Supplier',
309 'print_hide': 1
310 },
311 {
312 'fieldname': 'gst_transporter_id',
313 'label': 'GST Transporter ID',
314 'fieldtype': 'Data',
315 'insert_after': 'transporter',
316 'fetch_from': 'transporter.gst_transporter_id',
317 'print_hide': 1,
318 'translatable': 0
319 },
320 {
321 'fieldname': 'driver',
322 'label': 'Driver',
323 'fieldtype': 'Link',
324 'insert_after': 'gst_transporter_id',
325 'options': 'Driver',
326 'print_hide': 1
327 },
328 {
329 'fieldname': 'lr_no',
330 'label': 'Transport Receipt No',
331 'fieldtype': 'Data',
332 'insert_after': 'driver',
333 'print_hide': 1,
334 'translatable': 0
335 },
336 {
337 'fieldname': 'vehicle_no',
338 'label': 'Vehicle No',
339 'fieldtype': 'Data',
340 'insert_after': 'lr_no',
341 'print_hide': 1,
342 'translatable': 0
343 },
344 {
345 'fieldname': 'distance',
346 'label': 'Distance (in km)',
347 'fieldtype': 'Float',
348 'insert_after': 'vehicle_no',
349 'print_hide': 1
350 },
351 {
352 'fieldname': 'transporter_col_break',
353 'fieldtype': 'Column Break',
354 'insert_after': 'distance'
355 },
356 {
357 'fieldname': 'transporter_name',
358 'label': 'Transporter Name',
359 'fieldtype': 'Data',
360 'insert_after': 'transporter_col_break',
361 'fetch_from': 'transporter.name',
362 'read_only': 1,
363 'print_hide': 1,
364 'translatable': 0
365 },
366 {
367 'fieldname': 'mode_of_transport',
368 'label': 'Mode of Transport',
369 'fieldtype': 'Select',
370 'options': '\nRoad\nAir\nRail\nShip',
Nabin Hait34c551d2019-07-03 10:34:31 +0530371 'insert_after': 'transporter_name',
372 'print_hide': 1,
373 'translatable': 0
374 },
375 {
376 'fieldname': 'driver_name',
377 'label': 'Driver Name',
378 'fieldtype': 'Data',
379 'insert_after': 'mode_of_transport',
380 'fetch_from': 'driver.full_name',
381 'print_hide': 1,
382 'translatable': 0
383 },
384 {
385 'fieldname': 'lr_date',
386 'label': 'Transport Receipt Date',
387 'fieldtype': 'Date',
388 'insert_after': 'driver_name',
389 'default': 'Today',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530390 'print_hide': 1
391 },
392 {
393 'fieldname': 'gst_vehicle_type',
394 'label': 'GST Vehicle Type',
395 'fieldtype': 'Select',
Nabin Hait34c551d2019-07-03 10:34:31 +0530396 'options': 'Regular\nOver Dimensional Cargo (ODC)',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530397 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
Nabin Hait34c551d2019-07-03 10:34:31 +0530398 'default': 'Regular',
399 'insert_after': 'lr_date',
400 'print_hide': 1,
401 'translatable': 0
402 },
403 {
404 'fieldname': 'ewaybill',
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530405 'label': 'E-Way Bill No.',
Nabin Hait34c551d2019-07-03 10:34:31 +0530406 'fieldtype': 'Data',
Saqib6d74f5b2020-12-25 10:26:43 +0530407 'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)',
Nabin Hait34c551d2019-07-03 10:34:31 +0530408 'allow_on_submit': 1,
deepeshgarg007a85db662019-07-14 18:15:19 +0530409 'insert_after': 'tax_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530410 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530411 }
412 ]
413
Saqib6d74f5b2020-12-25 10:26:43 +0530414 si_einvoice_fields = [
415 dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1,
416 depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'),
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530417
Saqib6d74f5b2020-12-25 10:26:43 +0530418 dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='irn', no_copy=1, print_hide=1),
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530419
Saqib6d74f5b2020-12-25 10:26:43 +0530420 dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1),
421
422 dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1,
423 depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
424
425 dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1, print_hide=1,
426 depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
427
428 dict(fieldname='signed_einvoice', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1),
429
430 dict(fieldname='signed_qr_code', fieldtype='Code', options='JSON', hidden=1, no_copy=1, print_hide=1, read_only=1),
431
432 dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, no_copy=1, print_hide=1, read_only=1)
433 ]
434
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530435 custom_fields = {
436 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530437 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
438 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530439 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530440 options='\n'.join(states), insert_after='gstin'),
441 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait562d9422018-09-07 16:14:44 +0530442 fieldtype='Data', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530443 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530444 'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530445 'Purchase Order': purchase_invoice_gst_fields,
446 'Purchase Receipt': purchase_invoice_gst_fields,
Saqib6d74f5b2020-12-25 10:26:43 +0530447 'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields + si_einvoice_fields,
Deepesh Garg29997412021-03-29 19:49:52 +0530448 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields + delivery_note_gst_category,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530449 'Sales Order': sales_invoice_gst_fields,
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530450 'Tax Category': inter_state_gst_field,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530451 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530452 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530453 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
Marica9942acd2020-04-21 13:13:39 +0530454 dict(fieldname='is_nil_exempt', label='Is Nil Rated or Exempted',
Deepesh Garg22b61602019-03-21 20:47:47 +0530455 fieldtype='Check', insert_after='gst_hsn_code'),
456 dict(fieldname='is_non_gst', label='Is Non GST ',
457 fieldtype='Check', insert_after='is_nil_exempt')
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530458 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530459 'Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
460 'Supplier Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
461 'Sales Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
462 'Delivery Note Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
463 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
464 'Purchase Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
465 'Purchase Receipt Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
466 'Purchase Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Himanshu Warekar656d8e42019-04-01 19:38:43 +0530467 'Material Request Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Anurag Mishra289c8222020-06-19 19:17:57 +0530468 'Salary Component': [
469 dict(fieldname= 'component_type',
470 label= 'Component Type',
471 fieldtype= 'Select',
472 insert_after= 'description',
473 options= "\nProvident Fund\nAdditional Provident Fund\nProvident Fund Loan\nProfessional Tax",
474 depends_on = 'eval:doc.type == "Deduction"'
475 )
476 ],
Pawan Mehtaf4196352018-04-05 14:54:51 +0530477 'Employee': [
Anurag Mishra289c8222020-06-19 19:17:57 +0530478 dict(fieldname='ifsc_code',
479 label='IFSC Code',
480 fieldtype='Data',
481 insert_after='bank_ac_no',
482 print_hide=1,
483 depends_on='eval:doc.salary_mode == "Bank"'
484 ),
485 dict(
486 fieldname = 'pan_number',
487 label = 'PAN Number',
488 fieldtype = 'Data',
489 insert_after = 'payroll_cost_center',
490 print_hide = 1
491 ),
492 dict(
493 fieldname = 'micr_code',
494 label = 'MICR Code',
495 fieldtype = 'Data',
496 insert_after = 'ifsc_code',
497 print_hide = 1,
498 depends_on='eval:doc.salary_mode == "Bank"'
499 ),
500 dict(
501 fieldname = 'provident_fund_account',
502 label = 'Provident Fund Account',
503 fieldtype = 'Data',
504 insert_after = 'pan_number'
505 )
506
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530507 ],
508 'Company': [
509 dict(fieldname='hra_section', label='HRA Settings',
Anurag Mishraa5527222019-06-14 15:25:57 +0530510 fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530511 dict(fieldname='basic_component', label='Basic Component',
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530512 fieldtype='Link', options='Salary Component', insert_after='hra_section'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530513 dict(fieldname='hra_component', label='HRA Component',
514 fieldtype='Link', options='Salary Component', insert_after='basic_component'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530515 dict(fieldname='arrear_component', label='Arrear Component',
Mangesh-Khairnar9215de02019-05-06 16:24:10 +0530516 fieldtype='Link', options='Salary Component', insert_after='hra_component'),
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530517 dict(fieldname='non_profit_section', label='Non Profit Settings',
518 fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1),
519 dict(fieldname='company_80g_number', label='80G Number',
520 fieldtype='Data', insert_after='non_profit_section'),
521 dict(fieldname='with_effect_from', label='80G With Effect From',
522 fieldtype='Date', insert_after='company_80g_number'),
523 dict(fieldname='pan_details', label='PAN Number',
524 fieldtype='Data', insert_after='with_effect_from')
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530525 ],
526 'Employee Tax Exemption Declaration':[
527 dict(fieldname='hra_section', label='HRA Exemption',
528 fieldtype='Section Break', insert_after='declarations'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530529 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530530 fieldtype='Currency', insert_after='hra_section'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530531 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530532 fieldtype='Check', insert_after='monthly_house_rent', depends_on='monthly_house_rent'),
533 dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure',
534 fieldtype='Currency', insert_after='rented_in_metro_city', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530535 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530536 insert_after='salary_structure_hra', depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530537 dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530538 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530539 dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530540 fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1, depends_on='monthly_house_rent')
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530541 ],
542 'Employee Tax Exemption Proof Submission': [
543 dict(fieldname='hra_section', label='HRA Exemption',
544 fieldtype='Section Break', insert_after='tax_exemption_proofs'),
545 dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount',
546 fieldtype='Currency', insert_after='hra_section'),
547 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530548 fieldtype='Check', insert_after='house_rent_payment_amount', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530549 dict(fieldname='rented_from_date', label='Rented From Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530550 fieldtype='Date', insert_after='rented_in_metro_city', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530551 dict(fieldname='rented_to_date', label='Rented To Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530552 fieldtype='Date', insert_after='rented_from_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530553 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530554 insert_after='rented_to_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530555 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530556 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530557 dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530558 fieldtype='Currency', insert_after='monthly_house_rent', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530559 dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530560 fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1, depends_on='house_rent_payment_amount')
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530561 ],
562 'Supplier': [
563 {
564 'fieldname': 'gst_transporter_id',
565 'label': 'GST Transporter ID',
566 'fieldtype': 'Data',
567 'insert_after': 'supplier_type',
568 'depends_on': 'eval:doc.is_transporter'
Deepesh Garg22b61602019-03-21 20:47:47 +0530569 },
570 {
571 'fieldname': 'gst_category',
572 'label': 'GST Category',
573 'fieldtype': 'Select',
574 'insert_after': 'gst_transporter_id',
575 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders',
576 'default': 'Unregistered'
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530577 },
578 {
579 'fieldname': 'export_type',
580 'label': 'Export Type',
581 'fieldtype': 'Select',
582 'insert_after': 'gst_category',
583 'default': 'Without Payment of Tax',
584 'depends_on':'eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
585 'options': '\nWith Payment of Tax\nWithout Payment of Tax'
Deepesh Garg22b61602019-03-21 20:47:47 +0530586 }
587 ],
588 'Customer': [
589 {
590 'fieldname': 'gst_category',
591 'label': 'GST Category',
592 'fieldtype': 'Select',
593 'insert_after': 'customer_type',
594 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
595 'default': 'Unregistered'
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530596 },
597 {
598 'fieldname': 'export_type',
599 'label': 'Export Type',
600 'fieldtype': 'Select',
601 'insert_after': 'gst_category',
602 'default': 'Without Payment of Tax',
603 'depends_on':'eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
604 'options': '\nWith Payment of Tax\nWithout Payment of Tax'
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530605 }
Shivam Mishra1d6395c2020-03-30 18:14:44 +0530606 ],
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530607 'Member': [
608 {
609 'fieldname': 'pan_number',
610 'label': 'PAN Details',
611 'fieldtype': 'Data',
612 'insert_after': 'email_id'
613 }
614 ],
615 'Donor': [
Shivam Mishra1d6395c2020-03-30 18:14:44 +0530616 {
617 'fieldname': 'pan_number',
618 'label': 'PAN Details',
619 'fieldtype': 'Data',
620 'insert_after': 'email'
621 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530622 ]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530623 }
Deepesh Garg22b61602019-03-21 20:47:47 +0530624 create_custom_fields(custom_fields, update=update)
Nabin Hait9c421612017-07-20 13:32:01 +0530625
Saurabh2d8a7ee2018-05-11 13:16:16 +0530626def make_fixtures(company=None):
627 docs = []
628 company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
629
630 set_salary_components(docs)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530631 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530632
633 for d in docs:
634 try:
635 doc = frappe.get_doc(d)
636 doc.flags.ignore_permissions = True
637 doc.insert()
638 except frappe.NameError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530639 frappe.clear_messages()
Zarrar7f8024c2018-08-01 17:45:05 +0530640 except frappe.DuplicateEntryError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530641 frappe.clear_messages()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530642
Zarrar7f8024c2018-08-01 17:45:05 +0530643 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530644 set_tax_withholding_category(company)
645
Saurabh2d8a7ee2018-05-11 13:16:16 +0530646def set_salary_components(docs):
647 docs.extend([
Nabin Hait58ee6c12020-04-26 17:45:57 +0530648 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax',
649 'description': 'Professional Tax', 'type': 'Deduction', 'exempted_from_income_tax': 1},
650 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund',
651 'description': 'Provident fund', 'type': 'Deduction', 'is_tax_applicable': 1},
652 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance',
653 'description': 'House Rent Allowance', 'type': 'Earning', 'is_tax_applicable': 1},
654 {'doctype': 'Salary Component', 'salary_component': 'Basic',
655 'description': 'Basic', 'type': 'Earning', 'is_tax_applicable': 1},
656 {'doctype': 'Salary Component', 'salary_component': 'Arrear',
657 'description': 'Arrear', 'type': 'Earning', 'is_tax_applicable': 1},
658 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment',
659 'description': 'Leave Encashment', 'type': 'Earning', 'is_tax_applicable': 1}
Saurabh2d8a7ee2018-05-11 13:16:16 +0530660 ])
661
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530662def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +0530663 accounts = []
Anuja Pawar4569e522021-01-14 19:24:30 +0530664 fiscal_year = None
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530665 abbr = frappe.get_value("Company", company, "abbr")
666 tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
Saurabh2d8a7ee2018-05-11 13:16:16 +0530667
668 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530669 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +0530670
Anuja Pawar4569e522021-01-14 19:24:30 +0530671 try:
672 fiscal_year = get_fiscal_year(today(), verbose=0, company=company)[0]
673 except FiscalYearError:
674 pass
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530675
Anuja Pawar4569e522021-01-14 19:24:30 +0530676 docs = get_tds_details(accounts, fiscal_year)
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530677
Zarrar7f8024c2018-08-01 17:45:05 +0530678 for d in docs:
679 try:
680 doc = frappe.get_doc(d)
681 doc.flags.ignore_permissions = True
Nabin Haitafef9c12019-02-12 11:28:20 +0530682 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +0530683 doc.insert()
684 except frappe.DuplicateEntryError:
685 doc = frappe.get_doc("Tax Withholding Category", d.get("name"))
Zarrar963d62b2019-03-23 10:30:12 +0530686
687 if accounts:
688 doc.append("accounts", accounts[0])
Zarrar7f8024c2018-08-01 17:45:05 +0530689
Anuja Pawar4569e522021-01-14 19:24:30 +0530690 if fiscal_year:
691 # if fiscal year don't match with any of the already entered data, append rate row
692 fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
693 if not fy_exist:
694 doc.append("rates", d.get('rates')[0])
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530695
Anuja Pawar4569e522021-01-14 19:24:30 +0530696 doc.flags.ignore_permissions = True
697 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +0530698 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530699
700def set_tds_account(docs, company):
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530701 abbr = frappe.get_value("Company", company, "abbr")
Nabin Haitf77cd542018-11-20 16:46:25 +0530702 parent_account = frappe.db.get_value("Account", filters = {"account_name": "Duties and Taxes", "company": company})
703 if parent_account:
704 docs.extend([
705 {
706 "doctype": "Account",
707 "account_name": "TDS Payable",
708 "account_type": "Tax",
709 "parent_account": parent_account,
710 "company": company
711 }
712 ])
Zarrar7f8024c2018-08-01 17:45:05 +0530713
714def get_tds_details(accounts, fiscal_year):
715 # bootstrap default tax withholding sections
716 return [
717 dict(name="TDS - 194C - Company",
718 category_name="Payment to Contractors (Single / Aggregate)",
719 doctype="Tax Withholding Category", accounts=accounts,
720 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
721 "single_threshold": 30000, "cumulative_threshold": 100000}]),
722 dict(name="TDS - 194C - Individual",
723 category_name="Payment to Contractors (Single / Aggregate)",
724 doctype="Tax Withholding Category", accounts=accounts,
725 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
726 "single_threshold": 30000, "cumulative_threshold": 100000}]),
727 dict(name="TDS - 194C - No PAN / Invalid PAN",
728 category_name="Payment to Contractors (Single / Aggregate)",
729 doctype="Tax Withholding Category", accounts=accounts,
730 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
731 "single_threshold": 30000, "cumulative_threshold": 100000}]),
732 dict(name="TDS - 194D - Company",
733 category_name="Insurance Commission",
734 doctype="Tax Withholding Category", accounts=accounts,
735 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
736 "single_threshold": 15000, "cumulative_threshold": 0}]),
737 dict(name="TDS - 194D - Company Assessee",
738 category_name="Insurance Commission",
739 doctype="Tax Withholding Category", accounts=accounts,
740 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
741 "single_threshold": 15000, "cumulative_threshold": 0}]),
742 dict(name="TDS - 194D - Individual",
743 category_name="Insurance Commission",
744 doctype="Tax Withholding Category", accounts=accounts,
745 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
746 "single_threshold": 15000, "cumulative_threshold": 0}]),
747 dict(name="TDS - 194D - No PAN / Invalid PAN",
748 category_name="Insurance Commission",
749 doctype="Tax Withholding Category", accounts=accounts,
750 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
751 "single_threshold": 15000, "cumulative_threshold": 0}]),
752 dict(name="TDS - 194DA - Company",
753 category_name="Non-exempt payments made under a life insurance policy",
754 doctype="Tax Withholding Category", accounts=accounts,
755 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
756 "single_threshold": 100000, "cumulative_threshold": 0}]),
757 dict(name="TDS - 194DA - Individual",
758 category_name="Non-exempt payments made under a life insurance policy",
759 doctype="Tax Withholding Category", accounts=accounts,
760 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
761 "single_threshold": 100000, "cumulative_threshold": 0}]),
762 dict(name="TDS - 194DA - No PAN / Invalid PAN",
763 category_name="Non-exempt payments made under a life insurance policy",
764 doctype="Tax Withholding Category", accounts=accounts,
765 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
766 "single_threshold": 100000, "cumulative_threshold": 0}]),
767 dict(name="TDS - 194H - Company",
768 category_name="Commission / Brokerage",
769 doctype="Tax Withholding Category", accounts=accounts,
770 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
771 "single_threshold": 15000, "cumulative_threshold": 0}]),
772 dict(name="TDS - 194H - Individual",
773 category_name="Commission / Brokerage",
774 doctype="Tax Withholding Category", accounts=accounts,
775 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
776 "single_threshold": 15000, "cumulative_threshold": 0}]),
777 dict(name="TDS - 194H - No PAN / Invalid PAN",
778 category_name="Commission / Brokerage",
779 doctype="Tax Withholding Category", accounts=accounts,
780 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
781 "single_threshold": 15000, "cumulative_threshold": 0}]),
782 dict(name="TDS - 194I - Rent - Company",
783 category_name="Rent",
784 doctype="Tax Withholding Category", accounts=accounts,
785 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
786 "single_threshold": 180000, "cumulative_threshold": 0}]),
787 dict(name="TDS - 194I - Rent - Individual",
788 category_name="Rent",
789 doctype="Tax Withholding Category", accounts=accounts,
790 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
791 "single_threshold": 180000, "cumulative_threshold": 0}]),
792 dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
793 category_name="Rent",
794 doctype="Tax Withholding Category", accounts=accounts,
795 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
796 "single_threshold": 180000, "cumulative_threshold": 0}]),
797 dict(name="TDS - 194I - Rent/Machinery - Company",
798 category_name="Rent-Plant / Machinery",
799 doctype="Tax Withholding Category", accounts=accounts,
800 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
801 "single_threshold": 180000, "cumulative_threshold": 0}]),
802 dict(name="TDS - 194I - Rent/Machinery - Individual",
803 category_name="Rent-Plant / Machinery",
804 doctype="Tax Withholding Category", accounts=accounts,
805 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
806 "single_threshold": 180000, "cumulative_threshold": 0}]),
807 dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
808 category_name="Rent-Plant / Machinery",
809 doctype="Tax Withholding Category", accounts=accounts,
810 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
811 "single_threshold": 180000, "cumulative_threshold": 0}]),
812 dict(name="TDS - 194J - Professional Fees - Company",
813 category_name="Professional Fees",
814 doctype="Tax Withholding Category", accounts=accounts,
815 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
816 "single_threshold": 30000, "cumulative_threshold": 0}]),
817 dict(name="TDS - 194J - Professional Fees - Individual",
818 category_name="Professional Fees",
819 doctype="Tax Withholding Category", accounts=accounts,
820 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
821 "single_threshold": 30000, "cumulative_threshold": 0}]),
822 dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
823 category_name="Professional Fees",
824 doctype="Tax Withholding Category", accounts=accounts,
825 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
826 "single_threshold": 30000, "cumulative_threshold": 0}]),
827 dict(name="TDS - 194J - Director Fees - Company",
828 category_name="Director Fees",
829 doctype="Tax Withholding Category", accounts=accounts,
830 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
831 "single_threshold": 0, "cumulative_threshold": 0}]),
832 dict(name="TDS - 194J - Director Fees - Individual",
833 category_name="Director Fees",
834 doctype="Tax Withholding Category", accounts=accounts,
835 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
836 "single_threshold": 0, "cumulative_threshold": 0}]),
837 dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
838 category_name="Director Fees",
839 doctype="Tax Withholding Category", accounts=accounts,
840 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
841 "single_threshold": 0, "cumulative_threshold": 0}]),
842 dict(name="TDS - 194 - Dividends - Company",
843 category_name="Dividends",
844 doctype="Tax Withholding Category", accounts=accounts,
845 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
846 "single_threshold": 2500, "cumulative_threshold": 0}]),
847 dict(name="TDS - 194 - Dividends - Individual",
848 category_name="Dividends",
849 doctype="Tax Withholding Category", accounts=accounts,
850 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
851 "single_threshold": 2500, "cumulative_threshold": 0}]),
852 dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
853 category_name="Dividends",
854 doctype="Tax Withholding Category", accounts=accounts,
855 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
856 "single_threshold": 2500, "cumulative_threshold": 0}])
Anurag Mishrae1464a72020-08-17 15:03:32 +0530857 ]
858
Anurag Mishra25c35682020-08-18 14:13:54 +0530859def create_gratuity_rule():
Anurag Mishrae1464a72020-08-17 15:03:32 +0530860
861 # Standard Indain Gratuity Rule
Anurag Mishra493eea12020-08-18 15:02:32 +0530862 if not frappe.db.exists("Gratuity Rule", "Indian Standard Gratuity Rule"):
863 rule = frappe.new_doc("Gratuity Rule")
864 rule.name = "Indian Standard Gratuity Rule"
865 rule.calculate_gratuity_amount_based_on = "Current Slab"
866 rule.work_experience_calculation_method = "Round Off Work Experience"
867 rule.minimum_year_for_gratuity = 5
Anurag Mishrae1464a72020-08-17 15:03:32 +0530868
Anurag Mishra493eea12020-08-18 15:02:32 +0530869 fraction = 15/26
870 rule.append("gratuity_rule_slabs", {
871 "from_year": 0,
872 "to_year":0,
873 "fraction_of_applicable_earnings": fraction
874 })
Anurag Mishrae1464a72020-08-17 15:03:32 +0530875
Anurag Mishra493eea12020-08-18 15:02:32 +0530876 rule.flags.ignore_mandatory = True
Sagar Vora4c31fbb2021-04-01 15:32:37 +0530877 rule.save()