Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | |
| 6 | import frappe, os, json |
Rushabh Mehta | f056974 | 2017-09-13 12:52:30 +0530 | [diff] [blame] | 7 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
Nabin Hait | 49b41e4 | 2019-01-24 17:55:44 +0530 | [diff] [blame] | 8 | from frappe.permissions import add_permission, update_permission_property |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 9 | from erpnext.regional.india import states |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 10 | from erpnext.accounts.utils import get_fiscal_year |
| 11 | from frappe.utils import today |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 12 | |
Rushabh Mehta | 0165927 | 2017-06-27 18:05:17 +0530 | [diff] [blame] | 13 | def setup(company=None, patch=True): |
Prateeksha Singh | dabf349 | 2018-11-13 15:56:15 +0530 | [diff] [blame] | 14 | setup_company_independent_fixtures() |
Prateeksha Singh | 39b8765 | 2018-11-12 17:19:56 +0530 | [diff] [blame] | 15 | if not patch: |
| 16 | update_address_template() |
Prateeksha Singh | dabf349 | 2018-11-13 15:56:15 +0530 | [diff] [blame] | 17 | make_fixtures(company) |
Prateeksha Singh | 39b8765 | 2018-11-12 17:19:56 +0530 | [diff] [blame] | 18 | |
| 19 | # TODO: for all countries |
| 20 | def setup_company_independent_fixtures(): |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 21 | make_custom_fields() |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 22 | add_permissions() |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 23 | add_custom_roles_for_reports() |
Nabin Hait | c314485 | 2017-09-28 18:55:40 +0530 | [diff] [blame] | 24 | frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test) |
Nabin Hait | 852cb64 | 2017-07-05 12:58:19 +0530 | [diff] [blame] | 25 | add_print_formats() |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 26 | |
| 27 | def 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 Mehta | 9b09ff2 | 2017-06-27 12:17:39 +0530 | [diff] [blame] | 36 | frappe.get_doc(dict( |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 37 | doctype='Address Template', |
| 38 | country='India', |
| 39 | template=html |
Rushabh Mehta | 9b09ff2 | 2017-06-27 12:17:39 +0530 | [diff] [blame] | 40 | )).insert() |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 41 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 42 | def add_hsn_sac_codes(): |
| 43 | # HSN codes |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 44 | 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 Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 47 | create_hsn_codes(hsn_codes, code_field="hsn_code") |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 48 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 49 | # 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 Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 53 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 54 | def create_hsn_codes(data, code_field): |
| 55 | for d in data: |
Rushabh Mehta | f702d72 | 2017-09-27 15:31:30 +0530 | [diff] [blame] | 56 | 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 Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 61 | hsn_code.db_insert() |
Rushabh Mehta | f702d72 | 2017-09-27 15:31:30 +0530 | [diff] [blame] | 62 | except frappe.DuplicateEntryError: |
| 63 | pass |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 65 | def add_custom_roles_for_reports(): |
| 66 | for report_name in ('GST Sales Register', 'GST Purchase Register', |
rohitwaghchaure | 8cca61f | 2018-08-20 17:53:56 +0530 | [diff] [blame] | 67 | 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'): |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 68 | |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 69 | 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 Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 79 | def add_permissions(): |
Rushabh Mehta | 00ae424 | 2017-06-27 17:31:41 +0530 | [diff] [blame] | 80 | for doctype in ('GST HSN Code', 'GST Settings'): |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 81 | add_permission(doctype, 'All', 0) |
Saqib | 5e6ce88 | 2020-02-03 15:40:35 +0530 | [diff] [blame] | 82 | for role in ('Accounts Manager', 'System Manager', 'Item Manager', 'Stock Manager'): |
| 83 | add_permission(doctype, role, 0) |
| 84 | update_permission_property(doctype, role, 0, 'write', 1) |
| 85 | update_permission_property(doctype, role, 0, 'create', 1) |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 86 | |
Nabin Hait | 852cb64 | 2017-07-05 12:58:19 +0530 | [diff] [blame] | 87 | def add_print_formats(): |
| 88 | frappe.reload_doc("regional", "print_format", "gst_tax_invoice") |
rohitwaghchaure | e3b5c0f | 2017-12-16 10:53:53 +0530 | [diff] [blame] | 89 | frappe.reload_doc("accounts", "print_format", "gst_pos_invoice") |
| 90 | |
| 91 | frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where |
| 92 | name in('GST POS Invoice', 'GST Tax Invoice') """) |
Nabin Hait | 852cb64 | 2017-07-05 12:58:19 +0530 | [diff] [blame] | 93 | |
Rushabh Mehta | 69fa808 | 2018-07-17 18:22:51 +0530 | [diff] [blame] | 94 | def make_custom_fields(update=True): |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 95 | hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', |
Nabin Hait | d34bfa8 | 2018-11-13 18:19:58 +0530 | [diff] [blame] | 96 | fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description', |
Nabin Hait | f4af608 | 2019-04-01 11:51:54 +0530 | [diff] [blame] | 97 | allow_on_submit=1, print_hide=1, fetch_if_empty=1) |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 98 | nil_rated_exempt = dict(fieldname='is_nil_exempt', label='Is nil rated or exempted', |
| 99 | fieldtype='Check', fetch_from='item_code.is_nil_exempt', insert_after='gst_hsn_code', |
| 100 | print_hide=1) |
| 101 | is_non_gst = dict(fieldname='is_non_gst', label='Is Non GST', |
| 102 | fieldtype='Check', fetch_from='item_code.is_non_gst', insert_after='is_nil_exempt', |
| 103 | print_hide=1) |
| 104 | |
| 105 | purchase_invoice_gst_category = [ |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 106 | dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break', |
vishdha | 109b408 | 2018-01-30 12:11:13 +0530 | [diff] [blame] | 107 | insert_after='language', print_hide=1, collapsible=1), |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 108 | dict(fieldname='gst_category', label='GST Category', |
Nabin Hait | 10dae5d | 2019-04-01 20:56:51 +0530 | [diff] [blame] | 109 | fieldtype='Select', insert_after='gst_section', print_hide=1, |
Nabin Hait | 89b0613 | 2019-05-01 14:18:21 +0530 | [diff] [blame] | 110 | options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 111 | fetch_from='supplier.gst_category', fetch_if_empty=1), |
| 112 | dict(fieldname='export_type', label='Export Type', |
| 113 | fieldtype='Select', insert_after='gst_category', print_hide=1, |
| 114 | depends_on='eval:in_list(["SEZ", "Overseas"], doc.gst_category)', |
| 115 | options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='supplier.export_type', |
| 116 | fetch_if_empty=1), |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 117 | ] |
| 118 | |
| 119 | sales_invoice_gst_category = [ |
| 120 | dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break', |
| 121 | insert_after='language', print_hide=1, collapsible=1), |
| 122 | dict(fieldname='gst_category', label='GST Category', |
Nabin Hait | 10dae5d | 2019-04-01 20:56:51 +0530 | [diff] [blame] | 123 | fieldtype='Select', insert_after='gst_section', print_hide=1, |
Nabin Hait | 89b0613 | 2019-05-01 14:18:21 +0530 | [diff] [blame] | 124 | options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 125 | fetch_from='customer.gst_category', fetch_if_empty=1), |
| 126 | dict(fieldname='export_type', label='Export Type', |
| 127 | fieldtype='Select', insert_after='gst_category', print_hide=1, |
| 128 | depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)', |
| 129 | options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='customer.export_type', |
| 130 | fetch_if_empty=1), |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 131 | ] |
| 132 | |
| 133 | invoice_gst_fields = [ |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 134 | dict(fieldname='invoice_copy', label='Invoice Copy', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 135 | fieldtype='Select', insert_after='export_type', print_hide=1, allow_on_submit=1, |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 136 | options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'), |
| 137 | dict(fieldname='reverse_charge', label='Reverse Charge', |
| 138 | fieldtype='Select', insert_after='invoice_copy', print_hide=1, |
| 139 | options='Y\nN', default='N'), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 140 | dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN', |
Vishal Dhayagude | c463c06 | 2018-01-26 11:27:22 +0530 | [diff] [blame] | 141 | fieldtype='Data', insert_after='export_type', print_hide=1), |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 142 | dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'), |
Vishal Dhayagude | c463c06 | 2018-01-26 11:27:22 +0530 | [diff] [blame] | 143 | dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document', |
Nabin Hait | b02c109 | 2018-02-05 16:09:51 +0530 | [diff] [blame] | 144 | fieldtype='Select', insert_after='gst_col_break', print_hide=1, |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 145 | depends_on='eval:doc.is_return==1', |
Nabin Hait | a8d10b7 | 2018-02-12 16:54:13 +0530 | [diff] [blame] | 146 | 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 Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 147 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 148 | |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 149 | purchase_invoice_gst_fields = [ |
| 150 | dict(fieldname='supplier_gstin', label='Supplier GSTIN', |
| 151 | fieldtype='Data', insert_after='supplier_address', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 152 | fetch_from='supplier_address.gstin', print_hide=1, read_only=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 153 | dict(fieldname='company_gstin', label='Company GSTIN', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 154 | fieldtype='Data', insert_after='shipping_address_display', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 155 | fetch_from='shipping_address.gstin', print_hide=1, read_only=1), |
Nabin Hait | b02c109 | 2018-02-05 16:09:51 +0530 | [diff] [blame] | 156 | dict(fieldname='place_of_supply', label='Place of Supply', |
| 157 | fieldtype='Data', insert_after='shipping_address', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 158 | print_hide=1, read_only=1), |
deepeshgarg007 | d29ee97 | 2019-01-09 17:09:11 +0530 | [diff] [blame] | 159 | ] |
| 160 | |
| 161 | purchase_invoice_itc_fields = [ |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 162 | dict(fieldname='eligibility_for_itc', label='Eligibility For ITC', |
| 163 | fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1, |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 164 | options='Input Service Distributor\nImport Of Service\nImport Of Capital Goods\nIneligible\nAll Other ITC', default="All Other ITC"), |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 165 | dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax', |
| 166 | fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1), |
| 167 | dict(fieldname='itc_central_tax', label='Availed ITC Central Tax', |
| 168 | fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1), |
| 169 | dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax', |
| 170 | fieldtype='Data', insert_after='itc_central_tax', print_hide=1), |
| 171 | dict(fieldname='itc_cess_amount', label='Availed ITC Cess', |
| 172 | fieldtype='Data', insert_after='itc_state_tax', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 173 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 174 | |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 175 | sales_invoice_gst_fields = [ |
rohitwaghchaure | 1664580 | 2017-09-28 11:05:03 +0530 | [diff] [blame] | 176 | dict(fieldname='billing_address_gstin', label='Billing Address GSTIN', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 177 | fieldtype='Data', insert_after='customer_address', read_only=1, |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 178 | fetch_from='customer_address.gstin', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 179 | dict(fieldname='customer_gstin', label='Customer GSTIN', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 180 | fieldtype='Data', insert_after='shipping_address_name', |
| 181 | fetch_from='shipping_address_name.gstin', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 182 | dict(fieldname='place_of_supply', label='Place of Supply', |
Nabin Hait | 619c42b | 2018-01-10 17:48:03 +0530 | [diff] [blame] | 183 | fieldtype='Data', insert_after='customer_gstin', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 184 | print_hide=1, read_only=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 185 | dict(fieldname='company_gstin', label='Company GSTIN', |
| 186 | fieldtype='Data', insert_after='company_address', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 187 | fetch_from='company_address.gstin', print_hide=1, read_only=1), |
deepeshgarg007 | d29ee97 | 2019-01-09 17:09:11 +0530 | [diff] [blame] | 188 | ] |
| 189 | |
| 190 | sales_invoice_shipping_fields = [ |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 191 | dict(fieldname='port_code', label='Port Code', |
| 192 | fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1, |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 193 | depends_on="eval:doc.gst_category=='Overseas' "), |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 194 | dict(fieldname='shipping_bill_number', label=' Shipping Bill Number', |
| 195 | fieldtype='Data', insert_after='port_code', print_hide=1, |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 196 | depends_on="eval:doc.gst_category=='Overseas' "), |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 197 | dict(fieldname='shipping_bill_date', label='Shipping Bill Date', |
| 198 | fieldtype='Date', insert_after='shipping_bill_number', print_hide=1, |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 199 | depends_on="eval:doc.gst_category=='Overseas' "), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 200 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 201 | |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 202 | inter_state_gst_field = [ |
| 203 | dict(fieldname='is_inter_state', label='Is Inter State', |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 204 | fieldtype='Check', insert_after='disabled', print_hide=1), |
| 205 | dict(fieldname='tax_category_column_break', fieldtype='Column Break', |
| 206 | insert_after='is_inter_state'), |
| 207 | dict(fieldname='gst_state', label='Source State', fieldtype='Select', |
| 208 | options='\n'.join(states), insert_after='company') |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 209 | ] |
| 210 | |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 211 | ewaybill_fields = [ |
| 212 | { |
| 213 | 'fieldname': 'distance', |
| 214 | 'label': 'Distance (in km)', |
| 215 | 'fieldtype': 'Float', |
| 216 | 'insert_after': 'vehicle_no', |
| 217 | 'print_hide': 1 |
| 218 | }, |
| 219 | { |
| 220 | 'fieldname': 'gst_transporter_id', |
| 221 | 'label': 'GST Transporter ID', |
| 222 | 'fieldtype': 'Data', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 223 | 'insert_after': 'transporter', |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 224 | 'fetch_from': 'transporter.gst_transporter_id', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 225 | 'print_hide': 1, |
| 226 | 'translatable': 0 |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 227 | }, |
| 228 | { |
| 229 | 'fieldname': 'mode_of_transport', |
| 230 | 'label': 'Mode of Transport', |
| 231 | 'fieldtype': 'Select', |
| 232 | 'options': '\nRoad\nAir\nRail\nShip', |
| 233 | 'default': 'Road', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 234 | 'insert_after': 'transporter_name', |
| 235 | 'print_hide': 1, |
| 236 | 'translatable': 0 |
| 237 | }, |
| 238 | { |
| 239 | 'fieldname': 'gst_vehicle_type', |
| 240 | 'label': 'GST Vehicle Type', |
| 241 | 'fieldtype': 'Select', |
| 242 | 'options': 'Regular\nOver Dimensional Cargo (ODC)', |
| 243 | 'depends_on': 'eval:(doc.mode_of_transport === "Road")', |
| 244 | 'default': 'Regular', |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 245 | 'insert_after': 'lr_date', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 246 | 'print_hide': 1, |
| 247 | 'translatable': 0 |
| 248 | } |
| 249 | ] |
| 250 | |
| 251 | si_ewaybill_fields = [ |
| 252 | { |
| 253 | 'fieldname': 'transporter_info', |
| 254 | 'label': 'Transporter Info', |
| 255 | 'fieldtype': 'Section Break', |
| 256 | 'insert_after': 'terms', |
| 257 | 'collapsible': 1, |
| 258 | 'collapsible_depends_on': 'transporter', |
| 259 | 'print_hide': 1 |
| 260 | }, |
| 261 | { |
| 262 | 'fieldname': 'transporter', |
| 263 | 'label': 'Transporter', |
| 264 | 'fieldtype': 'Link', |
| 265 | 'insert_after': 'transporter_info', |
| 266 | 'options': 'Supplier', |
| 267 | 'print_hide': 1 |
| 268 | }, |
| 269 | { |
| 270 | 'fieldname': 'gst_transporter_id', |
| 271 | 'label': 'GST Transporter ID', |
| 272 | 'fieldtype': 'Data', |
| 273 | 'insert_after': 'transporter', |
| 274 | 'fetch_from': 'transporter.gst_transporter_id', |
| 275 | 'print_hide': 1, |
| 276 | 'translatable': 0 |
| 277 | }, |
| 278 | { |
| 279 | 'fieldname': 'driver', |
| 280 | 'label': 'Driver', |
| 281 | 'fieldtype': 'Link', |
| 282 | 'insert_after': 'gst_transporter_id', |
| 283 | 'options': 'Driver', |
| 284 | 'print_hide': 1 |
| 285 | }, |
| 286 | { |
| 287 | 'fieldname': 'lr_no', |
| 288 | 'label': 'Transport Receipt No', |
| 289 | 'fieldtype': 'Data', |
| 290 | 'insert_after': 'driver', |
| 291 | 'print_hide': 1, |
| 292 | 'translatable': 0 |
| 293 | }, |
| 294 | { |
| 295 | 'fieldname': 'vehicle_no', |
| 296 | 'label': 'Vehicle No', |
| 297 | 'fieldtype': 'Data', |
| 298 | 'insert_after': 'lr_no', |
| 299 | 'print_hide': 1, |
| 300 | 'translatable': 0 |
| 301 | }, |
| 302 | { |
| 303 | 'fieldname': 'distance', |
| 304 | 'label': 'Distance (in km)', |
| 305 | 'fieldtype': 'Float', |
| 306 | 'insert_after': 'vehicle_no', |
| 307 | 'print_hide': 1 |
| 308 | }, |
| 309 | { |
| 310 | 'fieldname': 'transporter_col_break', |
| 311 | 'fieldtype': 'Column Break', |
| 312 | 'insert_after': 'distance' |
| 313 | }, |
| 314 | { |
| 315 | 'fieldname': 'transporter_name', |
| 316 | 'label': 'Transporter Name', |
| 317 | 'fieldtype': 'Data', |
| 318 | 'insert_after': 'transporter_col_break', |
| 319 | 'fetch_from': 'transporter.name', |
| 320 | 'read_only': 1, |
| 321 | 'print_hide': 1, |
| 322 | 'translatable': 0 |
| 323 | }, |
| 324 | { |
| 325 | 'fieldname': 'mode_of_transport', |
| 326 | 'label': 'Mode of Transport', |
| 327 | 'fieldtype': 'Select', |
| 328 | 'options': '\nRoad\nAir\nRail\nShip', |
| 329 | 'default': 'Road', |
| 330 | 'insert_after': 'transporter_name', |
| 331 | 'print_hide': 1, |
| 332 | 'translatable': 0 |
| 333 | }, |
| 334 | { |
| 335 | 'fieldname': 'driver_name', |
| 336 | 'label': 'Driver Name', |
| 337 | 'fieldtype': 'Data', |
| 338 | 'insert_after': 'mode_of_transport', |
| 339 | 'fetch_from': 'driver.full_name', |
| 340 | 'print_hide': 1, |
| 341 | 'translatable': 0 |
| 342 | }, |
| 343 | { |
| 344 | 'fieldname': 'lr_date', |
| 345 | 'label': 'Transport Receipt Date', |
| 346 | 'fieldtype': 'Date', |
| 347 | 'insert_after': 'driver_name', |
| 348 | 'default': 'Today', |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 349 | 'print_hide': 1 |
| 350 | }, |
| 351 | { |
| 352 | 'fieldname': 'gst_vehicle_type', |
| 353 | 'label': 'GST Vehicle Type', |
| 354 | 'fieldtype': 'Select', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 355 | 'options': 'Regular\nOver Dimensional Cargo (ODC)', |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 356 | 'depends_on': 'eval:(doc.mode_of_transport === "Road")', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 357 | 'default': 'Regular', |
| 358 | 'insert_after': 'lr_date', |
| 359 | 'print_hide': 1, |
| 360 | 'translatable': 0 |
| 361 | }, |
| 362 | { |
| 363 | 'fieldname': 'ewaybill', |
| 364 | 'label': 'e-Way Bill No.', |
| 365 | 'fieldtype': 'Data', |
| 366 | 'depends_on': 'eval:(doc.docstatus === 1)', |
| 367 | 'allow_on_submit': 1, |
deepeshgarg007 | a85db66 | 2019-07-14 18:15:19 +0530 | [diff] [blame] | 368 | 'insert_after': 'tax_id', |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 369 | 'translatable': 0 |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 370 | } |
| 371 | ] |
| 372 | |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 373 | custom_fields = { |
| 374 | 'Address': [ |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 375 | dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data', |
| 376 | insert_after='fax'), |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 377 | dict(fieldname='gst_state', label='GST State', fieldtype='Select', |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 378 | options='\n'.join(states), insert_after='gstin'), |
| 379 | dict(fieldname='gst_state_number', label='GST State Number', |
Nabin Hait | 562d942 | 2018-09-07 16:14:44 +0530 | [diff] [blame] | 380 | fieldtype='Data', insert_after='gst_state', read_only=1), |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 381 | ], |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 382 | 'Purchase Invoice': purchase_invoice_gst_category + invoice_gst_fields + purchase_invoice_itc_fields + purchase_invoice_gst_fields, |
deepeshgarg007 | d29ee97 | 2019-01-09 17:09:11 +0530 | [diff] [blame] | 383 | 'Purchase Order': purchase_invoice_gst_fields, |
| 384 | 'Purchase Receipt': purchase_invoice_gst_fields, |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 385 | 'Sales Invoice': sales_invoice_gst_category + invoice_gst_fields + sales_invoice_shipping_fields + sales_invoice_gst_fields + si_ewaybill_fields, |
| 386 | 'Delivery Note': sales_invoice_gst_fields + ewaybill_fields + sales_invoice_shipping_fields, |
deepeshgarg007 | d29ee97 | 2019-01-09 17:09:11 +0530 | [diff] [blame] | 387 | 'Sales Order': sales_invoice_gst_fields, |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 388 | 'Tax Category': inter_state_gst_field, |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 389 | 'Item': [ |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 390 | dict(fieldname='gst_hsn_code', label='HSN/SAC', |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 391 | fieldtype='Link', options='GST HSN Code', insert_after='item_group'), |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 392 | dict(fieldname='is_nil_exempt', label='Is nil rated or exempted', |
| 393 | fieldtype='Check', insert_after='gst_hsn_code'), |
| 394 | dict(fieldname='is_non_gst', label='Is Non GST ', |
| 395 | fieldtype='Check', insert_after='is_nil_exempt') |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 396 | ], |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 397 | 'Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 398 | 'Supplier Quotation Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 399 | 'Sales Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 400 | 'Delivery Note Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 401 | 'Sales Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 402 | 'Purchase Order Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 403 | 'Purchase Receipt Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
| 404 | 'Purchase Invoice Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
Himanshu Warekar | 656d8e4 | 2019-04-01 19:38:43 +0530 | [diff] [blame] | 405 | 'Material Request Item': [hsn_sac_field, nil_rated_exempt, is_non_gst], |
Pawan Mehta | f419635 | 2018-04-05 14:54:51 +0530 | [diff] [blame] | 406 | 'Employee': [ |
| 407 | dict(fieldname='ifsc_code', label='IFSC Code', |
Rushabh Mehta | 369afce | 2018-04-26 10:10:03 +0530 | [diff] [blame] | 408 | fieldtype='Data', insert_after='bank_ac_no', print_hide=1, |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 409 | depends_on='eval:doc.salary_mode == "Bank"') |
| 410 | ], |
| 411 | 'Company': [ |
| 412 | dict(fieldname='hra_section', label='HRA Settings', |
Anurag Mishra | a552722 | 2019-06-14 15:25:57 +0530 | [diff] [blame] | 413 | fieldtype='Section Break', insert_after='asset_received_but_not_billed', collapsible=1), |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 414 | dict(fieldname='basic_component', label='Basic Component', |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 415 | fieldtype='Link', options='Salary Component', insert_after='hra_section'), |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 416 | dict(fieldname='hra_component', label='HRA Component', |
| 417 | fieldtype='Link', options='Salary Component', insert_after='basic_component'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 418 | dict(fieldname='arrear_component', label='Arrear Component', |
Mangesh-Khairnar | 9215de0 | 2019-05-06 16:24:10 +0530 | [diff] [blame] | 419 | fieldtype='Link', options='Salary Component', insert_after='hra_component'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 420 | ], |
| 421 | 'Employee Tax Exemption Declaration':[ |
| 422 | dict(fieldname='hra_section', label='HRA Exemption', |
| 423 | fieldtype='Section Break', insert_after='declarations'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 424 | dict(fieldname='monthly_house_rent', label='Monthly House Rent', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 425 | fieldtype='Currency', insert_after='hra_section'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 426 | dict(fieldname='rented_in_metro_city', label='Rented in Metro City', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 427 | fieldtype='Check', insert_after='monthly_house_rent', depends_on='monthly_house_rent'), |
| 428 | dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure', |
| 429 | fieldtype='Currency', insert_after='rented_in_metro_city', read_only=1, depends_on='monthly_house_rent'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 430 | dict(fieldname='hra_column_break', fieldtype='Column Break', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 431 | insert_after='salary_structure_hra', depends_on='monthly_house_rent'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 432 | dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 433 | fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='monthly_house_rent'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 434 | dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 435 | fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1, depends_on='monthly_house_rent') |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 436 | ], |
| 437 | 'Employee Tax Exemption Proof Submission': [ |
| 438 | dict(fieldname='hra_section', label='HRA Exemption', |
| 439 | fieldtype='Section Break', insert_after='tax_exemption_proofs'), |
| 440 | dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount', |
| 441 | fieldtype='Currency', insert_after='hra_section'), |
| 442 | dict(fieldname='rented_in_metro_city', label='Rented in Metro City', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 443 | fieldtype='Check', insert_after='house_rent_payment_amount', depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 444 | dict(fieldname='rented_from_date', label='Rented From Date', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 445 | fieldtype='Date', insert_after='rented_in_metro_city', depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 446 | dict(fieldname='rented_to_date', label='Rented To Date', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 447 | fieldtype='Date', insert_after='rented_from_date', depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 448 | dict(fieldname='hra_column_break', fieldtype='Column Break', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 449 | insert_after='rented_to_date', depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 450 | dict(fieldname='monthly_house_rent', label='Monthly House Rent', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 451 | fieldtype='Currency', insert_after='hra_column_break', read_only=1, depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 452 | dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 453 | fieldtype='Currency', insert_after='monthly_house_rent', read_only=1, depends_on='house_rent_payment_amount'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 454 | dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption', |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 455 | fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1, depends_on='house_rent_payment_amount') |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 456 | ], |
| 457 | 'Supplier': [ |
| 458 | { |
| 459 | 'fieldname': 'gst_transporter_id', |
| 460 | 'label': 'GST Transporter ID', |
| 461 | 'fieldtype': 'Data', |
| 462 | 'insert_after': 'supplier_type', |
| 463 | 'depends_on': 'eval:doc.is_transporter' |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 464 | }, |
| 465 | { |
| 466 | 'fieldname': 'gst_category', |
| 467 | 'label': 'GST Category', |
| 468 | 'fieldtype': 'Select', |
| 469 | 'insert_after': 'gst_transporter_id', |
| 470 | 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nUIN Holders', |
| 471 | 'default': 'Unregistered' |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 472 | }, |
| 473 | { |
| 474 | 'fieldname': 'export_type', |
| 475 | 'label': 'Export Type', |
| 476 | 'fieldtype': 'Select', |
| 477 | 'insert_after': 'gst_category', |
| 478 | 'default': 'Without Payment of Tax', |
| 479 | 'depends_on':'eval:in_list(["SEZ", "Overseas"], doc.gst_category)', |
| 480 | 'options': '\nWith Payment of Tax\nWithout Payment of Tax' |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 481 | } |
| 482 | ], |
| 483 | 'Customer': [ |
| 484 | { |
| 485 | 'fieldname': 'gst_category', |
| 486 | 'label': 'GST Category', |
| 487 | 'fieldtype': 'Select', |
| 488 | 'insert_after': 'customer_type', |
| 489 | 'options': 'Registered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders', |
| 490 | 'default': 'Unregistered' |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 491 | }, |
| 492 | { |
| 493 | 'fieldname': 'export_type', |
| 494 | 'label': 'Export Type', |
| 495 | 'fieldtype': 'Select', |
| 496 | 'insert_after': 'gst_category', |
| 497 | 'default': 'Without Payment of Tax', |
| 498 | 'depends_on':'eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)', |
| 499 | 'options': '\nWith Payment of Tax\nWithout Payment of Tax' |
Sagar Vora | d92f3ac | 2018-10-10 14:51:26 +0530 | [diff] [blame] | 500 | } |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 501 | ] |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 502 | } |
Deepesh Garg | 22b6160 | 2019-03-21 20:47:47 +0530 | [diff] [blame] | 503 | create_custom_fields(custom_fields, update=update) |
Nabin Hait | 9c42161 | 2017-07-20 13:32:01 +0530 | [diff] [blame] | 504 | |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 505 | def make_fixtures(company=None): |
| 506 | docs = [] |
| 507 | company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company") |
| 508 | |
| 509 | set_salary_components(docs) |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 510 | set_tds_account(docs, company) |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 511 | |
| 512 | for d in docs: |
| 513 | try: |
| 514 | doc = frappe.get_doc(d) |
| 515 | doc.flags.ignore_permissions = True |
| 516 | doc.insert() |
| 517 | except frappe.NameError: |
Faris Ansari | ec7b064 | 2019-05-14 16:21:09 +0530 | [diff] [blame] | 518 | frappe.clear_messages() |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 519 | except frappe.DuplicateEntryError: |
Faris Ansari | ec7b064 | 2019-05-14 16:21:09 +0530 | [diff] [blame] | 520 | frappe.clear_messages() |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 521 | |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 522 | # create records for Tax Withholding Category |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 523 | set_tax_withholding_category(company) |
| 524 | |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 525 | def set_salary_components(docs): |
| 526 | docs.extend([ |
| 527 | {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'}, |
| 528 | {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'}, |
| 529 | {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'}, |
| 530 | {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'}, |
| 531 | {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'}, |
| 532 | {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'} |
| 533 | ]) |
| 534 | |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 535 | def set_tax_withholding_category(company): |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 536 | accounts = [] |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 537 | abbr = frappe.get_value("Company", company, "abbr") |
| 538 | tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name') |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 539 | |
| 540 | if company and tds_account: |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 541 | accounts = [dict(company=company, account=tds_account)] |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 542 | |
Nabin Hait | afef9c1 | 2019-02-12 11:28:20 +0530 | [diff] [blame] | 543 | fiscal_year = get_fiscal_year(today(), company=company)[0] |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 544 | docs = get_tds_details(accounts, fiscal_year) |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 545 | |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 546 | for d in docs: |
| 547 | try: |
| 548 | doc = frappe.get_doc(d) |
| 549 | doc.flags.ignore_permissions = True |
Nabin Hait | afef9c1 | 2019-02-12 11:28:20 +0530 | [diff] [blame] | 550 | doc.flags.ignore_mandatory = True |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 551 | doc.insert() |
| 552 | except frappe.DuplicateEntryError: |
| 553 | doc = frappe.get_doc("Tax Withholding Category", d.get("name")) |
Zarrar | 963d62b | 2019-03-23 10:30:12 +0530 | [diff] [blame] | 554 | |
| 555 | if accounts: |
| 556 | doc.append("accounts", accounts[0]) |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 557 | |
| 558 | # if fiscal year don't match with any of the already entered data, append rate row |
| 559 | fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year] |
| 560 | if not fy_exist: |
| 561 | doc.append("rates", d.get('rates')[0]) |
| 562 | |
| 563 | doc.save() |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 564 | |
| 565 | def set_tds_account(docs, company): |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 566 | abbr = frappe.get_value("Company", company, "abbr") |
Nabin Hait | f77cd54 | 2018-11-20 16:46:25 +0530 | [diff] [blame] | 567 | parent_account = frappe.db.get_value("Account", filters = {"account_name": "Duties and Taxes", "company": company}) |
| 568 | if parent_account: |
| 569 | docs.extend([ |
| 570 | { |
| 571 | "doctype": "Account", |
| 572 | "account_name": "TDS Payable", |
| 573 | "account_type": "Tax", |
| 574 | "parent_account": parent_account, |
| 575 | "company": company |
| 576 | } |
| 577 | ]) |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 578 | |
| 579 | def get_tds_details(accounts, fiscal_year): |
| 580 | # bootstrap default tax withholding sections |
| 581 | return [ |
| 582 | dict(name="TDS - 194C - Company", |
| 583 | category_name="Payment to Contractors (Single / Aggregate)", |
| 584 | doctype="Tax Withholding Category", accounts=accounts, |
| 585 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 586 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 587 | dict(name="TDS - 194C - Individual", |
| 588 | category_name="Payment to Contractors (Single / Aggregate)", |
| 589 | doctype="Tax Withholding Category", accounts=accounts, |
| 590 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 591 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 592 | dict(name="TDS - 194C - No PAN / Invalid PAN", |
| 593 | category_name="Payment to Contractors (Single / Aggregate)", |
| 594 | doctype="Tax Withholding Category", accounts=accounts, |
| 595 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 596 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 597 | dict(name="TDS - 194D - Company", |
| 598 | category_name="Insurance Commission", |
| 599 | doctype="Tax Withholding Category", accounts=accounts, |
| 600 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 601 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 602 | dict(name="TDS - 194D - Company Assessee", |
| 603 | category_name="Insurance Commission", |
| 604 | doctype="Tax Withholding Category", accounts=accounts, |
| 605 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 606 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 607 | dict(name="TDS - 194D - Individual", |
| 608 | category_name="Insurance Commission", |
| 609 | doctype="Tax Withholding Category", accounts=accounts, |
| 610 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 611 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 612 | dict(name="TDS - 194D - No PAN / Invalid PAN", |
| 613 | category_name="Insurance Commission", |
| 614 | doctype="Tax Withholding Category", accounts=accounts, |
| 615 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 616 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 617 | dict(name="TDS - 194DA - Company", |
| 618 | category_name="Non-exempt payments made under a life insurance policy", |
| 619 | doctype="Tax Withholding Category", accounts=accounts, |
| 620 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 621 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 622 | dict(name="TDS - 194DA - Individual", |
| 623 | category_name="Non-exempt payments made under a life insurance policy", |
| 624 | doctype="Tax Withholding Category", accounts=accounts, |
| 625 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 626 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 627 | dict(name="TDS - 194DA - No PAN / Invalid PAN", |
| 628 | category_name="Non-exempt payments made under a life insurance policy", |
| 629 | doctype="Tax Withholding Category", accounts=accounts, |
| 630 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 631 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 632 | dict(name="TDS - 194H - Company", |
| 633 | category_name="Commission / Brokerage", |
| 634 | doctype="Tax Withholding Category", accounts=accounts, |
| 635 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 636 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 637 | dict(name="TDS - 194H - Individual", |
| 638 | category_name="Commission / Brokerage", |
| 639 | doctype="Tax Withholding Category", accounts=accounts, |
| 640 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 641 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 642 | dict(name="TDS - 194H - No PAN / Invalid PAN", |
| 643 | category_name="Commission / Brokerage", |
| 644 | doctype="Tax Withholding Category", accounts=accounts, |
| 645 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 646 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 647 | dict(name="TDS - 194I - Rent - Company", |
| 648 | category_name="Rent", |
| 649 | doctype="Tax Withholding Category", accounts=accounts, |
| 650 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 651 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 652 | dict(name="TDS - 194I - Rent - Individual", |
| 653 | category_name="Rent", |
| 654 | doctype="Tax Withholding Category", accounts=accounts, |
| 655 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 656 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 657 | dict(name="TDS - 194I - Rent - No PAN / Invalid PAN", |
| 658 | category_name="Rent", |
| 659 | doctype="Tax Withholding Category", accounts=accounts, |
| 660 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 661 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 662 | dict(name="TDS - 194I - Rent/Machinery - Company", |
| 663 | category_name="Rent-Plant / Machinery", |
| 664 | doctype="Tax Withholding Category", accounts=accounts, |
| 665 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 666 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 667 | dict(name="TDS - 194I - Rent/Machinery - Individual", |
| 668 | category_name="Rent-Plant / Machinery", |
| 669 | doctype="Tax Withholding Category", accounts=accounts, |
| 670 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 671 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 672 | dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN", |
| 673 | category_name="Rent-Plant / Machinery", |
| 674 | doctype="Tax Withholding Category", accounts=accounts, |
| 675 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 676 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 677 | dict(name="TDS - 194J - Professional Fees - Company", |
| 678 | category_name="Professional Fees", |
| 679 | doctype="Tax Withholding Category", accounts=accounts, |
| 680 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 681 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 682 | dict(name="TDS - 194J - Professional Fees - Individual", |
| 683 | category_name="Professional Fees", |
| 684 | doctype="Tax Withholding Category", accounts=accounts, |
| 685 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 686 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 687 | dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN", |
| 688 | category_name="Professional Fees", |
| 689 | doctype="Tax Withholding Category", accounts=accounts, |
| 690 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 691 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 692 | dict(name="TDS - 194J - Director Fees - Company", |
| 693 | category_name="Director Fees", |
| 694 | doctype="Tax Withholding Category", accounts=accounts, |
| 695 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 696 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 697 | dict(name="TDS - 194J - Director Fees - Individual", |
| 698 | category_name="Director Fees", |
| 699 | doctype="Tax Withholding Category", accounts=accounts, |
| 700 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 701 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 702 | dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN", |
| 703 | category_name="Director Fees", |
| 704 | doctype="Tax Withholding Category", accounts=accounts, |
| 705 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 706 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 707 | dict(name="TDS - 194 - Dividends - Company", |
| 708 | category_name="Dividends", |
| 709 | doctype="Tax Withholding Category", accounts=accounts, |
| 710 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 711 | "single_threshold": 2500, "cumulative_threshold": 0}]), |
| 712 | dict(name="TDS - 194 - Dividends - Individual", |
| 713 | category_name="Dividends", |
| 714 | doctype="Tax Withholding Category", accounts=accounts, |
| 715 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 716 | "single_threshold": 2500, "cumulative_threshold": 0}]), |
| 717 | dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN", |
| 718 | category_name="Dividends", |
| 719 | doctype="Tax Withholding Category", accounts=accounts, |
| 720 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 721 | "single_threshold": 2500, "cumulative_threshold": 0}]) |
Saqib | 5e6ce88 | 2020-02-03 15:40:35 +0530 | [diff] [blame] | 722 | ] |