blob: ec58fd2f33c32a2a172a10827c6a32ebf3f98149 [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',
Saqib93203162021-04-12 17:55:46 +053054 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill', 'E-Invoice Summary'):
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)
Deepesh Gargc36e48a2021-04-12 10:55:43 +0530130 taxable_value = dict(fieldname='taxable_value', label='Taxable Value',
131 fieldtype='Currency', insert_after='base_net_amount', hidden=1, options="Company:company:default_currency",
132 print_hide=1)
Deepesh Garg22b61602019-03-21 20:47:47 +0530133
134 purchase_invoice_gst_category = [
Nabin Hait879e1622017-08-21 08:28:55 +0530135 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
vishdha109b4082018-01-30 12:11:13 +0530136 insert_after='language', print_hide=1, collapsible=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530137 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530138 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530139 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530140 fetch_from='supplier.gst_category', fetch_if_empty=1),
141 dict(fieldname='export_type', label='Export Type',
142 fieldtype='Select', insert_after='gst_category', print_hide=1,
143 depends_on='eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
144 options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='supplier.export_type',
145 fetch_if_empty=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530146 ]
147
148 sales_invoice_gst_category = [
149 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
150 insert_after='language', print_hide=1, collapsible=1),
151 dict(fieldname='gst_category', label='GST Category',
Nabin Hait10dae5d2019-04-01 20:56:51 +0530152 fieldtype='Select', insert_after='gst_section', print_hide=1,
Nabin Hait89b06132019-05-01 14:18:21 +0530153 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530154 fetch_from='customer.gst_category', fetch_if_empty=1),
155 dict(fieldname='export_type', label='Export Type',
156 fieldtype='Select', insert_after='gst_category', print_hide=1,
157 depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
158 options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='customer.export_type',
159 fetch_if_empty=1),
Deepesh Garg22b61602019-03-21 20:47:47 +0530160 ]
161
Deepesh Garg29997412021-03-29 19:49:52 +0530162 delivery_note_gst_category = [
163 dict(fieldname='gst_category', label='GST Category',
164 fieldtype='Select', insert_after='gst_vehicle_type', print_hide=1,
165 options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
166 fetch_from='customer.gst_category', fetch_if_empty=1),
167 ]
168
Deepesh Garg22b61602019-03-21 20:47:47 +0530169 invoice_gst_fields = [
Nabin Hait879e1622017-08-21 08:28:55 +0530170 dict(fieldname='invoice_copy', label='Invoice Copy',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530171 fieldtype='Select', insert_after='export_type', print_hide=1, allow_on_submit=1,
Nabin Hait879e1622017-08-21 08:28:55 +0530172 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
173 dict(fieldname='reverse_charge', label='Reverse Charge',
174 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
175 options='Y\nN', default='N'),
Nabin Hait879e1622017-08-21 08:28:55 +0530176 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530177 fieldtype='Data', insert_after='export_type', print_hide=1),
Nabin Haite6d65bc2018-02-14 17:44:06 +0530178 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530179 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
Nabin Haitb02c1092018-02-05 16:09:51 +0530180 fieldtype='Select', insert_after='gst_col_break', print_hide=1,
Nabin Haite6d65bc2018-02-14 17:44:06 +0530181 depends_on='eval:doc.is_return==1',
Nabin Haita8d10b72018-02-12 16:54:13 +0530182 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 +0530183 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530184
Nabin Hait879e1622017-08-21 08:28:55 +0530185 purchase_invoice_gst_fields = [
186 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
187 fieldtype='Data', insert_after='supplier_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530188 fetch_from='supplier_address.gstin', print_hide=1, read_only=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530189 dict(fieldname='company_gstin', label='Company GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530190 fieldtype='Data', insert_after='shipping_address_display',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530191 fetch_from='shipping_address.gstin', print_hide=1, read_only=1),
Nabin Haitb02c1092018-02-05 16:09:51 +0530192 dict(fieldname='place_of_supply', label='Place of Supply',
193 fieldtype='Data', insert_after='shipping_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530194 print_hide=1, read_only=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530195 ]
196
197 purchase_invoice_itc_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530198 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
199 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530200 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 +0530201 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
202 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
203 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
204 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
205 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
206 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
207 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
208 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530209 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530210
Nabin Hait879e1622017-08-21 08:28:55 +0530211 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530212 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530213 fieldtype='Data', insert_after='customer_address', read_only=1,
Shreya Shah4fa600a2018-06-05 11:27:53 +0530214 fetch_from='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530215 dict(fieldname='customer_gstin', label='Customer GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530216 fieldtype='Data', insert_after='shipping_address_name',
217 fetch_from='shipping_address_name.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530218 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530219 fieldtype='Data', insert_after='customer_gstin',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530220 print_hide=1, read_only=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530221 dict(fieldname='company_gstin', label='Company GSTIN',
222 fieldtype='Data', insert_after='company_address',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530223 fetch_from='company_address.gstin', print_hide=1, read_only=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530224 ]
225
226 sales_invoice_shipping_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530227 dict(fieldname='port_code', label='Port Code',
228 fieldtype='Data', insert_after='reason_for_issuing_document', 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_number', label=' Shipping Bill Number',
231 fieldtype='Data', insert_after='port_code', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530232 depends_on="eval:doc.gst_category=='Overseas' "),
vishdha98e33c32018-01-29 13:57:34 +0530233 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
234 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
Deepesh Garg22b61602019-03-21 20:47:47 +0530235 depends_on="eval:doc.gst_category=='Overseas' "),
Nabin Hait879e1622017-08-21 08:28:55 +0530236 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530237
Shreya Shah4fa600a2018-06-05 11:27:53 +0530238 inter_state_gst_field = [
239 dict(fieldname='is_inter_state', label='Is Inter State',
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530240 fieldtype='Check', insert_after='disabled', print_hide=1),
241 dict(fieldname='tax_category_column_break', fieldtype='Column Break',
242 insert_after='is_inter_state'),
243 dict(fieldname='gst_state', label='Source State', fieldtype='Select',
244 options='\n'.join(states), insert_after='company')
Shreya Shah4fa600a2018-06-05 11:27:53 +0530245 ]
246
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530247 ewaybill_fields = [
248 {
249 'fieldname': 'distance',
250 'label': 'Distance (in km)',
251 'fieldtype': 'Float',
252 'insert_after': 'vehicle_no',
253 'print_hide': 1
254 },
255 {
256 'fieldname': 'gst_transporter_id',
257 'label': 'GST Transporter ID',
258 'fieldtype': 'Data',
Nabin Hait34c551d2019-07-03 10:34:31 +0530259 'insert_after': 'transporter',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530260 'fetch_from': 'transporter.gst_transporter_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530261 'print_hide': 1,
262 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530263 },
264 {
265 'fieldname': 'mode_of_transport',
266 'label': 'Mode of Transport',
267 'fieldtype': 'Select',
268 'options': '\nRoad\nAir\nRail\nShip',
269 'default': 'Road',
Nabin Hait34c551d2019-07-03 10:34:31 +0530270 'insert_after': 'transporter_name',
271 'print_hide': 1,
272 'translatable': 0
273 },
274 {
275 'fieldname': 'gst_vehicle_type',
276 'label': 'GST Vehicle Type',
277 'fieldtype': 'Select',
278 'options': 'Regular\nOver Dimensional Cargo (ODC)',
279 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
280 'default': 'Regular',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530281 'insert_after': 'lr_date',
Nabin Hait34c551d2019-07-03 10:34:31 +0530282 'print_hide': 1,
283 'translatable': 0
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530284 },
285 {
286 'fieldname': 'ewaybill',
287 'label': 'E-Way Bill No.',
288 'fieldtype': 'Data',
289 'depends_on': 'eval:(doc.docstatus === 1)',
290 'allow_on_submit': 1,
291 'insert_after': 'customer_name_in_arabic',
292 'translatable': 0,
Deepesh Garg29997412021-03-29 19:49:52 +0530293 }
Nabin Hait34c551d2019-07-03 10:34:31 +0530294 ]
295
296 si_ewaybill_fields = [
297 {
298 'fieldname': 'transporter_info',
299 'label': 'Transporter Info',
300 'fieldtype': 'Section Break',
301 'insert_after': 'terms',
302 'collapsible': 1,
303 'collapsible_depends_on': 'transporter',
304 'print_hide': 1
305 },
306 {
307 'fieldname': 'transporter',
308 'label': 'Transporter',
309 'fieldtype': 'Link',
310 'insert_after': 'transporter_info',
311 'options': 'Supplier',
312 'print_hide': 1
313 },
314 {
315 'fieldname': 'gst_transporter_id',
316 'label': 'GST Transporter ID',
317 'fieldtype': 'Data',
318 'insert_after': 'transporter',
319 'fetch_from': 'transporter.gst_transporter_id',
320 'print_hide': 1,
321 'translatable': 0
322 },
323 {
324 'fieldname': 'driver',
325 'label': 'Driver',
326 'fieldtype': 'Link',
327 'insert_after': 'gst_transporter_id',
328 'options': 'Driver',
329 'print_hide': 1
330 },
331 {
332 'fieldname': 'lr_no',
333 'label': 'Transport Receipt No',
334 'fieldtype': 'Data',
335 'insert_after': 'driver',
336 'print_hide': 1,
337 'translatable': 0
338 },
339 {
340 'fieldname': 'vehicle_no',
341 'label': 'Vehicle No',
342 'fieldtype': 'Data',
343 'insert_after': 'lr_no',
344 'print_hide': 1,
345 'translatable': 0
346 },
347 {
348 'fieldname': 'distance',
349 'label': 'Distance (in km)',
350 'fieldtype': 'Float',
351 'insert_after': 'vehicle_no',
352 'print_hide': 1
353 },
354 {
355 'fieldname': 'transporter_col_break',
356 'fieldtype': 'Column Break',
357 'insert_after': 'distance'
358 },
359 {
360 'fieldname': 'transporter_name',
361 'label': 'Transporter Name',
362 'fieldtype': 'Data',
363 'insert_after': 'transporter_col_break',
364 'fetch_from': 'transporter.name',
365 'read_only': 1,
366 'print_hide': 1,
367 'translatable': 0
368 },
369 {
370 'fieldname': 'mode_of_transport',
371 'label': 'Mode of Transport',
372 'fieldtype': 'Select',
373 'options': '\nRoad\nAir\nRail\nShip',
Nabin Hait34c551d2019-07-03 10:34:31 +0530374 'insert_after': 'transporter_name',
375 'print_hide': 1,
376 'translatable': 0
377 },
378 {
379 'fieldname': 'driver_name',
380 'label': 'Driver Name',
381 'fieldtype': 'Data',
382 'insert_after': 'mode_of_transport',
383 'fetch_from': 'driver.full_name',
384 'print_hide': 1,
385 'translatable': 0
386 },
387 {
388 'fieldname': 'lr_date',
389 'label': 'Transport Receipt Date',
390 'fieldtype': 'Date',
391 'insert_after': 'driver_name',
392 'default': 'Today',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530393 'print_hide': 1
394 },
395 {
396 'fieldname': 'gst_vehicle_type',
397 'label': 'GST Vehicle Type',
398 'fieldtype': 'Select',
Nabin Hait34c551d2019-07-03 10:34:31 +0530399 'options': 'Regular\nOver Dimensional Cargo (ODC)',
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530400 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
Nabin Hait34c551d2019-07-03 10:34:31 +0530401 'default': 'Regular',
402 'insert_after': 'lr_date',
403 'print_hide': 1,
404 'translatable': 0
405 },
406 {
407 'fieldname': 'ewaybill',
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530408 'label': 'E-Way Bill No.',
Nabin Hait34c551d2019-07-03 10:34:31 +0530409 'fieldtype': 'Data',
Saqib6d74f5b2020-12-25 10:26:43 +0530410 'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)',
Nabin Hait34c551d2019-07-03 10:34:31 +0530411 'allow_on_submit': 1,
deepeshgarg007a85db662019-07-14 18:15:19 +0530412 'insert_after': 'tax_id',
Nabin Hait34c551d2019-07-03 10:34:31 +0530413 'translatable': 0
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530414 }
415 ]
416
Saqib6d74f5b2020-12-25 10:26:43 +0530417 si_einvoice_fields = [
418 dict(fieldname='irn', label='IRN', fieldtype='Data', read_only=1, insert_after='customer', no_copy=1, print_hide=1,
419 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 +0530420
Saqib6d74f5b2020-12-25 10:26:43 +0530421 dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1,
422 depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
423
424 dict(fieldname='eway_bill_cancelled', label='E-Way Bill Cancelled', fieldtype='Check', no_copy=1, print_hide=1,
425 depends_on='eval:(doc.eway_bill_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
426
Saqib93203162021-04-12 17:55:46 +0530427 dict(fieldname='einvoice_section', label='E-Invoice Fields', fieldtype='Section Break', insert_after='gst_vehicle_type',
428 print_hide=1, hidden=1),
429
430 dict(fieldname='ack_no', label='Ack. No.', fieldtype='Data', read_only=1, hidden=1, insert_after='einvoice_section',
431 no_copy=1, print_hide=1),
432
433 dict(fieldname='ack_date', label='Ack. Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_no', no_copy=1, print_hide=1),
Saqib6d74f5b2020-12-25 10:26:43 +0530434
Saqib93203162021-04-12 17:55:46 +0530435 dict(fieldname='irn_cancel_date', label='Cancel Date', fieldtype='Data', read_only=1, hidden=1, insert_after='ack_date',
436 no_copy=1, print_hide=1),
Saqib6d74f5b2020-12-25 10:26:43 +0530437
Saqib93203162021-04-12 17:55:46 +0530438 dict(fieldname='signed_einvoice', label='Signed E-Invoice', fieldtype='Code', options='JSON', hidden=1, insert_after='irn_cancel_date',
439 no_copy=1, print_hide=1, read_only=1),
440
441 dict(fieldname='signed_qr_code', label='Signed QRCode', fieldtype='Code', options='JSON', hidden=1, insert_after='signed_einvoice',
442 no_copy=1, print_hide=1, read_only=1),
443
444 dict(fieldname='qrcode_image', label='QRCode', fieldtype='Attach Image', hidden=1, insert_after='signed_qr_code',
445 no_copy=1, print_hide=1, read_only=1),
446
447 dict(fieldname='einvoice_status', label='E-Invoice Status', fieldtype='Select', insert_after='qrcode_image',
448 options='\nPending\nGenerated\nCancelled\nFailed', default=None, hidden=1, no_copy=1, print_hide=1, read_only=1),
449
450 dict(fieldname='failure_description', label='E-Invoice Failure Description', fieldtype='Code', options='JSON',
451 hidden=1, insert_after='einvoice_status', no_copy=1, print_hide=1, read_only=1)
Saqib6d74f5b2020-12-25 10:26:43 +0530452 ]
453
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530454 custom_fields = {
455 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530456 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
457 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530458 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530459 options='\n'.join(states), insert_after='gstin'),
460 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait562d9422018-09-07 16:14:44 +0530461 fieldtype='Data', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530462 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530463 'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530464 'Purchase Order': purchase_invoice_gst_fields,
465 'Purchase Receipt': purchase_invoice_gst_fields,
Saqib6d74f5b2020-12-25 10:26:43 +0530466 '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 +0530467 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields + delivery_note_gst_category,
deepeshgarg007d29ee972019-01-09 17:09:11 +0530468 'Sales Order': sales_invoice_gst_fields,
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530469 'Tax Category': inter_state_gst_field,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530470 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530471 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530472 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
Marica9942acd2020-04-21 13:13:39 +0530473 dict(fieldname='is_nil_exempt', label='Is Nil Rated or Exempted',
Deepesh Garg22b61602019-03-21 20:47:47 +0530474 fieldtype='Check', insert_after='gst_hsn_code'),
475 dict(fieldname='is_non_gst', label='Is Non GST ',
476 fieldtype='Check', insert_after='is_nil_exempt')
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530477 ],
Deepesh Garg22b61602019-03-21 20:47:47 +0530478 'Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
479 'Supplier Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
480 'Sales Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
481 'Delivery Note Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Deepesh Gargc36e48a2021-04-12 10:55:43 +0530482 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst, taxable_value],
Deepesh Garg22b61602019-03-21 20:47:47 +0530483 'Purchase Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
484 'Purchase Receipt Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
485 'Purchase Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Himanshu Warekar656d8e42019-04-01 19:38:43 +0530486 'Material Request Item': [hsn_sac_field, nil_rated_exempt, is_non_gst],
Anurag Mishra289c8222020-06-19 19:17:57 +0530487 'Salary Component': [
488 dict(fieldname= 'component_type',
489 label= 'Component Type',
490 fieldtype= 'Select',
491 insert_after= 'description',
492 options= "\nProvident Fund\nAdditional Provident Fund\nProvident Fund Loan\nProfessional Tax",
493 depends_on = 'eval:doc.type == "Deduction"'
494 )
495 ],
Pawan Mehtaf4196352018-04-05 14:54:51 +0530496 'Employee': [
Anurag Mishra289c8222020-06-19 19:17:57 +0530497 dict(fieldname='ifsc_code',
498 label='IFSC Code',
499 fieldtype='Data',
500 insert_after='bank_ac_no',
501 print_hide=1,
502 depends_on='eval:doc.salary_mode == "Bank"'
503 ),
504 dict(
505 fieldname = 'pan_number',
506 label = 'PAN Number',
507 fieldtype = 'Data',
508 insert_after = 'payroll_cost_center',
509 print_hide = 1
510 ),
511 dict(
512 fieldname = 'micr_code',
513 label = 'MICR Code',
514 fieldtype = 'Data',
515 insert_after = 'ifsc_code',
516 print_hide = 1,
517 depends_on='eval:doc.salary_mode == "Bank"'
518 ),
519 dict(
520 fieldname = 'provident_fund_account',
521 label = 'Provident Fund Account',
522 fieldtype = 'Data',
523 insert_after = 'pan_number'
524 )
525
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530526 ],
527 'Company': [
528 dict(fieldname='hra_section', label='HRA Settings',
Anurag Mishraa5527222019-06-14 15:25:57 +0530529 fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530530 dict(fieldname='basic_component', label='Basic Component',
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530531 fieldtype='Link', options='Salary Component', insert_after='hra_section'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530532 dict(fieldname='hra_component', label='HRA Component',
533 fieldtype='Link', options='Salary Component', insert_after='basic_component'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530534 dict(fieldname='arrear_component', label='Arrear Component',
Mangesh-Khairnar9215de02019-05-06 16:24:10 +0530535 fieldtype='Link', options='Salary Component', insert_after='hra_component'),
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530536 dict(fieldname='non_profit_section', label='Non Profit Settings',
537 fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1),
538 dict(fieldname='company_80g_number', label='80G Number',
539 fieldtype='Data', insert_after='non_profit_section'),
540 dict(fieldname='with_effect_from', label='80G With Effect From',
541 fieldtype='Date', insert_after='company_80g_number'),
542 dict(fieldname='pan_details', label='PAN Number',
543 fieldtype='Data', insert_after='with_effect_from')
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530544 ],
545 'Employee Tax Exemption Declaration':[
546 dict(fieldname='hra_section', label='HRA Exemption',
547 fieldtype='Section Break', insert_after='declarations'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530548 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530549 fieldtype='Currency', insert_after='hra_section'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530550 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530551 fieldtype='Check', insert_after='monthly_house_rent', depends_on='monthly_house_rent'),
552 dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure',
553 fieldtype='Currency', insert_after='rented_in_metro_city', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530554 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530555 insert_after='salary_structure_hra', depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530556 dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530557 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='monthly_house_rent'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530558 dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530559 fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1, depends_on='monthly_house_rent')
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530560 ],
561 'Employee Tax Exemption Proof Submission': [
562 dict(fieldname='hra_section', label='HRA Exemption',
563 fieldtype='Section Break', insert_after='tax_exemption_proofs'),
564 dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount',
565 fieldtype='Currency', insert_after='hra_section'),
566 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530567 fieldtype='Check', insert_after='house_rent_payment_amount', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530568 dict(fieldname='rented_from_date', label='Rented From Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530569 fieldtype='Date', insert_after='rented_in_metro_city', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530570 dict(fieldname='rented_to_date', label='Rented To Date',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530571 fieldtype='Date', insert_after='rented_from_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530572 dict(fieldname='hra_column_break', fieldtype='Column Break',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530573 insert_after='rented_to_date', depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530574 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530575 fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530576 dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530577 fieldtype='Currency', insert_after='monthly_house_rent', read_only=1, depends_on='house_rent_payment_amount'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530578 dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption',
Nabin Hait04e7bf42019-04-25 18:44:10 +0530579 fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1, depends_on='house_rent_payment_amount')
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530580 ],
581 'Supplier': [
582 {
583 'fieldname': 'gst_transporter_id',
584 'label': 'GST Transporter ID',
585 'fieldtype': 'Data',
586 'insert_after': 'supplier_type',
587 'depends_on': 'eval:doc.is_transporter'
Deepesh Garg22b61602019-03-21 20:47:47 +0530588 },
589 {
590 'fieldname': 'gst_category',
591 'label': 'GST Category',
592 'fieldtype': 'Select',
593 'insert_after': 'gst_transporter_id',
594 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\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"], doc.gst_category)',
604 'options': '\nWith Payment of Tax\nWithout Payment of Tax'
Deepesh Garg22b61602019-03-21 20:47:47 +0530605 }
606 ],
607 'Customer': [
608 {
609 'fieldname': 'gst_category',
610 'label': 'GST Category',
611 'fieldtype': 'Select',
612 'insert_after': 'customer_type',
613 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders',
614 'default': 'Unregistered'
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530615 },
616 {
617 'fieldname': 'export_type',
618 'label': 'Export Type',
619 'fieldtype': 'Select',
620 'insert_after': 'gst_category',
621 'default': 'Without Payment of Tax',
622 'depends_on':'eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
623 'options': '\nWith Payment of Tax\nWithout Payment of Tax'
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530624 }
Shivam Mishra1d6395c2020-03-30 18:14:44 +0530625 ],
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530626 'Member': [
627 {
628 'fieldname': 'pan_number',
629 'label': 'PAN Details',
630 'fieldtype': 'Data',
631 'insert_after': 'email_id'
632 }
633 ],
634 'Donor': [
Shivam Mishra1d6395c2020-03-30 18:14:44 +0530635 {
636 'fieldname': 'pan_number',
637 'label': 'PAN Details',
638 'fieldtype': 'Data',
639 'insert_after': 'email'
640 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530641 ]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530642 }
Deepesh Garg22b61602019-03-21 20:47:47 +0530643 create_custom_fields(custom_fields, update=update)
Nabin Hait9c421612017-07-20 13:32:01 +0530644
Saurabh2d8a7ee2018-05-11 13:16:16 +0530645def make_fixtures(company=None):
646 docs = []
647 company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
648
649 set_salary_components(docs)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530650 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530651
652 for d in docs:
653 try:
654 doc = frappe.get_doc(d)
655 doc.flags.ignore_permissions = True
656 doc.insert()
657 except frappe.NameError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530658 frappe.clear_messages()
Zarrar7f8024c2018-08-01 17:45:05 +0530659 except frappe.DuplicateEntryError:
Faris Ansariec7b0642019-05-14 16:21:09 +0530660 frappe.clear_messages()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530661
Zarrar7f8024c2018-08-01 17:45:05 +0530662 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530663 set_tax_withholding_category(company)
664
Saurabh2d8a7ee2018-05-11 13:16:16 +0530665def set_salary_components(docs):
666 docs.extend([
Nabin Hait58ee6c12020-04-26 17:45:57 +0530667 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax',
668 'description': 'Professional Tax', 'type': 'Deduction', 'exempted_from_income_tax': 1},
669 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund',
670 'description': 'Provident fund', 'type': 'Deduction', 'is_tax_applicable': 1},
671 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance',
672 'description': 'House Rent Allowance', 'type': 'Earning', 'is_tax_applicable': 1},
673 {'doctype': 'Salary Component', 'salary_component': 'Basic',
674 'description': 'Basic', 'type': 'Earning', 'is_tax_applicable': 1},
675 {'doctype': 'Salary Component', 'salary_component': 'Arrear',
676 'description': 'Arrear', 'type': 'Earning', 'is_tax_applicable': 1},
677 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment',
678 'description': 'Leave Encashment', 'type': 'Earning', 'is_tax_applicable': 1}
Saurabh2d8a7ee2018-05-11 13:16:16 +0530679 ])
680
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530681def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +0530682 accounts = []
Anuja Pawar4569e522021-01-14 19:24:30 +0530683 fiscal_year = None
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530684 abbr = frappe.get_value("Company", company, "abbr")
685 tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
Saurabh2d8a7ee2018-05-11 13:16:16 +0530686
687 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530688 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +0530689
Anuja Pawar4569e522021-01-14 19:24:30 +0530690 try:
691 fiscal_year = get_fiscal_year(today(), verbose=0, company=company)[0]
692 except FiscalYearError:
693 pass
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530694
Anuja Pawar4569e522021-01-14 19:24:30 +0530695 docs = get_tds_details(accounts, fiscal_year)
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530696
Zarrar7f8024c2018-08-01 17:45:05 +0530697 for d in docs:
698 try:
699 doc = frappe.get_doc(d)
700 doc.flags.ignore_permissions = True
Nabin Haitafef9c12019-02-12 11:28:20 +0530701 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +0530702 doc.insert()
703 except frappe.DuplicateEntryError:
704 doc = frappe.get_doc("Tax Withholding Category", d.get("name"))
Zarrar963d62b2019-03-23 10:30:12 +0530705
706 if accounts:
707 doc.append("accounts", accounts[0])
Zarrar7f8024c2018-08-01 17:45:05 +0530708
Anuja Pawar4569e522021-01-14 19:24:30 +0530709 if fiscal_year:
710 # if fiscal year don't match with any of the already entered data, append rate row
711 fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
712 if not fy_exist:
713 doc.append("rates", d.get('rates')[0])
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +0530714
Anuja Pawar4569e522021-01-14 19:24:30 +0530715 doc.flags.ignore_permissions = True
716 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +0530717 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530718
719def set_tds_account(docs, company):
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530720 abbr = frappe.get_value("Company", company, "abbr")
Nabin Haitf77cd542018-11-20 16:46:25 +0530721 parent_account = frappe.db.get_value("Account", filters = {"account_name": "Duties and Taxes", "company": company})
722 if parent_account:
723 docs.extend([
724 {
725 "doctype": "Account",
726 "account_name": "TDS Payable",
727 "account_type": "Tax",
728 "parent_account": parent_account,
729 "company": company
730 }
731 ])
Zarrar7f8024c2018-08-01 17:45:05 +0530732
733def get_tds_details(accounts, fiscal_year):
734 # bootstrap default tax withholding sections
735 return [
736 dict(name="TDS - 194C - Company",
737 category_name="Payment to Contractors (Single / Aggregate)",
738 doctype="Tax Withholding Category", accounts=accounts,
739 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
740 "single_threshold": 30000, "cumulative_threshold": 100000}]),
741 dict(name="TDS - 194C - Individual",
742 category_name="Payment to Contractors (Single / Aggregate)",
743 doctype="Tax Withholding Category", accounts=accounts,
744 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
745 "single_threshold": 30000, "cumulative_threshold": 100000}]),
746 dict(name="TDS - 194C - No PAN / Invalid PAN",
747 category_name="Payment to Contractors (Single / Aggregate)",
748 doctype="Tax Withholding Category", accounts=accounts,
749 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
750 "single_threshold": 30000, "cumulative_threshold": 100000}]),
751 dict(name="TDS - 194D - Company",
752 category_name="Insurance Commission",
753 doctype="Tax Withholding Category", accounts=accounts,
754 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
755 "single_threshold": 15000, "cumulative_threshold": 0}]),
756 dict(name="TDS - 194D - Company Assessee",
757 category_name="Insurance Commission",
758 doctype="Tax Withholding Category", accounts=accounts,
759 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
760 "single_threshold": 15000, "cumulative_threshold": 0}]),
761 dict(name="TDS - 194D - Individual",
762 category_name="Insurance Commission",
763 doctype="Tax Withholding Category", accounts=accounts,
764 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
765 "single_threshold": 15000, "cumulative_threshold": 0}]),
766 dict(name="TDS - 194D - No PAN / Invalid PAN",
767 category_name="Insurance Commission",
768 doctype="Tax Withholding Category", accounts=accounts,
769 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
770 "single_threshold": 15000, "cumulative_threshold": 0}]),
771 dict(name="TDS - 194DA - Company",
772 category_name="Non-exempt payments made under a life insurance policy",
773 doctype="Tax Withholding Category", accounts=accounts,
774 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
775 "single_threshold": 100000, "cumulative_threshold": 0}]),
776 dict(name="TDS - 194DA - Individual",
777 category_name="Non-exempt payments made under a life insurance policy",
778 doctype="Tax Withholding Category", accounts=accounts,
779 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
780 "single_threshold": 100000, "cumulative_threshold": 0}]),
781 dict(name="TDS - 194DA - No PAN / Invalid PAN",
782 category_name="Non-exempt payments made under a life insurance policy",
783 doctype="Tax Withholding Category", accounts=accounts,
784 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
785 "single_threshold": 100000, "cumulative_threshold": 0}]),
786 dict(name="TDS - 194H - Company",
787 category_name="Commission / Brokerage",
788 doctype="Tax Withholding Category", accounts=accounts,
789 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
790 "single_threshold": 15000, "cumulative_threshold": 0}]),
791 dict(name="TDS - 194H - Individual",
792 category_name="Commission / Brokerage",
793 doctype="Tax Withholding Category", accounts=accounts,
794 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
795 "single_threshold": 15000, "cumulative_threshold": 0}]),
796 dict(name="TDS - 194H - No PAN / Invalid PAN",
797 category_name="Commission / Brokerage",
798 doctype="Tax Withholding Category", accounts=accounts,
799 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
800 "single_threshold": 15000, "cumulative_threshold": 0}]),
801 dict(name="TDS - 194I - Rent - Company",
802 category_name="Rent",
803 doctype="Tax Withholding Category", accounts=accounts,
804 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
805 "single_threshold": 180000, "cumulative_threshold": 0}]),
806 dict(name="TDS - 194I - Rent - Individual",
807 category_name="Rent",
808 doctype="Tax Withholding Category", accounts=accounts,
809 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
810 "single_threshold": 180000, "cumulative_threshold": 0}]),
811 dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
812 category_name="Rent",
813 doctype="Tax Withholding Category", accounts=accounts,
814 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
815 "single_threshold": 180000, "cumulative_threshold": 0}]),
816 dict(name="TDS - 194I - Rent/Machinery - Company",
817 category_name="Rent-Plant / Machinery",
818 doctype="Tax Withholding Category", accounts=accounts,
819 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
820 "single_threshold": 180000, "cumulative_threshold": 0}]),
821 dict(name="TDS - 194I - Rent/Machinery - Individual",
822 category_name="Rent-Plant / Machinery",
823 doctype="Tax Withholding Category", accounts=accounts,
824 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
825 "single_threshold": 180000, "cumulative_threshold": 0}]),
826 dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
827 category_name="Rent-Plant / Machinery",
828 doctype="Tax Withholding Category", accounts=accounts,
829 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
830 "single_threshold": 180000, "cumulative_threshold": 0}]),
831 dict(name="TDS - 194J - Professional Fees - Company",
832 category_name="Professional Fees",
833 doctype="Tax Withholding Category", accounts=accounts,
834 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
835 "single_threshold": 30000, "cumulative_threshold": 0}]),
836 dict(name="TDS - 194J - Professional Fees - Individual",
837 category_name="Professional Fees",
838 doctype="Tax Withholding Category", accounts=accounts,
839 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
840 "single_threshold": 30000, "cumulative_threshold": 0}]),
841 dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
842 category_name="Professional Fees",
843 doctype="Tax Withholding Category", accounts=accounts,
844 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
845 "single_threshold": 30000, "cumulative_threshold": 0}]),
846 dict(name="TDS - 194J - Director Fees - Company",
847 category_name="Director Fees",
848 doctype="Tax Withholding Category", accounts=accounts,
849 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
850 "single_threshold": 0, "cumulative_threshold": 0}]),
851 dict(name="TDS - 194J - Director Fees - Individual",
852 category_name="Director Fees",
853 doctype="Tax Withholding Category", accounts=accounts,
854 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
855 "single_threshold": 0, "cumulative_threshold": 0}]),
856 dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
857 category_name="Director Fees",
858 doctype="Tax Withholding Category", accounts=accounts,
859 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
860 "single_threshold": 0, "cumulative_threshold": 0}]),
861 dict(name="TDS - 194 - Dividends - Company",
862 category_name="Dividends",
863 doctype="Tax Withholding Category", accounts=accounts,
864 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
865 "single_threshold": 2500, "cumulative_threshold": 0}]),
866 dict(name="TDS - 194 - Dividends - Individual",
867 category_name="Dividends",
868 doctype="Tax Withholding Category", accounts=accounts,
869 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
870 "single_threshold": 2500, "cumulative_threshold": 0}]),
871 dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
872 category_name="Dividends",
873 doctype="Tax Withholding Category", accounts=accounts,
874 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
875 "single_threshold": 2500, "cumulative_threshold": 0}])
Anurag Mishrae1464a72020-08-17 15:03:32 +0530876 ]
877
Anurag Mishra25c35682020-08-18 14:13:54 +0530878def create_gratuity_rule():
Anurag Mishrae1464a72020-08-17 15:03:32 +0530879
880 # Standard Indain Gratuity Rule
Anurag Mishra493eea12020-08-18 15:02:32 +0530881 if not frappe.db.exists("Gratuity Rule", "Indian Standard Gratuity Rule"):
882 rule = frappe.new_doc("Gratuity Rule")
883 rule.name = "Indian Standard Gratuity Rule"
884 rule.calculate_gratuity_amount_based_on = "Current Slab"
885 rule.work_experience_calculation_method = "Round Off Work Experience"
886 rule.minimum_year_for_gratuity = 5
Anurag Mishrae1464a72020-08-17 15:03:32 +0530887
Anurag Mishra493eea12020-08-18 15:02:32 +0530888 fraction = 15/26
889 rule.append("gratuity_rule_slabs", {
890 "from_year": 0,
891 "to_year":0,
892 "fraction_of_applicable_earnings": fraction
893 })
Anurag Mishrae1464a72020-08-17 15:03:32 +0530894
Anurag Mishra493eea12020-08-18 15:02:32 +0530895 rule.flags.ignore_mandatory = True
Sagar Vora4c31fbb2021-04-01 15:32:37 +0530896 rule.save()