blob: a6d723a824ac55fe269c8dbfc174236926471f32 [file] [log] [blame]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5
6import frappe, os, json
Rushabh Mehtaf0569742017-09-13 12:52:30 +05307from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
Nabin Hait49b41e42019-01-24 17:55:44 +05308from frappe.permissions import add_permission, update_permission_property
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05309from erpnext.regional.india import states
Zarrar7f8024c2018-08-01 17:45:05 +053010from erpnext.accounts.utils import get_fiscal_year
11from frappe.utils import today
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012
Rushabh Mehta01659272017-06-27 18:05:17 +053013def setup(company=None, patch=True):
Prateeksha Singhdabf3492018-11-13 15:56:15 +053014 setup_company_independent_fixtures()
Prateeksha Singh39b87652018-11-12 17:19:56 +053015 if not patch:
16 update_address_template()
Prateeksha Singhdabf3492018-11-13 15:56:15 +053017 make_fixtures(company)
Prateeksha Singh39b87652018-11-12 17:19:56 +053018
19# TODO: for all countries
20def setup_company_independent_fixtures():
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053021 make_custom_fields()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053022 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053023 add_custom_roles_for_reports()
Nabin Haitc3144852017-09-28 18:55:40 +053024 frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
Nabin Hait852cb642017-07-05 12:58:19 +053025 add_print_formats()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053026
27def update_address_template():
28 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
29 html = f.read()
30
31 address_template = frappe.db.get_value('Address Template', 'India')
32 if address_template:
33 frappe.db.set_value('Address Template', 'India', 'template', html)
34 else:
35 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053036 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053037 doctype='Address Template',
38 country='India',
39 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053040 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053041
Nabin Hait1a609312017-07-13 12:16:04 +053042def add_hsn_sac_codes():
43 # HSN codes
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053044 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
45 hsn_codes = json.loads(f.read())
46
Nabin Hait1a609312017-07-13 12:16:04 +053047 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053048
Nabin Hait1a609312017-07-13 12:16:04 +053049 # SAC Codes
50 with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
51 sac_codes = json.loads(f.read())
52 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053053
Nabin Hait1a609312017-07-13 12:16:04 +053054def create_hsn_codes(data, code_field):
55 for d in data:
Rushabh Mehtaf702d722017-09-27 15:31:30 +053056 hsn_code = frappe.new_doc('GST HSN Code')
57 hsn_code.description = d["description"]
58 hsn_code.hsn_code = d[code_field]
59 hsn_code.name = d[code_field]
60 try:
Nabin Hait1a609312017-07-13 12:16:04 +053061 hsn_code.db_insert()
Rushabh Mehtaf702d722017-09-27 15:31:30 +053062 except frappe.DuplicateEntryError:
63 pass
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053064
Rushabh Mehta919a74a2017-06-22 16:37:04 +053065def add_custom_roles_for_reports():
66 for report_name in ('GST Sales Register', 'GST Purchase Register',
rohitwaghchaure8cca61f2018-08-20 17:53:56 +053067 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'):
Rushabh Mehta919a74a2017-06-22 16:37:04 +053068
Rushabh Mehta919a74a2017-06-22 16:37:04 +053069 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
70 frappe.get_doc(dict(
71 doctype='Custom Role',
72 report=report_name,
73 roles= [
74 dict(role='Accounts User'),
75 dict(role='Accounts Manager')
76 ]
77 )).insert()
78
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053079def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053080 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053081 add_permission(doctype, 'All', 0)
Nabin Hait49b41e42019-01-24 17:55:44 +053082 add_permission(doctype, 'Accounts Manager', 0)
83 update_permission_property(doctype, 'Accounts Manager', 0, 'write', 1)
84 update_permission_property(doctype, 'Accounts Manager', 0, 'create', 1)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053085
Nabin Hait852cb642017-07-05 12:58:19 +053086def add_print_formats():
87 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +053088 frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
89
90 frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
91 name in('GST POS Invoice', 'GST Tax Invoice') """)
Nabin Hait852cb642017-07-05 12:58:19 +053092
Rushabh Mehta69fa8082018-07-17 18:22:51 +053093def make_custom_fields(update=True):
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053094 hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
Nabin Haitd34bfa82018-11-13 18:19:58 +053095 fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description',
Nabin Haite5716e32017-09-11 19:21:37 +053096 allow_on_submit=1, print_hide=1)
Nabin Hait879e1622017-08-21 08:28:55 +053097 invoice_gst_fields = [
98 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
vishdha109b4082018-01-30 12:11:13 +053099 insert_after='language', print_hide=1, collapsible=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530100 dict(fieldname='invoice_copy', label='Invoice Copy',
101 fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
102 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
103 dict(fieldname='reverse_charge', label='Reverse Charge',
104 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
105 options='Y\nN', default='N'),
Nabin Hait879e1622017-08-21 08:28:55 +0530106 dict(fieldname='invoice_type', label='Invoice Type',
Nabin Haite6d65bc2018-02-14 17:44:06 +0530107 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
Nabin Hait879e1622017-08-21 08:28:55 +0530108 options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
109 dict(fieldname='export_type', label='Export Type',
110 fieldtype='Select', insert_after='invoice_type', print_hide=1,
111 depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
112 options='\nWith Payment of Tax\nWithout Payment of Tax'),
113 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530114 fieldtype='Data', insert_after='export_type', print_hide=1),
Nabin Haite6d65bc2018-02-14 17:44:06 +0530115 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530116 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
Nabin Haitb02c1092018-02-05 16:09:51 +0530117 fieldtype='Select', insert_after='gst_col_break', print_hide=1,
Nabin Haite6d65bc2018-02-14 17:44:06 +0530118 depends_on='eval:doc.is_return==1',
Nabin Haita8d10b72018-02-12 16:54:13 +0530119 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 +0530120 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530121
Nabin Hait879e1622017-08-21 08:28:55 +0530122 purchase_invoice_gst_fields = [
123 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
124 fieldtype='Data', insert_after='supplier_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530125 fetch_from='supplier_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530126 dict(fieldname='company_gstin', label='Company GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530127 fieldtype='Data', insert_after='shipping_address_display',
128 fetch_from='shipping_address.gstin', print_hide=1),
Nabin Haitb02c1092018-02-05 16:09:51 +0530129 dict(fieldname='place_of_supply', label='Place of Supply',
130 fieldtype='Data', insert_after='shipping_address',
131 print_hide=1, read_only=0),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530132 ]
133
134 purchase_invoice_itc_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530135 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
136 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
137 options='input\ninput service\ncapital goods\nineligible', default="ineligible"),
138 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
139 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
140 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
141 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
142 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
143 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
144 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
145 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530146 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530147
Nabin Hait879e1622017-08-21 08:28:55 +0530148 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530149 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
150 fieldtype='Data', insert_after='customer_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530151 fetch_from='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530152 dict(fieldname='customer_gstin', label='Customer GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530153 fieldtype='Data', insert_after='shipping_address_name',
154 fetch_from='shipping_address_name.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530155 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530156 fieldtype='Data', insert_after='customer_gstin',
157 print_hide=1, read_only=0),
Nabin Hait879e1622017-08-21 08:28:55 +0530158 dict(fieldname='company_gstin', label='Company GSTIN',
159 fieldtype='Data', insert_after='company_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530160 fetch_from='company_address.gstin', print_hide=1),
deepeshgarg007d29ee972019-01-09 17:09:11 +0530161 ]
162
163 sales_invoice_shipping_fields = [
vishdha98e33c32018-01-29 13:57:34 +0530164 dict(fieldname='port_code', label='Port Code',
165 fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
166 depends_on="eval:doc.invoice_type=='Export' "),
167 dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
168 fieldtype='Data', insert_after='port_code', print_hide=1,
169 depends_on="eval:doc.invoice_type=='Export' "),
170 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
171 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
172 depends_on="eval:doc.invoice_type=='Export' ")
Nabin Hait879e1622017-08-21 08:28:55 +0530173 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530174
Shreya Shah4fa600a2018-06-05 11:27:53 +0530175 inter_state_gst_field = [
176 dict(fieldname='is_inter_state', label='Is Inter State',
177 fieldtype='Check', insert_after='disabled', print_hide=1)
178 ]
179
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530180 ewaybill_fields = [
181 {
182 'fieldname': 'distance',
183 'label': 'Distance (in km)',
184 'fieldtype': 'Float',
185 'insert_after': 'vehicle_no',
186 'print_hide': 1
187 },
188 {
189 'fieldname': 'gst_transporter_id',
190 'label': 'GST Transporter ID',
191 'fieldtype': 'Data',
192 'insert_after': 'transporter_name',
193 'fetch_from': 'transporter.gst_transporter_id',
194 'print_hide': 1
195 },
196 {
197 'fieldname': 'mode_of_transport',
198 'label': 'Mode of Transport',
199 'fieldtype': 'Select',
200 'options': '\nRoad\nAir\nRail\nShip',
201 'default': 'Road',
202 'insert_after': 'lr_date',
203 'print_hide': 1
204 },
205 {
206 'fieldname': 'gst_vehicle_type',
207 'label': 'GST Vehicle Type',
208 'fieldtype': 'Select',
209 'options': '\nRegular\nOver Dimensional Cargo (ODC)',
210 'default': 'Regular',
211 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
212 'insert_after': 'mode_of_transport',
213 'print_hide': 1
214 }
215 ]
216
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530217 custom_fields = {
218 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530219 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
220 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530221 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530222 options='\n'.join(states), insert_after='gstin'),
223 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait562d9422018-09-07 16:14:44 +0530224 fieldtype='Data', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530225 ],
deepeshgarg007d29ee972019-01-09 17:09:11 +0530226 'Purchase Invoice': invoice_gst_fields + purchase_invoice_gst_fields + purchase_invoice_itc_fields,
227 'Purchase Order': purchase_invoice_gst_fields,
228 'Purchase Receipt': purchase_invoice_gst_fields,
229 'Sales Invoice': invoice_gst_fields + sales_invoice_gst_fields + sales_invoice_shipping_fields,
230 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields,
231 'Sales Order': sales_invoice_gst_fields,
Shreya Shah4fa600a2018-06-05 11:27:53 +0530232 'Sales Taxes and Charges Template': inter_state_gst_field,
233 'Purchase Taxes and Charges Template': inter_state_gst_field,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530234 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530235 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530236 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
237 ],
Nabin Hait9c421612017-07-20 13:32:01 +0530238 'Quotation Item': [hsn_sac_field],
239 'Supplier Quotation Item': [hsn_sac_field],
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530240 'Sales Order Item': [hsn_sac_field],
241 'Delivery Note Item': [hsn_sac_field],
242 'Sales Invoice Item': [hsn_sac_field],
243 'Purchase Order Item': [hsn_sac_field],
244 'Purchase Receipt Item': [hsn_sac_field],
Pawan Mehtaf4196352018-04-05 14:54:51 +0530245 'Purchase Invoice Item': [hsn_sac_field],
246 'Employee': [
247 dict(fieldname='ifsc_code', label='IFSC Code',
Rushabh Mehta369afce2018-04-26 10:10:03 +0530248 fieldtype='Data', insert_after='bank_ac_no', print_hide=1,
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530249 depends_on='eval:doc.salary_mode == "Bank"')
250 ],
251 'Company': [
252 dict(fieldname='hra_section', label='HRA Settings',
253 fieldtype='Section Break', insert_after='asset_received_but_not_billed'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530254 dict(fieldname='basic_component', label='Basic Component',
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530255 fieldtype='Link', options='Salary Component', insert_after='hra_section'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530256 dict(fieldname='hra_component', label='HRA Component',
257 fieldtype='Link', options='Salary Component', insert_after='basic_component'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530258 dict(fieldname='arrear_component', label='Arrear Component',
259 fieldtype='Link', options='Salary Component', insert_after='hra_component')
260 ],
261 'Employee Tax Exemption Declaration':[
262 dict(fieldname='hra_section', label='HRA Exemption',
263 fieldtype='Section Break', insert_after='declarations'),
264 dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure',
265 fieldtype='Currency', insert_after='hra_section', read_only=1),
266 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
267 fieldtype='Currency', insert_after='salary_structure_hra'),
268 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
269 fieldtype='Check', insert_after='monthly_house_rent'),
270 dict(fieldname='hra_column_break', fieldtype='Column Break',
271 insert_after='rented_in_metro_city'),
272 dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption',
273 fieldtype='Currency', insert_after='hra_column_break', read_only=1),
274 dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption',
275 fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1)
276 ],
277 'Employee Tax Exemption Proof Submission': [
278 dict(fieldname='hra_section', label='HRA Exemption',
279 fieldtype='Section Break', insert_after='tax_exemption_proofs'),
280 dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount',
281 fieldtype='Currency', insert_after='hra_section'),
282 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
283 fieldtype='Check', insert_after='house_rent_payment_amount'),
284 dict(fieldname='rented_from_date', label='Rented From Date',
285 fieldtype='Date', insert_after='rented_in_metro_city'),
286 dict(fieldname='rented_to_date', label='Rented To Date',
287 fieldtype='Date', insert_after='rented_from_date'),
288 dict(fieldname='hra_column_break', fieldtype='Column Break',
289 insert_after='rented_to_date'),
290 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
291 fieldtype='Currency', insert_after='hra_column_break', read_only=1),
292 dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount',
293 fieldtype='Currency', insert_after='monthly_house_rent', read_only=1),
294 dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption',
295 fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1)
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530296 ],
297 'Supplier': [
298 {
299 'fieldname': 'gst_transporter_id',
300 'label': 'GST Transporter ID',
301 'fieldtype': 'Data',
302 'insert_after': 'supplier_type',
303 'depends_on': 'eval:doc.is_transporter'
304 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530305 ]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530306 }
307
Rushabh Mehta69fa8082018-07-17 18:22:51 +0530308 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Nabin Hait9c421612017-07-20 13:32:01 +0530309
Saurabh2d8a7ee2018-05-11 13:16:16 +0530310def make_fixtures(company=None):
311 docs = []
312 company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
313
314 set_salary_components(docs)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530315 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530316
317 for d in docs:
318 try:
319 doc = frappe.get_doc(d)
320 doc.flags.ignore_permissions = True
321 doc.insert()
322 except frappe.NameError:
323 pass
Zarrar7f8024c2018-08-01 17:45:05 +0530324 except frappe.DuplicateEntryError:
325 pass
Saurabh2d8a7ee2018-05-11 13:16:16 +0530326
Zarrar7f8024c2018-08-01 17:45:05 +0530327 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530328 set_tax_withholding_category(company)
329
Saurabh2d8a7ee2018-05-11 13:16:16 +0530330def set_salary_components(docs):
331 docs.extend([
332 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
333 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
334 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
335 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
336 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
337 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
338 ])
339
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530340def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +0530341 accounts = []
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530342 abbr = frappe.get_value("Company", company, "abbr")
343 tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
Saurabh2d8a7ee2018-05-11 13:16:16 +0530344
345 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530346 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +0530347
Zarrar7f8024c2018-08-01 17:45:05 +0530348 fiscal_year = get_fiscal_year(today(), company=accounts[0].get('company'))[0]
349 docs = get_tds_details(accounts, fiscal_year)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530350
Zarrar7f8024c2018-08-01 17:45:05 +0530351 for d in docs:
352 try:
353 doc = frappe.get_doc(d)
354 doc.flags.ignore_permissions = True
355 doc.insert()
356 except frappe.DuplicateEntryError:
357 doc = frappe.get_doc("Tax Withholding Category", d.get("name"))
358 doc.append("accounts", accounts[0])
359
360 # if fiscal year don't match with any of the already entered data, append rate row
361 fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
362 if not fy_exist:
363 doc.append("rates", d.get('rates')[0])
364
365 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530366
367def set_tds_account(docs, company):
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530368 abbr = frappe.get_value("Company", company, "abbr")
Nabin Haitf77cd542018-11-20 16:46:25 +0530369 parent_account = frappe.db.get_value("Account", filters = {"account_name": "Duties and Taxes", "company": company})
370 if parent_account:
371 docs.extend([
372 {
373 "doctype": "Account",
374 "account_name": "TDS Payable",
375 "account_type": "Tax",
376 "parent_account": parent_account,
377 "company": company
378 }
379 ])
Zarrar7f8024c2018-08-01 17:45:05 +0530380
381def get_tds_details(accounts, fiscal_year):
382 # bootstrap default tax withholding sections
383 return [
384 dict(name="TDS - 194C - Company",
385 category_name="Payment to Contractors (Single / Aggregate)",
386 doctype="Tax Withholding Category", accounts=accounts,
387 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
388 "single_threshold": 30000, "cumulative_threshold": 100000}]),
389 dict(name="TDS - 194C - Individual",
390 category_name="Payment to Contractors (Single / Aggregate)",
391 doctype="Tax Withholding Category", accounts=accounts,
392 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
393 "single_threshold": 30000, "cumulative_threshold": 100000}]),
394 dict(name="TDS - 194C - No PAN / Invalid PAN",
395 category_name="Payment to Contractors (Single / Aggregate)",
396 doctype="Tax Withholding Category", accounts=accounts,
397 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
398 "single_threshold": 30000, "cumulative_threshold": 100000}]),
399 dict(name="TDS - 194D - Company",
400 category_name="Insurance Commission",
401 doctype="Tax Withholding Category", accounts=accounts,
402 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
403 "single_threshold": 15000, "cumulative_threshold": 0}]),
404 dict(name="TDS - 194D - Company Assessee",
405 category_name="Insurance Commission",
406 doctype="Tax Withholding Category", accounts=accounts,
407 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
408 "single_threshold": 15000, "cumulative_threshold": 0}]),
409 dict(name="TDS - 194D - Individual",
410 category_name="Insurance Commission",
411 doctype="Tax Withholding Category", accounts=accounts,
412 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
413 "single_threshold": 15000, "cumulative_threshold": 0}]),
414 dict(name="TDS - 194D - No PAN / Invalid PAN",
415 category_name="Insurance Commission",
416 doctype="Tax Withholding Category", accounts=accounts,
417 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
418 "single_threshold": 15000, "cumulative_threshold": 0}]),
419 dict(name="TDS - 194DA - Company",
420 category_name="Non-exempt payments made under a life insurance policy",
421 doctype="Tax Withholding Category", accounts=accounts,
422 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
423 "single_threshold": 100000, "cumulative_threshold": 0}]),
424 dict(name="TDS - 194DA - Individual",
425 category_name="Non-exempt payments made under a life insurance policy",
426 doctype="Tax Withholding Category", accounts=accounts,
427 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
428 "single_threshold": 100000, "cumulative_threshold": 0}]),
429 dict(name="TDS - 194DA - No PAN / Invalid PAN",
430 category_name="Non-exempt payments made under a life insurance policy",
431 doctype="Tax Withholding Category", accounts=accounts,
432 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
433 "single_threshold": 100000, "cumulative_threshold": 0}]),
434 dict(name="TDS - 194H - Company",
435 category_name="Commission / Brokerage",
436 doctype="Tax Withholding Category", accounts=accounts,
437 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
438 "single_threshold": 15000, "cumulative_threshold": 0}]),
439 dict(name="TDS - 194H - Individual",
440 category_name="Commission / Brokerage",
441 doctype="Tax Withholding Category", accounts=accounts,
442 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
443 "single_threshold": 15000, "cumulative_threshold": 0}]),
444 dict(name="TDS - 194H - No PAN / Invalid PAN",
445 category_name="Commission / Brokerage",
446 doctype="Tax Withholding Category", accounts=accounts,
447 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
448 "single_threshold": 15000, "cumulative_threshold": 0}]),
449 dict(name="TDS - 194I - Rent - Company",
450 category_name="Rent",
451 doctype="Tax Withholding Category", accounts=accounts,
452 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
453 "single_threshold": 180000, "cumulative_threshold": 0}]),
454 dict(name="TDS - 194I - Rent - Individual",
455 category_name="Rent",
456 doctype="Tax Withholding Category", accounts=accounts,
457 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
458 "single_threshold": 180000, "cumulative_threshold": 0}]),
459 dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
460 category_name="Rent",
461 doctype="Tax Withholding Category", accounts=accounts,
462 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
463 "single_threshold": 180000, "cumulative_threshold": 0}]),
464 dict(name="TDS - 194I - Rent/Machinery - Company",
465 category_name="Rent-Plant / Machinery",
466 doctype="Tax Withholding Category", accounts=accounts,
467 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
468 "single_threshold": 180000, "cumulative_threshold": 0}]),
469 dict(name="TDS - 194I - Rent/Machinery - Individual",
470 category_name="Rent-Plant / Machinery",
471 doctype="Tax Withholding Category", accounts=accounts,
472 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
473 "single_threshold": 180000, "cumulative_threshold": 0}]),
474 dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
475 category_name="Rent-Plant / Machinery",
476 doctype="Tax Withholding Category", accounts=accounts,
477 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
478 "single_threshold": 180000, "cumulative_threshold": 0}]),
479 dict(name="TDS - 194J - Professional Fees - Company",
480 category_name="Professional Fees",
481 doctype="Tax Withholding Category", accounts=accounts,
482 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
483 "single_threshold": 30000, "cumulative_threshold": 0}]),
484 dict(name="TDS - 194J - Professional Fees - Individual",
485 category_name="Professional Fees",
486 doctype="Tax Withholding Category", accounts=accounts,
487 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
488 "single_threshold": 30000, "cumulative_threshold": 0}]),
489 dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
490 category_name="Professional Fees",
491 doctype="Tax Withholding Category", accounts=accounts,
492 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
493 "single_threshold": 30000, "cumulative_threshold": 0}]),
494 dict(name="TDS - 194J - Director Fees - Company",
495 category_name="Director Fees",
496 doctype="Tax Withholding Category", accounts=accounts,
497 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
498 "single_threshold": 0, "cumulative_threshold": 0}]),
499 dict(name="TDS - 194J - Director Fees - Individual",
500 category_name="Director Fees",
501 doctype="Tax Withholding Category", accounts=accounts,
502 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
503 "single_threshold": 0, "cumulative_threshold": 0}]),
504 dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
505 category_name="Director Fees",
506 doctype="Tax Withholding Category", accounts=accounts,
507 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
508 "single_threshold": 0, "cumulative_threshold": 0}]),
509 dict(name="TDS - 194 - Dividends - Company",
510 category_name="Dividends",
511 doctype="Tax Withholding Category", accounts=accounts,
512 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
513 "single_threshold": 2500, "cumulative_threshold": 0}]),
514 dict(name="TDS - 194 - Dividends - Individual",
515 category_name="Dividends",
516 doctype="Tax Withholding Category", accounts=accounts,
517 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
518 "single_threshold": 2500, "cumulative_threshold": 0}]),
519 dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
520 category_name="Dividends",
521 doctype="Tax Withholding Category", accounts=accounts,
522 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
523 "single_threshold": 2500, "cumulative_threshold": 0}])
524 ]