blob: c7541212990065cb2dce3672bbe36cfb1c5f6cb1 [file] [log] [blame]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5
6import frappe, os, json
Rushabh Mehtaf0569742017-09-13 12:52:30 +05307from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05308from frappe.permissions import add_permission
9from erpnext.regional.india import states
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):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053014 make_custom_fields()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053015 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053016 add_custom_roles_for_reports()
Nabin Haitc3144852017-09-28 18:55:40 +053017 frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test)
Nabin Hait852cb642017-07-05 12:58:19 +053018 add_print_formats()
Rushabh Mehta01659272017-06-27 18:05:17 +053019 if not patch:
Nabin Hait1a609312017-07-13 12:16:04 +053020 update_address_template()
Saurabh2d8a7ee2018-05-11 13:16:16 +053021 make_fixtures(company)
Rushabh Mehta919a74a2017-06-22 16:37:04 +053022
23def update_address_template():
24 with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f:
25 html = f.read()
26
27 address_template = frappe.db.get_value('Address Template', 'India')
28 if address_template:
29 frappe.db.set_value('Address Template', 'India', 'template', html)
30 else:
31 # make new html template for India
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053032 frappe.get_doc(dict(
Rushabh Mehta919a74a2017-06-22 16:37:04 +053033 doctype='Address Template',
34 country='India',
35 template=html
Rushabh Mehta9b09ff22017-06-27 12:17:39 +053036 )).insert()
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053037
Nabin Hait1a609312017-07-13 12:16:04 +053038def add_hsn_sac_codes():
39 # HSN codes
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053040 with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f:
41 hsn_codes = json.loads(f.read())
42
Nabin Hait1a609312017-07-13 12:16:04 +053043 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053044
Nabin Hait1a609312017-07-13 12:16:04 +053045 # SAC Codes
46 with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f:
47 sac_codes = json.loads(f.read())
48 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053049
Nabin Hait1a609312017-07-13 12:16:04 +053050def create_hsn_codes(data, code_field):
51 for d in data:
Rushabh Mehtaf702d722017-09-27 15:31:30 +053052 hsn_code = frappe.new_doc('GST HSN Code')
53 hsn_code.description = d["description"]
54 hsn_code.hsn_code = d[code_field]
55 hsn_code.name = d[code_field]
56 try:
Nabin Hait1a609312017-07-13 12:16:04 +053057 hsn_code.db_insert()
Rushabh Mehtaf702d722017-09-27 15:31:30 +053058 except frappe.DuplicateEntryError:
59 pass
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053060
Rushabh Mehta919a74a2017-06-22 16:37:04 +053061def add_custom_roles_for_reports():
62 for report_name in ('GST Sales Register', 'GST Purchase Register',
rohitwaghchaure8cca61f2018-08-20 17:53:56 +053063 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'):
Rushabh Mehta919a74a2017-06-22 16:37:04 +053064
Rushabh Mehta919a74a2017-06-22 16:37:04 +053065 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
66 frappe.get_doc(dict(
67 doctype='Custom Role',
68 report=report_name,
69 roles= [
70 dict(role='Accounts User'),
71 dict(role='Accounts Manager')
72 ]
73 )).insert()
74
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053075def add_permissions():
Rushabh Mehta00ae4242017-06-27 17:31:41 +053076 for doctype in ('GST HSN Code', 'GST Settings'):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053077 add_permission(doctype, 'All', 0)
78
Nabin Hait852cb642017-07-05 12:58:19 +053079def add_print_formats():
80 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +053081 frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
82
83 frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
84 name in('GST POS Invoice', 'GST Tax Invoice') """)
Nabin Hait852cb642017-07-05 12:58:19 +053085
Rushabh Mehta69fa8082018-07-17 18:22:51 +053086def make_custom_fields(update=True):
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053087 hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
Nabin Haite5716e32017-09-11 19:21:37 +053088 fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description',
89 allow_on_submit=1, print_hide=1)
Nabin Hait879e1622017-08-21 08:28:55 +053090 invoice_gst_fields = [
91 dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
vishdha109b4082018-01-30 12:11:13 +053092 insert_after='language', print_hide=1, collapsible=1),
Nabin Hait879e1622017-08-21 08:28:55 +053093 dict(fieldname='invoice_copy', label='Invoice Copy',
94 fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
95 options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
96 dict(fieldname='reverse_charge', label='Reverse Charge',
97 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
98 options='Y\nN', default='N'),
Nabin Hait879e1622017-08-21 08:28:55 +053099 dict(fieldname='invoice_type', label='Invoice Type',
Nabin Haite6d65bc2018-02-14 17:44:06 +0530100 fieldtype='Select', insert_after='invoice_copy', print_hide=1,
Nabin Hait879e1622017-08-21 08:28:55 +0530101 options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
102 dict(fieldname='export_type', label='Export Type',
103 fieldtype='Select', insert_after='invoice_type', print_hide=1,
104 depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
105 options='\nWith Payment of Tax\nWithout Payment of Tax'),
106 dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530107 fieldtype='Data', insert_after='export_type', print_hide=1),
Nabin Haite6d65bc2018-02-14 17:44:06 +0530108 dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'),
Vishal Dhayagudec463c062018-01-26 11:27:22 +0530109 dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document',
Nabin Haitb02c1092018-02-05 16:09:51 +0530110 fieldtype='Select', insert_after='gst_col_break', print_hide=1,
Nabin Haite6d65bc2018-02-14 17:44:06 +0530111 depends_on='eval:doc.is_return==1',
Nabin Haita8d10b72018-02-12 16:54:13 +0530112 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 +0530113 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530114
Nabin Hait879e1622017-08-21 08:28:55 +0530115 purchase_invoice_gst_fields = [
116 dict(fieldname='supplier_gstin', label='Supplier GSTIN',
117 fieldtype='Data', insert_after='supplier_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530118 fetch_from='supplier_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530119 dict(fieldname='company_gstin', label='Company GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530120 fieldtype='Data', insert_after='shipping_address_display',
121 fetch_from='shipping_address.gstin', print_hide=1),
Nabin Haitb02c1092018-02-05 16:09:51 +0530122 dict(fieldname='place_of_supply', label='Place of Supply',
123 fieldtype='Data', insert_after='shipping_address',
124 print_hide=1, read_only=0),
vishdha98e33c32018-01-29 13:57:34 +0530125 dict(fieldname='eligibility_for_itc', label='Eligibility For ITC',
126 fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1,
127 options='input\ninput service\ncapital goods\nineligible', default="ineligible"),
128 dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax',
129 fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1),
130 dict(fieldname='itc_central_tax', label='Availed ITC Central Tax',
131 fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1),
132 dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax',
133 fieldtype='Data', insert_after='itc_central_tax', print_hide=1),
134 dict(fieldname='itc_cess_amount', label='Availed ITC Cess',
135 fieldtype='Data', insert_after='itc_state_tax', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530136 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530137
Nabin Hait879e1622017-08-21 08:28:55 +0530138 sales_invoice_gst_fields = [
rohitwaghchaure16645802017-09-28 11:05:03 +0530139 dict(fieldname='billing_address_gstin', label='Billing Address GSTIN',
140 fieldtype='Data', insert_after='customer_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530141 fetch_from='customer_address.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530142 dict(fieldname='customer_gstin', label='Customer GSTIN',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530143 fieldtype='Data', insert_after='shipping_address_name',
144 fetch_from='shipping_address_name.gstin', print_hide=1),
Nabin Hait879e1622017-08-21 08:28:55 +0530145 dict(fieldname='place_of_supply', label='Place of Supply',
Nabin Hait619c42b2018-01-10 17:48:03 +0530146 fieldtype='Data', insert_after='customer_gstin',
147 print_hide=1, read_only=0),
Nabin Hait879e1622017-08-21 08:28:55 +0530148 dict(fieldname='company_gstin', label='Company GSTIN',
149 fieldtype='Data', insert_after='company_address',
Shreya Shah4fa600a2018-06-05 11:27:53 +0530150 fetch_from='company_address.gstin', print_hide=1),
vishdha98e33c32018-01-29 13:57:34 +0530151 dict(fieldname='port_code', label='Port Code',
152 fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1,
153 depends_on="eval:doc.invoice_type=='Export' "),
154 dict(fieldname='shipping_bill_number', label=' Shipping Bill Number',
155 fieldtype='Data', insert_after='port_code', print_hide=1,
156 depends_on="eval:doc.invoice_type=='Export' "),
157 dict(fieldname='shipping_bill_date', label='Shipping Bill Date',
158 fieldtype='Date', insert_after='shipping_bill_number', print_hide=1,
159 depends_on="eval:doc.invoice_type=='Export' ")
Nabin Hait879e1622017-08-21 08:28:55 +0530160 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530161
Shreya Shah4fa600a2018-06-05 11:27:53 +0530162 inter_state_gst_field = [
163 dict(fieldname='is_inter_state', label='Is Inter State',
164 fieldtype='Check', insert_after='disabled', print_hide=1)
165 ]
166
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530167 ewaybill_fields = [
168 {
169 'fieldname': 'distance',
170 'label': 'Distance (in km)',
171 'fieldtype': 'Float',
172 'insert_after': 'vehicle_no',
173 'print_hide': 1
174 },
175 {
176 'fieldname': 'gst_transporter_id',
177 'label': 'GST Transporter ID',
178 'fieldtype': 'Data',
179 'insert_after': 'transporter_name',
180 'fetch_from': 'transporter.gst_transporter_id',
181 'print_hide': 1
182 },
183 {
184 'fieldname': 'mode_of_transport',
185 'label': 'Mode of Transport',
186 'fieldtype': 'Select',
187 'options': '\nRoad\nAir\nRail\nShip',
188 'default': 'Road',
189 'insert_after': 'lr_date',
190 'print_hide': 1
191 },
192 {
193 'fieldname': 'gst_vehicle_type',
194 'label': 'GST Vehicle Type',
195 'fieldtype': 'Select',
196 'options': '\nRegular\nOver Dimensional Cargo (ODC)',
197 'default': 'Regular',
198 'depends_on': 'eval:(doc.mode_of_transport === "Road")',
199 'insert_after': 'mode_of_transport',
200 'print_hide': 1
201 }
202 ]
203
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530204 custom_fields = {
205 'Address': [
Rushabh Mehta919a74a2017-06-22 16:37:04 +0530206 dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data',
207 insert_after='fax'),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530208 dict(fieldname='gst_state', label='GST State', fieldtype='Select',
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530209 options='\n'.join(states), insert_after='gstin'),
210 dict(fieldname='gst_state_number', label='GST State Number',
Nabin Hait562d9422018-09-07 16:14:44 +0530211 fieldtype='Data', insert_after='gst_state', read_only=1),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530212 ],
Nabin Haitb02c1092018-02-05 16:09:51 +0530213 'Purchase Invoice': invoice_gst_fields + purchase_invoice_gst_fields,
214 'Sales Invoice': invoice_gst_fields + sales_invoice_gst_fields,
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530215 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields,
Shreya Shah4fa600a2018-06-05 11:27:53 +0530216 'Sales Taxes and Charges Template': inter_state_gst_field,
217 'Purchase Taxes and Charges Template': inter_state_gst_field,
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530218 'Item': [
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530219 dict(fieldname='gst_hsn_code', label='HSN/SAC',
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530220 fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
221 ],
Nabin Hait9c421612017-07-20 13:32:01 +0530222 'Quotation Item': [hsn_sac_field],
223 'Supplier Quotation Item': [hsn_sac_field],
Nabin Haitf3f0dfe2017-07-06 14:49:34 +0530224 'Sales Order Item': [hsn_sac_field],
225 'Delivery Note Item': [hsn_sac_field],
226 'Sales Invoice Item': [hsn_sac_field],
227 'Purchase Order Item': [hsn_sac_field],
228 'Purchase Receipt Item': [hsn_sac_field],
Pawan Mehtaf4196352018-04-05 14:54:51 +0530229 'Purchase Invoice Item': [hsn_sac_field],
230 'Employee': [
231 dict(fieldname='ifsc_code', label='IFSC Code',
Rushabh Mehta369afce2018-04-26 10:10:03 +0530232 fieldtype='Data', insert_after='bank_ac_no', print_hide=1,
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530233 depends_on='eval:doc.salary_mode == "Bank"')
234 ],
235 'Company': [
236 dict(fieldname='hra_section', label='HRA Settings',
237 fieldtype='Section Break', insert_after='asset_received_but_not_billed'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530238 dict(fieldname='basic_component', label='Basic Component',
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530239 fieldtype='Link', options='Salary Component', insert_after='hra_section'),
Ranjith Kurungadamb1a756c2018-07-01 16:42:38 +0530240 dict(fieldname='hra_component', label='HRA Component',
241 fieldtype='Link', options='Salary Component', insert_after='basic_component'),
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530242 dict(fieldname='arrear_component', label='Arrear Component',
243 fieldtype='Link', options='Salary Component', insert_after='hra_component')
244 ],
245 'Employee Tax Exemption Declaration':[
246 dict(fieldname='hra_section', label='HRA Exemption',
247 fieldtype='Section Break', insert_after='declarations'),
248 dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure',
249 fieldtype='Currency', insert_after='hra_section', read_only=1),
250 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
251 fieldtype='Currency', insert_after='salary_structure_hra'),
252 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
253 fieldtype='Check', insert_after='monthly_house_rent'),
254 dict(fieldname='hra_column_break', fieldtype='Column Break',
255 insert_after='rented_in_metro_city'),
256 dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption',
257 fieldtype='Currency', insert_after='hra_column_break', read_only=1),
258 dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption',
259 fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1)
260 ],
261 'Employee Tax Exemption Proof Submission': [
262 dict(fieldname='hra_section', label='HRA Exemption',
263 fieldtype='Section Break', insert_after='tax_exemption_proofs'),
264 dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount',
265 fieldtype='Currency', insert_after='hra_section'),
266 dict(fieldname='rented_in_metro_city', label='Rented in Metro City',
267 fieldtype='Check', insert_after='house_rent_payment_amount'),
268 dict(fieldname='rented_from_date', label='Rented From Date',
269 fieldtype='Date', insert_after='rented_in_metro_city'),
270 dict(fieldname='rented_to_date', label='Rented To Date',
271 fieldtype='Date', insert_after='rented_from_date'),
272 dict(fieldname='hra_column_break', fieldtype='Column Break',
273 insert_after='rented_to_date'),
274 dict(fieldname='monthly_house_rent', label='Monthly House Rent',
275 fieldtype='Currency', insert_after='hra_column_break', read_only=1),
276 dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount',
277 fieldtype='Currency', insert_after='monthly_house_rent', read_only=1),
278 dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption',
279 fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1)
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530280 ],
281 'Supplier': [
282 {
283 'fieldname': 'gst_transporter_id',
284 'label': 'GST Transporter ID',
285 'fieldtype': 'Data',
286 'insert_after': 'supplier_type',
287 'depends_on': 'eval:doc.is_transporter'
288 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530289 ]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530290 }
291
Rushabh Mehta69fa8082018-07-17 18:22:51 +0530292 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Nabin Hait9c421612017-07-20 13:32:01 +0530293
Saurabh2d8a7ee2018-05-11 13:16:16 +0530294def make_fixtures(company=None):
295 docs = []
296 company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
297
298 set_salary_components(docs)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530299 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530300
301 for d in docs:
302 try:
303 doc = frappe.get_doc(d)
304 doc.flags.ignore_permissions = True
305 doc.insert()
306 except frappe.NameError:
307 pass
Zarrar7f8024c2018-08-01 17:45:05 +0530308 except frappe.DuplicateEntryError:
309 pass
Saurabh2d8a7ee2018-05-11 13:16:16 +0530310
Zarrar7f8024c2018-08-01 17:45:05 +0530311 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530312 set_tax_withholding_category(company)
313
Saurabh2d8a7ee2018-05-11 13:16:16 +0530314def set_salary_components(docs):
315 docs.extend([
316 {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
317 {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'},
318 {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'},
319 {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'},
320 {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'},
321 {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
322 ])
323
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530324def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +0530325 accounts = []
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530326 abbr = frappe.get_value("Company", company, "abbr")
327 tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
Saurabh2d8a7ee2018-05-11 13:16:16 +0530328
329 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530330 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +0530331
Zarrar7f8024c2018-08-01 17:45:05 +0530332 fiscal_year = get_fiscal_year(today(), company=accounts[0].get('company'))[0]
333 docs = get_tds_details(accounts, fiscal_year)
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530334
Zarrar7f8024c2018-08-01 17:45:05 +0530335 for d in docs:
336 try:
337 doc = frappe.get_doc(d)
338 doc.flags.ignore_permissions = True
339 doc.insert()
340 except frappe.DuplicateEntryError:
341 doc = frappe.get_doc("Tax Withholding Category", d.get("name"))
342 doc.append("accounts", accounts[0])
343
344 # if fiscal year don't match with any of the already entered data, append rate row
345 fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
346 if not fy_exist:
347 doc.append("rates", d.get('rates')[0])
348
349 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +0530350
351def set_tds_account(docs, company):
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530352 abbr = frappe.get_value("Company", company, "abbr")
Saurabh2d8a7ee2018-05-11 13:16:16 +0530353 docs.extend([
354 {
Ranjith Kurungadame51c1752018-07-24 11:07:28 +0530355 "doctype": "Account", "account_name": "TDS Payable", "account_type": "Tax",
356 "parent_account": "Duties and Taxes - {0}".format(abbr), "company": company
Saurabh2d8a7ee2018-05-11 13:16:16 +0530357 }
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530358 ])
Zarrar7f8024c2018-08-01 17:45:05 +0530359
360def get_tds_details(accounts, fiscal_year):
361 # bootstrap default tax withholding sections
362 return [
363 dict(name="TDS - 194C - Company",
364 category_name="Payment to Contractors (Single / Aggregate)",
365 doctype="Tax Withholding Category", accounts=accounts,
366 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
367 "single_threshold": 30000, "cumulative_threshold": 100000}]),
368 dict(name="TDS - 194C - Individual",
369 category_name="Payment to Contractors (Single / Aggregate)",
370 doctype="Tax Withholding Category", accounts=accounts,
371 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
372 "single_threshold": 30000, "cumulative_threshold": 100000}]),
373 dict(name="TDS - 194C - No PAN / Invalid PAN",
374 category_name="Payment to Contractors (Single / Aggregate)",
375 doctype="Tax Withholding Category", accounts=accounts,
376 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
377 "single_threshold": 30000, "cumulative_threshold": 100000}]),
378 dict(name="TDS - 194D - Company",
379 category_name="Insurance Commission",
380 doctype="Tax Withholding Category", accounts=accounts,
381 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
382 "single_threshold": 15000, "cumulative_threshold": 0}]),
383 dict(name="TDS - 194D - Company Assessee",
384 category_name="Insurance Commission",
385 doctype="Tax Withholding Category", accounts=accounts,
386 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
387 "single_threshold": 15000, "cumulative_threshold": 0}]),
388 dict(name="TDS - 194D - Individual",
389 category_name="Insurance Commission",
390 doctype="Tax Withholding Category", accounts=accounts,
391 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
392 "single_threshold": 15000, "cumulative_threshold": 0}]),
393 dict(name="TDS - 194D - No PAN / Invalid PAN",
394 category_name="Insurance Commission",
395 doctype="Tax Withholding Category", accounts=accounts,
396 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
397 "single_threshold": 15000, "cumulative_threshold": 0}]),
398 dict(name="TDS - 194DA - Company",
399 category_name="Non-exempt payments made under a life insurance policy",
400 doctype="Tax Withholding Category", accounts=accounts,
401 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
402 "single_threshold": 100000, "cumulative_threshold": 0}]),
403 dict(name="TDS - 194DA - Individual",
404 category_name="Non-exempt payments made under a life insurance policy",
405 doctype="Tax Withholding Category", accounts=accounts,
406 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
407 "single_threshold": 100000, "cumulative_threshold": 0}]),
408 dict(name="TDS - 194DA - No PAN / Invalid PAN",
409 category_name="Non-exempt payments made under a life insurance policy",
410 doctype="Tax Withholding Category", accounts=accounts,
411 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
412 "single_threshold": 100000, "cumulative_threshold": 0}]),
413 dict(name="TDS - 194H - Company",
414 category_name="Commission / Brokerage",
415 doctype="Tax Withholding Category", accounts=accounts,
416 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
417 "single_threshold": 15000, "cumulative_threshold": 0}]),
418 dict(name="TDS - 194H - Individual",
419 category_name="Commission / Brokerage",
420 doctype="Tax Withholding Category", accounts=accounts,
421 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
422 "single_threshold": 15000, "cumulative_threshold": 0}]),
423 dict(name="TDS - 194H - No PAN / Invalid PAN",
424 category_name="Commission / Brokerage",
425 doctype="Tax Withholding Category", accounts=accounts,
426 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
427 "single_threshold": 15000, "cumulative_threshold": 0}]),
428 dict(name="TDS - 194I - Rent - Company",
429 category_name="Rent",
430 doctype="Tax Withholding Category", accounts=accounts,
431 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
432 "single_threshold": 180000, "cumulative_threshold": 0}]),
433 dict(name="TDS - 194I - Rent - Individual",
434 category_name="Rent",
435 doctype="Tax Withholding Category", accounts=accounts,
436 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
437 "single_threshold": 180000, "cumulative_threshold": 0}]),
438 dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
439 category_name="Rent",
440 doctype="Tax Withholding Category", accounts=accounts,
441 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
442 "single_threshold": 180000, "cumulative_threshold": 0}]),
443 dict(name="TDS - 194I - Rent/Machinery - Company",
444 category_name="Rent-Plant / Machinery",
445 doctype="Tax Withholding Category", accounts=accounts,
446 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
447 "single_threshold": 180000, "cumulative_threshold": 0}]),
448 dict(name="TDS - 194I - Rent/Machinery - Individual",
449 category_name="Rent-Plant / Machinery",
450 doctype="Tax Withholding Category", accounts=accounts,
451 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
452 "single_threshold": 180000, "cumulative_threshold": 0}]),
453 dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
454 category_name="Rent-Plant / Machinery",
455 doctype="Tax Withholding Category", accounts=accounts,
456 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
457 "single_threshold": 180000, "cumulative_threshold": 0}]),
458 dict(name="TDS - 194J - Professional Fees - Company",
459 category_name="Professional Fees",
460 doctype="Tax Withholding Category", accounts=accounts,
461 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
462 "single_threshold": 30000, "cumulative_threshold": 0}]),
463 dict(name="TDS - 194J - Professional Fees - Individual",
464 category_name="Professional Fees",
465 doctype="Tax Withholding Category", accounts=accounts,
466 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
467 "single_threshold": 30000, "cumulative_threshold": 0}]),
468 dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
469 category_name="Professional Fees",
470 doctype="Tax Withholding Category", accounts=accounts,
471 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
472 "single_threshold": 30000, "cumulative_threshold": 0}]),
473 dict(name="TDS - 194J - Director Fees - Company",
474 category_name="Director Fees",
475 doctype="Tax Withholding Category", accounts=accounts,
476 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
477 "single_threshold": 0, "cumulative_threshold": 0}]),
478 dict(name="TDS - 194J - Director Fees - Individual",
479 category_name="Director Fees",
480 doctype="Tax Withholding Category", accounts=accounts,
481 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
482 "single_threshold": 0, "cumulative_threshold": 0}]),
483 dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
484 category_name="Director Fees",
485 doctype="Tax Withholding Category", accounts=accounts,
486 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
487 "single_threshold": 0, "cumulative_threshold": 0}]),
488 dict(name="TDS - 194 - Dividends - Company",
489 category_name="Dividends",
490 doctype="Tax Withholding Category", accounts=accounts,
491 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
492 "single_threshold": 2500, "cumulative_threshold": 0}]),
493 dict(name="TDS - 194 - Dividends - Individual",
494 category_name="Dividends",
495 doctype="Tax Withholding Category", accounts=accounts,
496 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
497 "single_threshold": 2500, "cumulative_threshold": 0}]),
498 dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
499 category_name="Dividends",
500 doctype="Tax Withholding Category", accounts=accounts,
501 rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
502 "single_threshold": 2500, "cumulative_threshold": 0}])
503 ]