blob: 9ca3137db4d9efa08983265b9ce9a5fec5caad4e [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
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05304
5import frappe, os, json
Rushabh Mehtaf0569742017-09-13 12:52:30 +05306from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
Sagar Vora4c31fbb2021-04-01 15:32:37 +05307from frappe.custom.doctype.property_setter.property_setter import make_property_setter
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
Anuja Pawar4569e522021-01-14 19:24:30 +053010from erpnext.accounts.utils import get_fiscal_year, FiscalYearError
Zarrar7f8024c2018-08-01 17:45:05 +053011from frappe.utils import today
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053012
Ankush Menat494bd9e2022-03-28 18:52:46 +053013
Rushabh Mehta01659272017-06-27 18:05:17 +053014def setup(company=None, patch=True):
Deepesh Gargfea29ae2021-07-12 18:29:52 +053015 # Company independent fixtures should be called only once at the first company setup
Ankush Menat494bd9e2022-03-28 18:52:46 +053016 if patch or frappe.db.count("Company", {"country": "India"}) <= 1:
Deepesh Gargfea29ae2021-07-12 18:29:52 +053017 setup_company_independent_fixtures(patch=patch)
18
Prateeksha Singh39b87652018-11-12 17:19:56 +053019 if not patch:
Prateeksha Singhdabf3492018-11-13 15:56:15 +053020 make_fixtures(company)
Prateeksha Singh39b87652018-11-12 17:19:56 +053021
Ankush Menat494bd9e2022-03-28 18:52:46 +053022
Prateeksha Singh39b87652018-11-12 17:19:56 +053023# TODO: for all countries
Nabin Hait10c61372021-04-13 15:46:01 +053024def setup_company_independent_fixtures(patch=False):
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053025 make_custom_fields()
Nabin Hait10c61372021-04-13 15:46:01 +053026 make_property_setters(patch=patch)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053027 add_permissions()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053028 add_custom_roles_for_reports()
Ankush Menat494bd9e2022-03-28 18:52:46 +053029 frappe.enqueue("erpnext.regional.india.setup.add_hsn_sac_codes", now=frappe.flags.in_test)
Nabin Hait852cb642017-07-05 12:58:19 +053030 add_print_formats()
Deepesh Garg204ea102021-04-30 16:35:52 +053031 update_accounts_settings_for_taxes()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053032
Ankush Menat494bd9e2022-03-28 18:52:46 +053033
Nabin Hait1a609312017-07-13 12:16:04 +053034def add_hsn_sac_codes():
Ankush Menat5bb89b02021-06-11 15:57:01 +053035 if frappe.flags.in_test and frappe.flags.created_hsn_codes:
36 return
37
Nabin Hait1a609312017-07-13 12:16:04 +053038 # HSN codes
Ankush Menat494bd9e2022-03-28 18:52:46 +053039 with open(os.path.join(os.path.dirname(__file__), "hsn_code_data.json"), "r") as f:
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053040 hsn_codes = json.loads(f.read())
41
Nabin Hait1a609312017-07-13 12:16:04 +053042 create_hsn_codes(hsn_codes, code_field="hsn_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053043
Nabin Hait1a609312017-07-13 12:16:04 +053044 # SAC Codes
Ankush Menat494bd9e2022-03-28 18:52:46 +053045 with open(os.path.join(os.path.dirname(__file__), "sac_code_data.json"), "r") as f:
Nabin Hait1a609312017-07-13 12:16:04 +053046 sac_codes = json.loads(f.read())
47 create_hsn_codes(sac_codes, code_field="sac_code")
Prateeksha Singh95d8fd32017-09-04 11:14:04 +053048
Ankush Menat5bb89b02021-06-11 15:57:01 +053049 if frappe.flags.in_test:
50 frappe.flags.created_hsn_codes = True
51
Ankush Menat494bd9e2022-03-28 18:52:46 +053052
Nabin Hait1a609312017-07-13 12:16:04 +053053def create_hsn_codes(data, code_field):
54 for d in data:
Ankush Menat494bd9e2022-03-28 18:52:46 +053055 hsn_code = frappe.new_doc("GST HSN Code")
Rushabh Mehtaf702d722017-09-27 15:31:30 +053056 hsn_code.description = d["description"]
57 hsn_code.hsn_code = d[code_field]
58 hsn_code.name = d[code_field]
Ankush Menat9c7df2e2022-02-22 20:53:19 +053059 hsn_code.db_insert(ignore_if_duplicate=True)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053060
Ankush Menat494bd9e2022-03-28 18:52:46 +053061
Rushabh Mehta919a74a2017-06-22 16:37:04 +053062def add_custom_roles_for_reports():
Ankush Menat494bd9e2022-03-28 18:52:46 +053063 for report_name in (
64 "GST Sales Register",
65 "GST Purchase Register",
66 "GST Itemised Sales Register",
67 "GST Itemised Purchase Register",
68 "Eway Bill",
69 "E-Invoice Summary",
70 ):
Rushabh Mehta919a74a2017-06-22 16:37:04 +053071
Ankush Menat494bd9e2022-03-28 18:52:46 +053072 if not frappe.db.get_value("Custom Role", dict(report=report_name)):
73 frappe.get_doc(
74 dict(
75 doctype="Custom Role",
76 report=report_name,
77 roles=[dict(role="Accounts User"), dict(role="Accounts Manager")],
78 )
79 ).insert()
Rushabh Mehta919a74a2017-06-22 16:37:04 +053080
Ankush Menat494bd9e2022-03-28 18:52:46 +053081 for report_name in ("HSN-wise-summary of outward supplies", "GSTR-1", "GSTR-2"):
Anurag Mishra54cd1942020-09-03 13:51:26 +053082
Ankush Menat494bd9e2022-03-28 18:52:46 +053083 if not frappe.db.get_value("Custom Role", dict(report=report_name)):
84 frappe.get_doc(
85 dict(
86 doctype="Custom Role",
87 report=report_name,
88 roles=[dict(role="Accounts User"), dict(role="Accounts Manager"), dict(role="Auditor")],
89 )
90 ).insert()
91
Anurag Mishra54cd1942020-09-03 13:51:26 +053092
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053093def add_permissions():
Ankush Menat494bd9e2022-03-28 18:52:46 +053094 for doctype in (
95 "GST HSN Code",
96 "GST Settings",
97 "GSTR 3B Report",
98 "Lower Deduction Certificate",
99 "E Invoice Settings",
100 ):
101 add_permission(doctype, "All", 0)
102 for role in ("Accounts Manager", "Accounts User", "System Manager"):
Saqib5e6ce882020-02-03 15:40:35 +0530103 add_permission(doctype, role, 0)
Ankush Menat494bd9e2022-03-28 18:52:46 +0530104 update_permission_property(doctype, role, 0, "write", 1)
105 update_permission_property(doctype, role, 0, "create", 1)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530106
Ankush Menat494bd9e2022-03-28 18:52:46 +0530107 if doctype == "GST HSN Code":
108 for role in ("Item Manager", "Stock Manager"):
Deepesh Garg6c8efde2020-04-04 20:05:17 +0530109 add_permission(doctype, role, 0)
Ankush Menat494bd9e2022-03-28 18:52:46 +0530110 update_permission_property(doctype, role, 0, "write", 1)
111 update_permission_property(doctype, role, 0, "create", 1)
112
Deepesh Garg6c8efde2020-04-04 20:05:17 +0530113
Nabin Hait852cb642017-07-05 12:58:19 +0530114def add_print_formats():
115 frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
Deepesh Gargfe2ced72022-02-25 16:57:59 +0530116 frappe.reload_doc("selling", "print_format", "gst_pos_invoice")
Saqib Ansaric5782b02022-01-27 20:09:56 +0530117 frappe.reload_doc("accounts", "print_format", "GST E-Invoice")
rohitwaghchauree3b5c0f2017-12-16 10:53:53 +0530118
barredterra1521b312021-03-03 12:33:48 +0100119 frappe.db.set_value("Print Format", "GST POS Invoice", "disabled", 0)
120 frappe.db.set_value("Print Format", "GST Tax Invoice", "disabled", 0)
Saqib Ansaric5782b02022-01-27 20:09:56 +0530121 frappe.db.set_value("Print Format", "GST E-Invoice", "disabled", 0)
Nabin Hait852cb642017-07-05 12:58:19 +0530122
Ankush Menat494bd9e2022-03-28 18:52:46 +0530123
Nabin Hait10c61372021-04-13 15:46:01 +0530124def make_property_setters(patch=False):
Sagar Vora4c31fbb2021-04-01 15:32:37 +0530125 # GST rules do not allow for an invoice no. bigger than 16 characters
Ankush Menat494bd9e2022-03-28 18:52:46 +0530126 journal_entry_types = frappe.get_meta("Journal Entry").get_options("voucher_type").split("\n") + [
127 "Reversal Of ITC"
128 ]
129 sales_invoice_series = ["SINV-.YY.-", "SRET-.YY.-", ""] + frappe.get_meta(
130 "Sales Invoice"
131 ).get_options("naming_series").split("\n")
132 purchase_invoice_series = ["PINV-.YY.-", "PRET-.YY.-", ""] + frappe.get_meta(
133 "Purchase Invoice"
134 ).get_options("naming_series").split("\n")
Deepesh Garg55fe85d2021-05-14 12:17:41 +0530135
Nabin Hait10c61372021-04-13 15:46:01 +0530136 if not patch:
Ankush Menat494bd9e2022-03-28 18:52:46 +0530137 make_property_setter(
138 "Sales Invoice", "naming_series", "options", "\n".join(sales_invoice_series), ""
139 )
140 make_property_setter(
141 "Purchase Invoice", "naming_series", "options", "\n".join(purchase_invoice_series), ""
142 )
143 make_property_setter(
144 "Journal Entry", "voucher_type", "options", "\n".join(journal_entry_types), ""
145 )
146
Sagar Vora4c31fbb2021-04-01 15:32:37 +0530147
Rushabh Mehta69fa8082018-07-17 18:22:51 +0530148def make_custom_fields(update=True):
Saqib Ansarif1fcb382021-09-29 19:56:02 +0530149 custom_fields = get_custom_fields()
150 create_custom_fields(custom_fields, update=update)
151
Ankush Menat494bd9e2022-03-28 18:52:46 +0530152
Saqib Ansarif1fcb382021-09-29 19:56:02 +0530153def get_custom_fields():
Ankush Menat494bd9e2022-03-28 18:52:46 +0530154 hsn_sac_field = dict(
155 fieldname="gst_hsn_code",
156 label="HSN/SAC",
157 fieldtype="Data",
158 fetch_from="item_code.gst_hsn_code",
159 insert_after="description",
160 allow_on_submit=1,
161 print_hide=1,
162 fetch_if_empty=1,
163 )
164 nil_rated_exempt = dict(
165 fieldname="is_nil_exempt",
166 label="Is Nil Rated or Exempted",
167 fieldtype="Check",
168 fetch_from="item_code.is_nil_exempt",
169 insert_after="gst_hsn_code",
170 print_hide=1,
171 )
172 is_non_gst = dict(
173 fieldname="is_non_gst",
174 label="Is Non GST",
175 fieldtype="Check",
176 fetch_from="item_code.is_non_gst",
177 insert_after="is_nil_exempt",
178 print_hide=1,
179 )
180 taxable_value = dict(
181 fieldname="taxable_value",
182 label="Taxable Value",
183 fieldtype="Currency",
184 insert_after="base_net_amount",
185 hidden=1,
186 options="Company:company:default_currency",
187 print_hide=1,
188 )
Deepesh Garg22b61602019-03-21 20:47:47 +0530189
190 purchase_invoice_gst_category = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530191 dict(
192 fieldname="gst_section",
193 label="GST Details",
194 fieldtype="Section Break",
195 insert_after="language",
196 print_hide=1,
197 collapsible=1,
198 ),
199 dict(
200 fieldname="gst_category",
201 label="GST Category",
202 fieldtype="Select",
203 insert_after="gst_section",
204 print_hide=1,
205 options="\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders",
206 fetch_from="supplier.gst_category",
207 fetch_if_empty=1,
208 ),
209 dict(
210 fieldname="export_type",
211 label="Export Type",
212 fieldtype="Select",
213 insert_after="gst_category",
214 print_hide=1,
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530215 depends_on='eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
Ankush Menat494bd9e2022-03-28 18:52:46 +0530216 options="\nWith Payment of Tax\nWithout Payment of Tax",
217 fetch_from="supplier.export_type",
218 fetch_if_empty=1,
219 ),
Deepesh Garg22b61602019-03-21 20:47:47 +0530220 ]
221
222 sales_invoice_gst_category = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530223 dict(
224 fieldname="gst_section",
225 label="GST Details",
226 fieldtype="Section Break",
227 insert_after="language",
228 print_hide=1,
229 collapsible=1,
230 ),
231 dict(
232 fieldname="gst_category",
233 label="GST Category",
234 fieldtype="Select",
235 insert_after="gst_section",
236 print_hide=1,
237 options="\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders",
238 fetch_from="customer.gst_category",
239 fetch_if_empty=1,
240 length=25,
241 ),
242 dict(
243 fieldname="export_type",
244 label="Export Type",
245 fieldtype="Select",
246 insert_after="gst_category",
247 print_hide=1,
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530248 depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
Ankush Menat494bd9e2022-03-28 18:52:46 +0530249 options="\nWith Payment of Tax\nWithout Payment of Tax",
250 fetch_from="customer.export_type",
251 fetch_if_empty=1,
252 length=25,
253 ),
Deepesh Garg22b61602019-03-21 20:47:47 +0530254 ]
255
Deepesh Garg29997412021-03-29 19:49:52 +0530256 delivery_note_gst_category = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530257 dict(
258 fieldname="gst_category",
259 label="GST Category",
260 fieldtype="Select",
261 insert_after="gst_vehicle_type",
262 print_hide=1,
263 options="\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders",
264 fetch_from="customer.gst_category",
265 fetch_if_empty=1,
266 ),
Deepesh Garg29997412021-03-29 19:49:52 +0530267 ]
268
Deepesh Garg22b61602019-03-21 20:47:47 +0530269 invoice_gst_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530270 dict(
271 fieldname="invoice_copy",
272 label="Invoice Copy",
273 length=30,
274 fieldtype="Select",
275 insert_after="export_type",
276 print_hide=1,
277 allow_on_submit=1,
278 options="Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier",
279 ),
280 dict(
281 fieldname="reverse_charge",
282 label="Reverse Charge",
283 length=2,
284 fieldtype="Select",
285 insert_after="invoice_copy",
286 print_hide=1,
287 options="Y\nN",
288 default="N",
289 ),
290 dict(
291 fieldname="ecommerce_gstin",
292 label="E-commerce GSTIN",
293 length=15,
294 fieldtype="Data",
295 insert_after="export_type",
296 print_hide=1,
297 ),
298 dict(fieldname="gst_col_break", fieldtype="Column Break", insert_after="ecommerce_gstin"),
299 dict(
300 fieldname="reason_for_issuing_document",
301 label="Reason For Issuing document",
302 fieldtype="Select",
303 insert_after="gst_col_break",
304 print_hide=1,
305 depends_on="eval:doc.is_return==1",
306 length=45,
307 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",
308 ),
Nabin Hait879e1622017-08-21 08:28:55 +0530309 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530310
Nabin Hait879e1622017-08-21 08:28:55 +0530311 purchase_invoice_gst_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530312 dict(
313 fieldname="supplier_gstin",
314 label="Supplier GSTIN",
315 fieldtype="Data",
316 insert_after="supplier_address",
317 fetch_from="supplier_address.gstin",
318 print_hide=1,
319 read_only=1,
320 ),
321 dict(
322 fieldname="company_gstin",
323 label="Company GSTIN",
324 fieldtype="Data",
325 insert_after="shipping_address_display",
326 fetch_from="shipping_address.gstin",
327 print_hide=1,
328 read_only=1,
329 ),
330 dict(
331 fieldname="place_of_supply",
332 label="Place of Supply",
333 fieldtype="Data",
334 insert_after="shipping_address",
335 print_hide=1,
336 read_only=1,
337 ),
338 ]
deepeshgarg007d29ee972019-01-09 17:09:11 +0530339
340 purchase_invoice_itc_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530341 dict(
342 fieldname="eligibility_for_itc",
343 label="Eligibility For ITC",
344 fieldtype="Select",
345 insert_after="reason_for_issuing_document",
346 print_hide=1,
347 options="Input Service Distributor\nImport Of Service\nImport Of Capital Goods\nITC on Reverse Charge\nIneligible As Per Section 17(5)\nIneligible Others\nAll Other ITC",
348 default="All Other ITC",
349 ),
350 dict(
351 fieldname="itc_integrated_tax",
352 label="Availed ITC Integrated Tax",
353 fieldtype="Currency",
354 insert_after="eligibility_for_itc",
355 options="Company:company:default_currency",
356 print_hide=1,
357 ),
358 dict(
359 fieldname="itc_central_tax",
360 label="Availed ITC Central Tax",
361 fieldtype="Currency",
362 insert_after="itc_integrated_tax",
363 options="Company:company:default_currency",
364 print_hide=1,
365 ),
366 dict(
367 fieldname="itc_state_tax",
368 label="Availed ITC State/UT Tax",
369 fieldtype="Currency",
370 insert_after="itc_central_tax",
371 options="Company:company:default_currency",
372 print_hide=1,
373 ),
374 dict(
375 fieldname="itc_cess_amount",
376 label="Availed ITC Cess",
377 fieldtype="Currency",
378 insert_after="itc_state_tax",
379 options="Company:company:default_currency",
380 print_hide=1,
381 ),
382 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530383
Nabin Hait879e1622017-08-21 08:28:55 +0530384 sales_invoice_gst_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530385 dict(
386 fieldname="billing_address_gstin",
387 label="Billing Address GSTIN",
388 fieldtype="Data",
389 insert_after="customer_address",
390 read_only=1,
391 fetch_from="customer_address.gstin",
392 print_hide=1,
393 length=15,
394 ),
395 dict(
396 fieldname="customer_gstin",
397 label="Customer GSTIN",
398 fieldtype="Data",
399 insert_after="shipping_address_name",
400 fetch_from="shipping_address_name.gstin",
401 print_hide=1,
402 length=15,
403 ),
404 dict(
405 fieldname="place_of_supply",
406 label="Place of Supply",
407 fieldtype="Data",
408 insert_after="customer_gstin",
409 print_hide=1,
410 read_only=1,
411 length=50,
412 ),
413 dict(
414 fieldname="company_gstin",
415 label="Company GSTIN",
416 fieldtype="Data",
417 insert_after="company_address",
418 fetch_from="company_address.gstin",
419 print_hide=1,
420 read_only=1,
421 length=15,
422 ),
423 ]
deepeshgarg007d29ee972019-01-09 17:09:11 +0530424
425 sales_invoice_shipping_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530426 dict(
427 fieldname="port_code",
428 label="Port Code",
429 fieldtype="Data",
430 insert_after="reason_for_issuing_document",
431 print_hide=1,
432 depends_on="eval:doc.gst_category=='Overseas' ",
433 length=15,
434 ),
435 dict(
436 fieldname="shipping_bill_number",
437 label=" Shipping Bill Number",
438 fieldtype="Data",
439 insert_after="port_code",
440 print_hide=1,
441 depends_on="eval:doc.gst_category=='Overseas' ",
442 length=50,
443 ),
444 dict(
445 fieldname="shipping_bill_date",
446 label="Shipping Bill Date",
447 fieldtype="Date",
448 insert_after="shipping_bill_number",
449 print_hide=1,
450 depends_on="eval:doc.gst_category=='Overseas' ",
451 ),
452 ]
Prateeksha Singh95d8fd32017-09-04 11:14:04 +0530453
Deepesh Garg55fe85d2021-05-14 12:17:41 +0530454 journal_entry_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530455 dict(
456 fieldname="reversal_type",
457 label="Reversal Type",
458 fieldtype="Select",
459 insert_after="voucher_type",
460 print_hide=1,
Deepesh Garg55fe85d2021-05-14 12:17:41 +0530461 options="As per rules 42 & 43 of CGST Rules\nOthers",
462 depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530463 mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
464 ),
465 dict(
466 fieldname="company_address",
467 label="Company Address",
468 fieldtype="Link",
469 options="Address",
470 insert_after="reversal_type",
471 print_hide=1,
Deepesh Garg55fe85d2021-05-14 12:17:41 +0530472 depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530473 mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
474 ),
475 dict(
476 fieldname="company_gstin",
477 label="Company GSTIN",
478 fieldtype="Data",
479 read_only=1,
480 insert_after="company_address",
481 print_hide=1,
482 fetch_from="company_address.gstin",
483 depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
484 mandatory_depends_on="eval:doc.voucher_type=='Reversal Of ITC'",
485 ),
Deepesh Garg55fe85d2021-05-14 12:17:41 +0530486 ]
487
Shreya Shah4fa600a2018-06-05 11:27:53 +0530488 inter_state_gst_field = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530489 dict(
490 fieldname="is_inter_state",
491 label="Is Inter State",
492 fieldtype="Check",
493 insert_after="disabled",
494 print_hide=1,
495 ),
496 dict(
497 fieldname="is_reverse_charge",
498 label="Is Reverse Charge",
499 fieldtype="Check",
500 insert_after="is_inter_state",
501 print_hide=1,
502 ),
503 dict(
504 fieldname="tax_category_column_break",
505 fieldtype="Column Break",
506 insert_after="is_reverse_charge",
507 ),
508 dict(
509 fieldname="gst_state",
510 label="Source State",
511 fieldtype="Select",
512 options="\n".join(states),
513 insert_after="company",
514 ),
Shreya Shah4fa600a2018-06-05 11:27:53 +0530515 ]
516
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530517 ewaybill_fields = [
518 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530519 "fieldname": "distance",
520 "label": "Distance (in km)",
521 "fieldtype": "Float",
522 "insert_after": "vehicle_no",
523 "print_hide": 1,
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530524 },
525 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530526 "fieldname": "gst_transporter_id",
527 "label": "GST Transporter ID",
528 "fieldtype": "Data",
529 "insert_after": "transporter",
530 "fetch_from": "transporter.gst_transporter_id",
531 "print_hide": 1,
532 "translatable": 0,
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530533 },
534 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530535 "fieldname": "mode_of_transport",
536 "label": "Mode of Transport",
537 "fieldtype": "Select",
538 "options": "\nRoad\nAir\nRail\nShip",
539 "default": "Road",
540 "insert_after": "transporter_name",
541 "print_hide": 1,
542 "translatable": 0,
Nabin Hait34c551d2019-07-03 10:34:31 +0530543 },
544 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530545 "fieldname": "gst_vehicle_type",
546 "label": "GST Vehicle Type",
547 "fieldtype": "Select",
548 "options": "Regular\nOver Dimensional Cargo (ODC)",
549 "depends_on": 'eval:(doc.mode_of_transport === "Road")',
550 "default": "Regular",
551 "insert_after": "lr_date",
552 "print_hide": 1,
553 "translatable": 0,
Deepesh Garg15ff6a52020-02-18 12:28:41 +0530554 },
555 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530556 "fieldname": "ewaybill",
557 "label": "E-Way Bill No.",
558 "fieldtype": "Data",
559 "depends_on": "eval:(doc.docstatus === 1)",
560 "allow_on_submit": 1,
561 "insert_after": "customer_name_in_arabic",
562 "translatable": 0,
563 },
Nabin Hait34c551d2019-07-03 10:34:31 +0530564 ]
565
566 si_ewaybill_fields = [
567 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530568 "fieldname": "transporter_info",
569 "label": "Transporter Info",
570 "fieldtype": "Section Break",
571 "insert_after": "terms",
572 "collapsible": 1,
573 "collapsible_depends_on": "transporter",
574 "print_hide": 1,
Nabin Hait34c551d2019-07-03 10:34:31 +0530575 },
576 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530577 "fieldname": "transporter",
578 "label": "Transporter",
579 "fieldtype": "Link",
580 "insert_after": "transporter_info",
581 "options": "Supplier",
582 "print_hide": 1,
Nabin Hait34c551d2019-07-03 10:34:31 +0530583 },
584 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530585 "fieldname": "gst_transporter_id",
586 "label": "GST Transporter ID",
587 "fieldtype": "Data",
588 "insert_after": "transporter",
589 "fetch_from": "transporter.gst_transporter_id",
590 "print_hide": 1,
591 "translatable": 0,
592 "length": 20,
Nabin Hait34c551d2019-07-03 10:34:31 +0530593 },
594 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530595 "fieldname": "driver",
596 "label": "Driver",
597 "fieldtype": "Link",
598 "insert_after": "gst_transporter_id",
599 "options": "Driver",
600 "print_hide": 1,
Nabin Hait34c551d2019-07-03 10:34:31 +0530601 },
602 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530603 "fieldname": "lr_no",
604 "label": "Transport Receipt No",
605 "fieldtype": "Data",
606 "insert_after": "driver",
607 "print_hide": 1,
608 "translatable": 0,
609 "length": 30,
Nabin Hait34c551d2019-07-03 10:34:31 +0530610 },
611 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530612 "fieldname": "vehicle_no",
613 "label": "Vehicle No",
614 "fieldtype": "Data",
615 "insert_after": "lr_no",
616 "print_hide": 1,
617 "translatable": 0,
618 "length": 10,
Nabin Hait34c551d2019-07-03 10:34:31 +0530619 },
620 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530621 "fieldname": "distance",
622 "label": "Distance (in km)",
623 "fieldtype": "Float",
624 "insert_after": "vehicle_no",
625 "print_hide": 1,
626 },
627 {"fieldname": "transporter_col_break", "fieldtype": "Column Break", "insert_after": "distance"},
628 {
629 "fieldname": "transporter_name",
630 "label": "Transporter Name",
631 "fieldtype": "Small Text",
632 "insert_after": "transporter_col_break",
633 "fetch_from": "transporter.name",
634 "read_only": 1,
635 "print_hide": 1,
636 "translatable": 0,
Nabin Hait34c551d2019-07-03 10:34:31 +0530637 },
638 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530639 "fieldname": "mode_of_transport",
640 "label": "Mode of Transport",
641 "fieldtype": "Select",
642 "options": "\nRoad\nAir\nRail\nShip",
643 "insert_after": "transporter_name",
644 "print_hide": 1,
645 "translatable": 0,
646 "length": 5,
Nabin Hait34c551d2019-07-03 10:34:31 +0530647 },
648 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530649 "fieldname": "driver_name",
650 "label": "Driver Name",
651 "fieldtype": "Small Text",
652 "insert_after": "mode_of_transport",
653 "fetch_from": "driver.full_name",
654 "print_hide": 1,
655 "translatable": 0,
Nabin Hait34c551d2019-07-03 10:34:31 +0530656 },
657 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530658 "fieldname": "lr_date",
659 "label": "Transport Receipt Date",
660 "fieldtype": "Date",
661 "insert_after": "driver_name",
662 "default": "Today",
663 "print_hide": 1,
Nabin Hait34c551d2019-07-03 10:34:31 +0530664 },
665 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530666 "fieldname": "gst_vehicle_type",
667 "label": "GST Vehicle Type",
668 "fieldtype": "Select",
669 "options": "Regular\nOver Dimensional Cargo (ODC)",
670 "depends_on": 'eval:(doc.mode_of_transport === "Road")',
671 "default": "Regular",
672 "insert_after": "lr_date",
673 "print_hide": 1,
674 "translatable": 0,
675 "length": 30,
Nabin Hait34c551d2019-07-03 10:34:31 +0530676 },
677 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530678 "fieldname": "ewaybill",
679 "label": "E-Way Bill No.",
680 "fieldtype": "Data",
681 "depends_on": "eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)",
682 "allow_on_submit": 1,
683 "insert_after": "tax_id",
684 "translatable": 0,
685 "length": 20,
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530686 },
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530687 ]
688
Deepesh Garge8a5dc32021-09-02 18:56:04 +0530689 payment_entry_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530690 dict(
691 fieldname="gst_section",
692 label="GST Details",
693 fieldtype="Section Break",
694 insert_after="deductions",
695 print_hide=1,
696 collapsible=1,
697 ),
698 dict(
699 fieldname="company_address",
700 label="Company Address",
701 fieldtype="Link",
702 insert_after="gst_section",
703 print_hide=1,
704 options="Address",
705 ),
706 dict(
707 fieldname="company_gstin",
708 label="Company GSTIN",
709 fieldtype="Data",
710 insert_after="company_address",
711 fetch_from="company_address.gstin",
712 print_hide=1,
713 read_only=1,
714 ),
715 dict(
716 fieldname="place_of_supply",
717 label="Place of Supply",
718 fieldtype="Data",
719 insert_after="company_gstin",
720 print_hide=1,
721 read_only=1,
722 ),
723 dict(fieldname="gst_column_break", fieldtype="Column Break", insert_after="place_of_supply"),
724 dict(
725 fieldname="customer_address",
726 label="Customer Address",
727 fieldtype="Link",
728 insert_after="gst_column_break",
729 print_hide=1,
730 options="Address",
731 depends_on='eval:doc.party_type == "Customer"',
732 ),
733 dict(
734 fieldname="customer_gstin",
735 label="Customer GSTIN",
736 fieldtype="Data",
737 insert_after="customer_address",
738 fetch_from="customer_address.gstin",
739 print_hide=1,
740 read_only=1,
741 ),
Deepesh Garge8a5dc32021-09-02 18:56:04 +0530742 ]
743
Saqib Ansaric5782b02022-01-27 20:09:56 +0530744 si_einvoice_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530745 dict(
746 fieldname="irn",
747 label="IRN",
748 fieldtype="Data",
749 read_only=1,
750 insert_after="customer",
751 no_copy=1,
752 print_hide=1,
maharshivpatel80a13c32022-05-02 21:51:27 +0530753 depends_on='eval:in_list(["Registered Regular", "Registered Composition", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0',
Ankush Menat494bd9e2022-03-28 18:52:46 +0530754 ),
755 dict(
756 fieldname="irn_cancelled",
757 label="IRN Cancelled",
758 fieldtype="Check",
759 no_copy=1,
760 print_hide=1,
761 depends_on="eval: doc.irn",
762 allow_on_submit=1,
763 insert_after="customer",
764 ),
765 dict(
766 fieldname="eway_bill_validity",
767 label="E-Way Bill Validity",
768 fieldtype="Data",
769 no_copy=1,
770 print_hide=1,
771 depends_on="ewaybill",
772 read_only=1,
773 allow_on_submit=1,
774 insert_after="ewaybill",
775 ),
776 dict(
777 fieldname="eway_bill_cancelled",
778 label="E-Way Bill Cancelled",
779 fieldtype="Check",
780 no_copy=1,
781 print_hide=1,
782 depends_on="eval:(doc.eway_bill_cancelled === 1)",
783 read_only=1,
784 allow_on_submit=1,
785 insert_after="customer",
786 ),
787 dict(
788 fieldname="einvoice_section",
789 label="E-Invoice Fields",
790 fieldtype="Section Break",
791 insert_after="gst_vehicle_type",
792 print_hide=1,
793 hidden=1,
794 ),
795 dict(
796 fieldname="ack_no",
797 label="Ack. No.",
798 fieldtype="Data",
799 read_only=1,
800 hidden=1,
801 insert_after="einvoice_section",
802 no_copy=1,
803 print_hide=1,
804 ),
805 dict(
806 fieldname="ack_date",
807 label="Ack. Date",
808 fieldtype="Data",
809 read_only=1,
810 hidden=1,
811 insert_after="ack_no",
812 no_copy=1,
813 print_hide=1,
814 ),
815 dict(
816 fieldname="irn_cancel_date",
817 label="Cancel Date",
818 fieldtype="Data",
819 read_only=1,
820 hidden=1,
821 insert_after="ack_date",
822 no_copy=1,
823 print_hide=1,
824 ),
825 dict(
826 fieldname="signed_einvoice",
827 label="Signed E-Invoice",
828 fieldtype="Code",
829 options="JSON",
830 hidden=1,
831 insert_after="irn_cancel_date",
832 no_copy=1,
833 print_hide=1,
834 read_only=1,
835 ),
836 dict(
837 fieldname="signed_qr_code",
838 label="Signed QRCode",
839 fieldtype="Code",
840 options="JSON",
841 hidden=1,
842 insert_after="signed_einvoice",
843 no_copy=1,
844 print_hide=1,
845 read_only=1,
846 ),
847 dict(
848 fieldname="qrcode_image",
849 label="QRCode",
850 fieldtype="Attach Image",
851 hidden=1,
852 insert_after="signed_qr_code",
853 no_copy=1,
854 print_hide=1,
855 read_only=1,
856 ),
857 dict(
858 fieldname="einvoice_status",
859 label="E-Invoice Status",
860 fieldtype="Select",
861 insert_after="qrcode_image",
862 options="\nPending\nGenerated\nCancelled\nFailed",
863 default=None,
864 hidden=1,
865 no_copy=1,
866 print_hide=1,
867 read_only=1,
868 ),
869 dict(
870 fieldname="failure_description",
871 label="E-Invoice Failure Description",
872 fieldtype="Code",
873 options="JSON",
874 hidden=1,
875 insert_after="einvoice_status",
876 no_copy=1,
877 print_hide=1,
878 read_only=1,
879 ),
Saqib Ansaric5782b02022-01-27 20:09:56 +0530880 ]
881
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530882 custom_fields = {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530883 "Address": [
884 dict(fieldname="gstin", label="Party GSTIN", fieldtype="Data", insert_after="fax"),
885 dict(
886 fieldname="gst_state",
887 label="GST State",
888 fieldtype="Select",
889 options="\n".join(states),
890 insert_after="gstin",
891 ),
892 dict(
893 fieldname="gst_state_number",
894 label="GST State Number",
895 fieldtype="Data",
896 insert_after="gst_state",
897 read_only=1,
898 ),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530899 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530900 "Purchase Invoice": purchase_invoice_gst_category
901 + invoice_gst_fields
902 + purchase_invoice_itc_fields
903 + purchase_invoice_gst_fields,
904 "Purchase Order": purchase_invoice_gst_fields,
905 "Purchase Receipt": purchase_invoice_gst_fields,
906 "Sales Invoice": sales_invoice_gst_category
907 + invoice_gst_fields
908 + sales_invoice_shipping_fields
909 + sales_invoice_gst_fields
910 + si_ewaybill_fields
911 + si_einvoice_fields,
912 "POS Invoice": sales_invoice_gst_fields,
913 "Delivery Note": sales_invoice_gst_fields
914 + ewaybill_fields
915 + sales_invoice_shipping_fields
916 + delivery_note_gst_category,
917 "Payment Entry": payment_entry_fields,
918 "Journal Entry": journal_entry_fields,
919 "Sales Order": sales_invoice_gst_fields,
920 "Tax Category": inter_state_gst_field,
Deepesh Garg485f5cf2022-04-02 17:25:29 +0530921 "Quotation": sales_invoice_gst_fields,
Ankush Menat494bd9e2022-03-28 18:52:46 +0530922 "Item": [
923 dict(
924 fieldname="gst_hsn_code",
925 label="HSN/SAC",
926 fieldtype="Link",
927 options="GST HSN Code",
928 insert_after="item_group",
929 ),
930 dict(
931 fieldname="is_nil_exempt",
932 label="Is Nil Rated or Exempted",
933 fieldtype="Check",
934 insert_after="gst_hsn_code",
935 ),
936 dict(
937 fieldname="is_non_gst", label="Is Non GST ", fieldtype="Check", insert_after="is_nil_exempt"
938 ),
Rushabh Mehtab3c8f442017-06-21 17:22:38 +0530939 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530940 "Quotation Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
941 "Supplier Quotation Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
942 "Sales Order Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
943 "Delivery Note Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
944 "Sales Invoice Item": [hsn_sac_field, nil_rated_exempt, is_non_gst, taxable_value],
945 "POS Invoice Item": [hsn_sac_field, nil_rated_exempt, is_non_gst, taxable_value],
946 "Purchase Order Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
947 "Purchase Receipt Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
948 "Purchase Invoice Item": [hsn_sac_field, nil_rated_exempt, is_non_gst, taxable_value],
949 "Material Request Item": [hsn_sac_field, nil_rated_exempt, is_non_gst],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530950 "Supplier": [
951 {"fieldname": "pan", "label": "PAN", "fieldtype": "Data", "insert_after": "supplier_type"},
Sagar Vorad92f3ac2018-10-10 14:51:26 +0530952 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530953 "fieldname": "gst_transporter_id",
954 "label": "GST Transporter ID",
955 "fieldtype": "Data",
956 "insert_after": "pan",
957 "depends_on": "eval:doc.is_transporter",
Deepesh Garge3ae8d52021-10-20 22:10:21 +0530958 },
959 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530960 "fieldname": "gst_category",
961 "label": "GST Category",
962 "fieldtype": "Select",
963 "insert_after": "gst_transporter_id",
964 "options": "Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders",
965 "default": "Unregistered",
Deepesh Garg22b61602019-03-21 20:47:47 +0530966 },
967 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530968 "fieldname": "export_type",
969 "label": "Export Type",
970 "fieldtype": "Select",
971 "insert_after": "gst_category",
972 "depends_on": 'eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
973 "options": "\nWith Payment of Tax\nWithout Payment of Tax",
974 "mandatory_depends_on": 'eval:in_list(["SEZ", "Overseas"], doc.gst_category)',
975 },
976 ],
977 "Customer": [
978 {"fieldname": "pan", "label": "PAN", "fieldtype": "Data", "insert_after": "customer_type"},
979 {
980 "fieldname": "gst_category",
981 "label": "GST Category",
982 "fieldtype": "Select",
983 "insert_after": "pan",
984 "options": "Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders",
985 "default": "Unregistered",
Deepesh Garg6e2c13f2019-12-10 15:55:05 +0530986 },
987 {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530988 "fieldname": "export_type",
989 "label": "Export Type",
990 "fieldtype": "Select",
991 "insert_after": "gst_category",
992 "depends_on": 'eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
993 "options": "\nWith Payment of Tax\nWithout Payment of Tax",
994 "mandatory_depends_on": 'eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)',
995 },
996 ],
997 "Finance Book": [
998 {
999 "fieldname": "for_income_tax",
1000 "label": "For Income Tax",
1001 "fieldtype": "Check",
1002 "insert_after": "finance_book_name",
1003 "description": "If the asset is put to use for less than 180 days, the first Depreciation Rate will be reduced by 50%.",
Deepesh Garg22b61602019-03-21 20:47:47 +05301004 }
1005 ],
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301006 }
Saqib Ansarif1fcb382021-09-29 19:56:02 +05301007
1008 return custom_fields
Nabin Hait9c421612017-07-20 13:32:01 +05301009
Ankush Menat494bd9e2022-03-28 18:52:46 +05301010
Saurabh2d8a7ee2018-05-11 13:16:16 +05301011def make_fixtures(company=None):
1012 docs = []
Deepesh Garga66184f2021-05-02 12:22:16 +05301013 company = company or frappe.db.get_value("Global Defaults", None, "default_company")
Saurabh2d8a7ee2018-05-11 13:16:16 +05301014
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301015 set_tds_account(docs, company)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301016
1017 for d in docs:
1018 try:
1019 doc = frappe.get_doc(d)
1020 doc.flags.ignore_permissions = True
Ankush Menatcdac2b82022-04-21 20:43:07 +05301021 doc.insert(ignore_if_duplicate=True)
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301022 except frappe.NameError:
Faris Ansariec7b0642019-05-14 16:21:09 +05301023 frappe.clear_messages()
Zarrar7f8024c2018-08-01 17:45:05 +05301024 except frappe.DuplicateEntryError:
Faris Ansariec7b0642019-05-14 16:21:09 +05301025 frappe.clear_messages()
Saurabh2d8a7ee2018-05-11 13:16:16 +05301026
Zarrar7f8024c2018-08-01 17:45:05 +05301027 # create records for Tax Withholding Category
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301028 set_tax_withholding_category(company)
1029
Ankush Menat494bd9e2022-03-28 18:52:46 +05301030
Deepesh Gargb3ed8072021-06-02 13:26:21 +05301031def update_regional_tax_settings(country, company):
Deepesh Garg1bac72b2021-05-02 22:29:48 +05301032 # Will only add default GST accounts if present
Ankush Menat494bd9e2022-03-28 18:52:46 +05301033 input_account_names = ["Input Tax CGST", "Input Tax SGST", "Input Tax IGST"]
1034 output_account_names = ["Output Tax CGST", "Output Tax SGST", "Output Tax IGST"]
1035 rcm_accounts = ["Input Tax CGST RCM", "Input Tax SGST RCM", "Input Tax IGST RCM"]
1036 gst_settings = frappe.get_single("GST Settings")
Deepesh Garg1bac72b2021-05-02 22:29:48 +05301037 existing_account_list = []
1038
Ankush Menat494bd9e2022-03-28 18:52:46 +05301039 for account in gst_settings.get("gst_accounts"):
1040 for key in ["cgst_account", "sgst_account", "igst_account"]:
Deepesh Garg1bac72b2021-05-02 22:29:48 +05301041 existing_account_list.append(account.get(key))
1042
Ankush Menat494bd9e2022-03-28 18:52:46 +05301043 gst_accounts = frappe._dict(
1044 frappe.get_all(
1045 "Account",
1046 {
1047 "company": company,
1048 "account_name": ("in", input_account_names + output_account_names + rcm_accounts),
1049 },
1050 ["account_name", "name"],
1051 as_list=1,
1052 )
1053 )
Deepesh Garg1bac72b2021-05-02 22:29:48 +05301054
Ankush Menat494bd9e2022-03-28 18:52:46 +05301055 add_accounts_in_gst_settings(
1056 company, input_account_names, gst_accounts, existing_account_list, gst_settings
1057 )
1058 add_accounts_in_gst_settings(
1059 company, output_account_names, gst_accounts, existing_account_list, gst_settings
1060 )
1061 add_accounts_in_gst_settings(
1062 company, rcm_accounts, gst_accounts, existing_account_list, gst_settings, is_reverse_charge=1
1063 )
Deepesh Garg1bac72b2021-05-02 22:29:48 +05301064
1065 gst_settings.save()
1066
Ankush Menat494bd9e2022-03-28 18:52:46 +05301067
1068def add_accounts_in_gst_settings(
1069 company, account_names, gst_accounts, existing_account_list, gst_settings, is_reverse_charge=0
1070):
Deepesh Garg48b1a822021-05-29 23:54:51 +05301071 accounts_not_added = 1
1072
1073 for account in account_names:
1074 # Default Account Added does not exists
1075 if not gst_accounts.get(account):
1076 accounts_not_added = 0
1077
1078 # Check if already added in GST Settings
1079 if gst_accounts.get(account) in existing_account_list:
1080 accounts_not_added = 0
1081
1082 if accounts_not_added:
Ankush Menat494bd9e2022-03-28 18:52:46 +05301083 gst_settings.append(
1084 "gst_accounts",
1085 {
1086 "company": company,
1087 "cgst_account": gst_accounts.get(account_names[0]),
1088 "sgst_account": gst_accounts.get(account_names[1]),
1089 "igst_account": gst_accounts.get(account_names[2]),
1090 "is_reverse_charge_account": is_reverse_charge,
1091 },
1092 )
1093
Deepesh Garg48b1a822021-05-29 23:54:51 +05301094
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301095def set_tax_withholding_category(company):
Saurabh2d8a7ee2018-05-11 13:16:16 +05301096 accounts = []
Saqibf8c1c732021-09-26 16:27:56 +05301097 fiscal_year_details = None
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301098 abbr = frappe.get_value("Company", company, "abbr")
Ankush Menat494bd9e2022-03-28 18:52:46 +05301099 tds_account = frappe.get_value("Account", "TDS Payable - {0}".format(abbr), "name")
Saurabh2d8a7ee2018-05-11 13:16:16 +05301100
1101 if company and tds_account:
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301102 accounts = [dict(company=company, account=tds_account)]
Saurabh2d8a7ee2018-05-11 13:16:16 +05301103
Anuja Pawar4569e522021-01-14 19:24:30 +05301104 try:
Subin Tom350ed1a2021-11-19 21:05:25 +05301105 fiscal_year_details = get_fiscal_year(today(), verbose=0)
Anuja Pawar4569e522021-01-14 19:24:30 +05301106 except FiscalYearError:
1107 pass
Ranjith Kurungadame51c1752018-07-24 11:07:28 +05301108
Deepesh Gargc53b78e2021-09-14 20:28:48 +05301109 docs = get_tds_details(accounts, fiscal_year_details)
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +05301110
Zarrar7f8024c2018-08-01 17:45:05 +05301111 for d in docs:
Deepesh Garg66a71bd2021-04-21 20:42:20 +05301112 if not frappe.db.exists("Tax Withholding Category", d.get("name")):
Zarrar7f8024c2018-08-01 17:45:05 +05301113 doc = frappe.get_doc(d)
Deepesh Garg204ea102021-04-30 16:35:52 +05301114 doc.flags.ignore_validate = True
Zarrar7f8024c2018-08-01 17:45:05 +05301115 doc.flags.ignore_permissions = True
Nabin Haitafef9c12019-02-12 11:28:20 +05301116 doc.flags.ignore_mandatory = True
Zarrar7f8024c2018-08-01 17:45:05 +05301117 doc.insert()
Deepesh Garg66a71bd2021-04-21 20:42:20 +05301118 else:
Deepesh Gargfea29ae2021-07-12 18:29:52 +05301119 doc = frappe.get_doc("Tax Withholding Category", d.get("name"), for_update=True)
Zarrar963d62b2019-03-23 10:30:12 +05301120
1121 if accounts:
1122 doc.append("accounts", accounts[0])
Zarrar7f8024c2018-08-01 17:45:05 +05301123
Deepesh Gargc53b78e2021-09-14 20:28:48 +05301124 if fiscal_year_details:
Anuja Pawar4569e522021-01-14 19:24:30 +05301125 # if fiscal year don't match with any of the already entered data, append rate row
Ankush Menat494bd9e2022-03-28 18:52:46 +05301126 fy_exist = [
1127 k
1128 for k in doc.get("rates")
1129 if k.get("from_date") <= fiscal_year_details[1] and k.get("to_date") >= fiscal_year_details[2]
1130 ]
Anuja Pawar4569e522021-01-14 19:24:30 +05301131 if not fy_exist:
Ankush Menat494bd9e2022-03-28 18:52:46 +05301132 doc.append("rates", d.get("rates")[0])
Rucha Mahabalbe2c1fc2021-03-11 13:19:44 +05301133
Anuja Pawar4569e522021-01-14 19:24:30 +05301134 doc.flags.ignore_permissions = True
Deepesh Garg48b1a822021-05-29 23:54:51 +05301135 doc.flags.ignore_validate = True
Anuja Pawar4569e522021-01-14 19:24:30 +05301136 doc.flags.ignore_mandatory = True
Deepesh Garg204ea102021-04-30 16:35:52 +05301137 doc.flags.ignore_links = True
Zarrar7f8024c2018-08-01 17:45:05 +05301138 doc.save()
Saurabh2d8a7ee2018-05-11 13:16:16 +05301139
Ankush Menat494bd9e2022-03-28 18:52:46 +05301140
Saurabh2d8a7ee2018-05-11 13:16:16 +05301141def set_tds_account(docs, company):
Ankush Menat494bd9e2022-03-28 18:52:46 +05301142 parent_account = frappe.db.get_value(
1143 "Account", filters={"account_name": "Duties and Taxes", "company": company}
1144 )
Nabin Haitf77cd542018-11-20 16:46:25 +05301145 if parent_account:
Ankush Menat494bd9e2022-03-28 18:52:46 +05301146 docs.extend(
1147 [
1148 {
1149 "doctype": "Account",
1150 "account_name": "TDS Payable",
1151 "account_type": "Tax",
1152 "parent_account": parent_account,
1153 "company": company,
1154 }
1155 ]
1156 )
1157
Zarrar7f8024c2018-08-01 17:45:05 +05301158
Deepesh Gargc53b78e2021-09-14 20:28:48 +05301159def get_tds_details(accounts, fiscal_year_details):
Zarrar7f8024c2018-08-01 17:45:05 +05301160 # bootstrap default tax withholding sections
1161 return [
Ankush Menat494bd9e2022-03-28 18:52:46 +05301162 dict(
1163 name="TDS - 194C - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301164 category_name="Payment to Contractors (Single / Aggregate)",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301165 doctype="Tax Withholding Category",
1166 accounts=accounts,
1167 rates=[
1168 {
1169 "from_date": fiscal_year_details[1],
1170 "to_date": fiscal_year_details[2],
1171 "tax_withholding_rate": 2,
1172 "single_threshold": 30000,
1173 "cumulative_threshold": 100000,
1174 }
1175 ],
1176 ),
1177 dict(
1178 name="TDS - 194C - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301179 category_name="Payment to Contractors (Single / Aggregate)",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301180 doctype="Tax Withholding Category",
1181 accounts=accounts,
1182 rates=[
1183 {
1184 "from_date": fiscal_year_details[1],
1185 "to_date": fiscal_year_details[2],
1186 "tax_withholding_rate": 1,
1187 "single_threshold": 30000,
1188 "cumulative_threshold": 100000,
1189 }
1190 ],
1191 ),
1192 dict(
1193 name="TDS - 194C - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301194 category_name="Payment to Contractors (Single / Aggregate)",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301195 doctype="Tax Withholding Category",
1196 accounts=accounts,
1197 rates=[
1198 {
1199 "from_date": fiscal_year_details[1],
1200 "to_date": fiscal_year_details[2],
1201 "tax_withholding_rate": 20,
1202 "single_threshold": 30000,
1203 "cumulative_threshold": 100000,
1204 }
1205 ],
1206 ),
1207 dict(
1208 name="TDS - 194D - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301209 category_name="Insurance Commission",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301210 doctype="Tax Withholding Category",
1211 accounts=accounts,
1212 rates=[
1213 {
1214 "from_date": fiscal_year_details[1],
1215 "to_date": fiscal_year_details[2],
1216 "tax_withholding_rate": 5,
1217 "single_threshold": 15000,
1218 "cumulative_threshold": 0,
1219 }
1220 ],
1221 ),
1222 dict(
1223 name="TDS - 194D - Company Assessee",
Zarrar7f8024c2018-08-01 17:45:05 +05301224 category_name="Insurance Commission",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301225 doctype="Tax Withholding Category",
1226 accounts=accounts,
1227 rates=[
1228 {
1229 "from_date": fiscal_year_details[1],
1230 "to_date": fiscal_year_details[2],
1231 "tax_withholding_rate": 10,
1232 "single_threshold": 15000,
1233 "cumulative_threshold": 0,
1234 }
1235 ],
1236 ),
1237 dict(
1238 name="TDS - 194D - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301239 category_name="Insurance Commission",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301240 doctype="Tax Withholding Category",
1241 accounts=accounts,
1242 rates=[
1243 {
1244 "from_date": fiscal_year_details[1],
1245 "to_date": fiscal_year_details[2],
1246 "tax_withholding_rate": 5,
1247 "single_threshold": 15000,
1248 "cumulative_threshold": 0,
1249 }
1250 ],
1251 ),
1252 dict(
1253 name="TDS - 194D - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301254 category_name="Insurance Commission",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301255 doctype="Tax Withholding Category",
1256 accounts=accounts,
1257 rates=[
1258 {
1259 "from_date": fiscal_year_details[1],
1260 "to_date": fiscal_year_details[2],
1261 "tax_withholding_rate": 20,
1262 "single_threshold": 15000,
1263 "cumulative_threshold": 0,
1264 }
1265 ],
1266 ),
1267 dict(
1268 name="TDS - 194DA - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301269 category_name="Non-exempt payments made under a life insurance policy",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301270 doctype="Tax Withholding Category",
1271 accounts=accounts,
1272 rates=[
1273 {
1274 "from_date": fiscal_year_details[1],
1275 "to_date": fiscal_year_details[2],
1276 "tax_withholding_rate": 1,
1277 "single_threshold": 100000,
1278 "cumulative_threshold": 0,
1279 }
1280 ],
1281 ),
1282 dict(
1283 name="TDS - 194DA - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301284 category_name="Non-exempt payments made under a life insurance policy",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301285 doctype="Tax Withholding Category",
1286 accounts=accounts,
1287 rates=[
1288 {
1289 "from_date": fiscal_year_details[1],
1290 "to_date": fiscal_year_details[2],
1291 "tax_withholding_rate": 1,
1292 "single_threshold": 100000,
1293 "cumulative_threshold": 0,
1294 }
1295 ],
1296 ),
1297 dict(
1298 name="TDS - 194DA - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301299 category_name="Non-exempt payments made under a life insurance policy",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301300 doctype="Tax Withholding Category",
1301 accounts=accounts,
1302 rates=[
1303 {
1304 "from_date": fiscal_year_details[1],
1305 "to_date": fiscal_year_details[2],
1306 "tax_withholding_rate": 20,
1307 "single_threshold": 100000,
1308 "cumulative_threshold": 0,
1309 }
1310 ],
1311 ),
1312 dict(
1313 name="TDS - 194H - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301314 category_name="Commission / Brokerage",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301315 doctype="Tax Withholding Category",
1316 accounts=accounts,
1317 rates=[
1318 {
1319 "from_date": fiscal_year_details[1],
1320 "to_date": fiscal_year_details[2],
1321 "tax_withholding_rate": 5,
1322 "single_threshold": 15000,
1323 "cumulative_threshold": 0,
1324 }
1325 ],
1326 ),
1327 dict(
1328 name="TDS - 194H - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301329 category_name="Commission / Brokerage",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301330 doctype="Tax Withholding Category",
1331 accounts=accounts,
1332 rates=[
1333 {
1334 "from_date": fiscal_year_details[1],
1335 "to_date": fiscal_year_details[2],
1336 "tax_withholding_rate": 5,
1337 "single_threshold": 15000,
1338 "cumulative_threshold": 0,
1339 }
1340 ],
1341 ),
1342 dict(
1343 name="TDS - 194H - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301344 category_name="Commission / Brokerage",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301345 doctype="Tax Withholding Category",
1346 accounts=accounts,
1347 rates=[
1348 {
1349 "from_date": fiscal_year_details[1],
1350 "to_date": fiscal_year_details[2],
1351 "tax_withholding_rate": 20,
1352 "single_threshold": 15000,
1353 "cumulative_threshold": 0,
1354 }
1355 ],
1356 ),
1357 dict(
1358 name="TDS - 194I - Rent - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301359 category_name="Rent",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301360 doctype="Tax Withholding Category",
1361 accounts=accounts,
1362 rates=[
1363 {
1364 "from_date": fiscal_year_details[1],
1365 "to_date": fiscal_year_details[2],
1366 "tax_withholding_rate": 10,
1367 "single_threshold": 180000,
1368 "cumulative_threshold": 0,
1369 }
1370 ],
1371 ),
1372 dict(
1373 name="TDS - 194I - Rent - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301374 category_name="Rent",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301375 doctype="Tax Withholding Category",
1376 accounts=accounts,
1377 rates=[
1378 {
1379 "from_date": fiscal_year_details[1],
1380 "to_date": fiscal_year_details[2],
1381 "tax_withholding_rate": 10,
1382 "single_threshold": 180000,
1383 "cumulative_threshold": 0,
1384 }
1385 ],
1386 ),
1387 dict(
1388 name="TDS - 194I - Rent - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301389 category_name="Rent",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301390 doctype="Tax Withholding Category",
1391 accounts=accounts,
1392 rates=[
1393 {
1394 "from_date": fiscal_year_details[1],
1395 "to_date": fiscal_year_details[2],
1396 "tax_withholding_rate": 20,
1397 "single_threshold": 180000,
1398 "cumulative_threshold": 0,
1399 }
1400 ],
1401 ),
1402 dict(
1403 name="TDS - 194I - Rent/Machinery - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301404 category_name="Rent-Plant / Machinery",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301405 doctype="Tax Withholding Category",
1406 accounts=accounts,
1407 rates=[
1408 {
1409 "from_date": fiscal_year_details[1],
1410 "to_date": fiscal_year_details[2],
1411 "tax_withholding_rate": 2,
1412 "single_threshold": 180000,
1413 "cumulative_threshold": 0,
1414 }
1415 ],
1416 ),
1417 dict(
1418 name="TDS - 194I - Rent/Machinery - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301419 category_name="Rent-Plant / Machinery",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301420 doctype="Tax Withholding Category",
1421 accounts=accounts,
1422 rates=[
1423 {
1424 "from_date": fiscal_year_details[1],
1425 "to_date": fiscal_year_details[2],
1426 "tax_withholding_rate": 2,
1427 "single_threshold": 180000,
1428 "cumulative_threshold": 0,
1429 }
1430 ],
1431 ),
1432 dict(
1433 name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301434 category_name="Rent-Plant / Machinery",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301435 doctype="Tax Withholding Category",
1436 accounts=accounts,
1437 rates=[
1438 {
1439 "from_date": fiscal_year_details[1],
1440 "to_date": fiscal_year_details[2],
1441 "tax_withholding_rate": 20,
1442 "single_threshold": 180000,
1443 "cumulative_threshold": 0,
1444 }
1445 ],
1446 ),
1447 dict(
1448 name="TDS - 194J - Professional Fees - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301449 category_name="Professional Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301450 doctype="Tax Withholding Category",
1451 accounts=accounts,
1452 rates=[
1453 {
1454 "from_date": fiscal_year_details[1],
1455 "to_date": fiscal_year_details[2],
1456 "tax_withholding_rate": 10,
1457 "single_threshold": 30000,
1458 "cumulative_threshold": 0,
1459 }
1460 ],
1461 ),
1462 dict(
1463 name="TDS - 194J - Professional Fees - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301464 category_name="Professional Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301465 doctype="Tax Withholding Category",
1466 accounts=accounts,
1467 rates=[
1468 {
1469 "from_date": fiscal_year_details[1],
1470 "to_date": fiscal_year_details[2],
1471 "tax_withholding_rate": 10,
1472 "single_threshold": 30000,
1473 "cumulative_threshold": 0,
1474 }
1475 ],
1476 ),
1477 dict(
1478 name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301479 category_name="Professional Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301480 doctype="Tax Withholding Category",
1481 accounts=accounts,
1482 rates=[
1483 {
1484 "from_date": fiscal_year_details[1],
1485 "to_date": fiscal_year_details[2],
1486 "tax_withholding_rate": 20,
1487 "single_threshold": 30000,
1488 "cumulative_threshold": 0,
1489 }
1490 ],
1491 ),
1492 dict(
1493 name="TDS - 194J - Director Fees - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301494 category_name="Director Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301495 doctype="Tax Withholding Category",
1496 accounts=accounts,
1497 rates=[
1498 {
1499 "from_date": fiscal_year_details[1],
1500 "to_date": fiscal_year_details[2],
1501 "tax_withholding_rate": 10,
1502 "single_threshold": 0,
1503 "cumulative_threshold": 0,
1504 }
1505 ],
1506 ),
1507 dict(
1508 name="TDS - 194J - Director Fees - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301509 category_name="Director Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301510 doctype="Tax Withholding Category",
1511 accounts=accounts,
1512 rates=[
1513 {
1514 "from_date": fiscal_year_details[1],
1515 "to_date": fiscal_year_details[2],
1516 "tax_withholding_rate": 10,
1517 "single_threshold": 0,
1518 "cumulative_threshold": 0,
1519 }
1520 ],
1521 ),
1522 dict(
1523 name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301524 category_name="Director Fees",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301525 doctype="Tax Withholding Category",
1526 accounts=accounts,
1527 rates=[
1528 {
1529 "from_date": fiscal_year_details[1],
1530 "to_date": fiscal_year_details[2],
1531 "tax_withholding_rate": 20,
1532 "single_threshold": 0,
1533 "cumulative_threshold": 0,
1534 }
1535 ],
1536 ),
1537 dict(
1538 name="TDS - 194 - Dividends - Company",
Zarrar7f8024c2018-08-01 17:45:05 +05301539 category_name="Dividends",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301540 doctype="Tax Withholding Category",
1541 accounts=accounts,
1542 rates=[
1543 {
1544 "from_date": fiscal_year_details[1],
1545 "to_date": fiscal_year_details[2],
1546 "tax_withholding_rate": 10,
1547 "single_threshold": 2500,
1548 "cumulative_threshold": 0,
1549 }
1550 ],
1551 ),
1552 dict(
1553 name="TDS - 194 - Dividends - Individual",
Zarrar7f8024c2018-08-01 17:45:05 +05301554 category_name="Dividends",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301555 doctype="Tax Withholding Category",
1556 accounts=accounts,
1557 rates=[
1558 {
1559 "from_date": fiscal_year_details[1],
1560 "to_date": fiscal_year_details[2],
1561 "tax_withholding_rate": 10,
1562 "single_threshold": 2500,
1563 "cumulative_threshold": 0,
1564 }
1565 ],
1566 ),
1567 dict(
1568 name="TDS - 194 - Dividends - No PAN / Invalid PAN",
Zarrar7f8024c2018-08-01 17:45:05 +05301569 category_name="Dividends",
Ankush Menat494bd9e2022-03-28 18:52:46 +05301570 doctype="Tax Withholding Category",
1571 accounts=accounts,
1572 rates=[
1573 {
1574 "from_date": fiscal_year_details[1],
1575 "to_date": fiscal_year_details[2],
1576 "tax_withholding_rate": 20,
1577 "single_threshold": 2500,
1578 "cumulative_threshold": 0,
1579 }
1580 ],
1581 ),
Anurag Mishrae1464a72020-08-17 15:03:32 +05301582 ]
1583
Ankush Menat494bd9e2022-03-28 18:52:46 +05301584
Deepesh Garg204ea102021-04-30 16:35:52 +05301585def update_accounts_settings_for_taxes():
Ankush Menat494bd9e2022-03-28 18:52:46 +05301586 if frappe.db.count("Company") == 1:
1587 frappe.db.set_value("Accounts Settings", None, "add_taxes_from_item_tax_template", 0)