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 |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 8 | from frappe.permissions import add_permission |
| 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): |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 14 | make_custom_fields() |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 15 | add_permissions() |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 16 | add_custom_roles_for_reports() |
Nabin Hait | c314485 | 2017-09-28 18:55:40 +0530 | [diff] [blame] | 17 | 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] | 18 | add_print_formats() |
Rushabh Mehta | 0165927 | 2017-06-27 18:05:17 +0530 | [diff] [blame] | 19 | if not patch: |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 20 | update_address_template() |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 21 | make_fixtures(company) |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 22 | |
| 23 | def update_address_template(): |
| 24 | with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f: |
| 25 | html = f.read() |
| 26 | |
| 27 | address_template = frappe.db.get_value('Address Template', 'India') |
| 28 | if address_template: |
| 29 | frappe.db.set_value('Address Template', 'India', 'template', html) |
| 30 | else: |
| 31 | # make new html template for India |
Rushabh Mehta | 9b09ff2 | 2017-06-27 12:17:39 +0530 | [diff] [blame] | 32 | frappe.get_doc(dict( |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 33 | doctype='Address Template', |
| 34 | country='India', |
| 35 | template=html |
Rushabh Mehta | 9b09ff2 | 2017-06-27 12:17:39 +0530 | [diff] [blame] | 36 | )).insert() |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 37 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 38 | def add_hsn_sac_codes(): |
| 39 | # HSN codes |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 40 | with open(os.path.join(os.path.dirname(__file__), 'hsn_code_data.json'), 'r') as f: |
| 41 | hsn_codes = json.loads(f.read()) |
| 42 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 43 | create_hsn_codes(hsn_codes, code_field="hsn_code") |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 44 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 45 | # SAC Codes |
| 46 | with open(os.path.join(os.path.dirname(__file__), 'sac_code_data.json'), 'r') as f: |
| 47 | sac_codes = json.loads(f.read()) |
| 48 | create_hsn_codes(sac_codes, code_field="sac_code") |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 49 | |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 50 | def create_hsn_codes(data, code_field): |
| 51 | for d in data: |
Rushabh Mehta | f702d72 | 2017-09-27 15:31:30 +0530 | [diff] [blame] | 52 | hsn_code = frappe.new_doc('GST HSN Code') |
| 53 | hsn_code.description = d["description"] |
| 54 | hsn_code.hsn_code = d[code_field] |
| 55 | hsn_code.name = d[code_field] |
| 56 | try: |
Nabin Hait | 1a60931 | 2017-07-13 12:16:04 +0530 | [diff] [blame] | 57 | hsn_code.db_insert() |
Rushabh Mehta | f702d72 | 2017-09-27 15:31:30 +0530 | [diff] [blame] | 58 | except frappe.DuplicateEntryError: |
| 59 | pass |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 60 | |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 61 | def add_custom_roles_for_reports(): |
| 62 | for report_name in ('GST Sales Register', 'GST Purchase Register', |
rohitwaghchaure | 8cca61f | 2018-08-20 17:53:56 +0530 | [diff] [blame] | 63 | 'GST Itemised Sales Register', 'GST Itemised Purchase Register', 'Eway Bill'): |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 65 | if not frappe.db.get_value('Custom Role', dict(report=report_name)): |
| 66 | frappe.get_doc(dict( |
| 67 | doctype='Custom Role', |
| 68 | report=report_name, |
| 69 | roles= [ |
| 70 | dict(role='Accounts User'), |
| 71 | dict(role='Accounts Manager') |
| 72 | ] |
| 73 | )).insert() |
| 74 | |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 75 | def add_permissions(): |
Rushabh Mehta | 00ae424 | 2017-06-27 17:31:41 +0530 | [diff] [blame] | 76 | for doctype in ('GST HSN Code', 'GST Settings'): |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 77 | add_permission(doctype, 'All', 0) |
| 78 | |
Nabin Hait | 852cb64 | 2017-07-05 12:58:19 +0530 | [diff] [blame] | 79 | def add_print_formats(): |
| 80 | frappe.reload_doc("regional", "print_format", "gst_tax_invoice") |
rohitwaghchaure | e3b5c0f | 2017-12-16 10:53:53 +0530 | [diff] [blame] | 81 | frappe.reload_doc("accounts", "print_format", "gst_pos_invoice") |
| 82 | |
| 83 | frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where |
| 84 | name in('GST POS Invoice', 'GST Tax Invoice') """) |
Nabin Hait | 852cb64 | 2017-07-05 12:58:19 +0530 | [diff] [blame] | 85 | |
Rushabh Mehta | 69fa808 | 2018-07-17 18:22:51 +0530 | [diff] [blame] | 86 | def make_custom_fields(update=True): |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 87 | hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', |
Nabin Hait | e5716e3 | 2017-09-11 19:21:37 +0530 | [diff] [blame] | 88 | fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description', |
| 89 | allow_on_submit=1, print_hide=1) |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 90 | invoice_gst_fields = [ |
| 91 | dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break', |
vishdha | 109b408 | 2018-01-30 12:11:13 +0530 | [diff] [blame] | 92 | insert_after='language', print_hide=1, collapsible=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 93 | dict(fieldname='invoice_copy', label='Invoice Copy', |
| 94 | fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1, |
| 95 | options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'), |
| 96 | dict(fieldname='reverse_charge', label='Reverse Charge', |
| 97 | fieldtype='Select', insert_after='invoice_copy', print_hide=1, |
| 98 | options='Y\nN', default='N'), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 99 | dict(fieldname='invoice_type', label='Invoice Type', |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 100 | fieldtype='Select', insert_after='invoice_copy', print_hide=1, |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 101 | options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'), |
| 102 | dict(fieldname='export_type', label='Export Type', |
| 103 | fieldtype='Select', insert_after='invoice_type', print_hide=1, |
| 104 | depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)', |
| 105 | options='\nWith Payment of Tax\nWithout Payment of Tax'), |
| 106 | dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN', |
Vishal Dhayagude | c463c06 | 2018-01-26 11:27:22 +0530 | [diff] [blame] | 107 | fieldtype='Data', insert_after='export_type', print_hide=1), |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 108 | dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'), |
Vishal Dhayagude | c463c06 | 2018-01-26 11:27:22 +0530 | [diff] [blame] | 109 | dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document', |
Nabin Hait | b02c109 | 2018-02-05 16:09:51 +0530 | [diff] [blame] | 110 | fieldtype='Select', insert_after='gst_col_break', print_hide=1, |
Nabin Hait | e6d65bc | 2018-02-14 17:44:06 +0530 | [diff] [blame] | 111 | depends_on='eval:doc.is_return==1', |
Nabin Hait | a8d10b7 | 2018-02-12 16:54:13 +0530 | [diff] [blame] | 112 | 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] | 113 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 114 | |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 115 | purchase_invoice_gst_fields = [ |
| 116 | dict(fieldname='supplier_gstin', label='Supplier GSTIN', |
| 117 | fieldtype='Data', insert_after='supplier_address', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 118 | fetch_from='supplier_address.gstin', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 119 | dict(fieldname='company_gstin', label='Company GSTIN', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 120 | fieldtype='Data', insert_after='shipping_address_display', |
| 121 | fetch_from='shipping_address.gstin', print_hide=1), |
Nabin Hait | b02c109 | 2018-02-05 16:09:51 +0530 | [diff] [blame] | 122 | dict(fieldname='place_of_supply', label='Place of Supply', |
| 123 | fieldtype='Data', insert_after='shipping_address', |
| 124 | print_hide=1, read_only=0), |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 125 | dict(fieldname='eligibility_for_itc', label='Eligibility For ITC', |
| 126 | fieldtype='Select', insert_after='reason_for_issuing_document', print_hide=1, |
| 127 | options='input\ninput service\ncapital goods\nineligible', default="ineligible"), |
| 128 | dict(fieldname='itc_integrated_tax', label='Availed ITC Integrated Tax', |
| 129 | fieldtype='Data', insert_after='eligibility_for_itc', print_hide=1), |
| 130 | dict(fieldname='itc_central_tax', label='Availed ITC Central Tax', |
| 131 | fieldtype='Data', insert_after='itc_integrated_tax', print_hide=1), |
| 132 | dict(fieldname='itc_state_tax', label='Availed ITC State/UT Tax', |
| 133 | fieldtype='Data', insert_after='itc_central_tax', print_hide=1), |
| 134 | dict(fieldname='itc_cess_amount', label='Availed ITC Cess', |
| 135 | fieldtype='Data', insert_after='itc_state_tax', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 136 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 137 | |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 138 | sales_invoice_gst_fields = [ |
rohitwaghchaure | 1664580 | 2017-09-28 11:05:03 +0530 | [diff] [blame] | 139 | dict(fieldname='billing_address_gstin', label='Billing Address GSTIN', |
| 140 | fieldtype='Data', insert_after='customer_address', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 141 | fetch_from='customer_address.gstin', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 142 | dict(fieldname='customer_gstin', label='Customer GSTIN', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 143 | fieldtype='Data', insert_after='shipping_address_name', |
| 144 | fetch_from='shipping_address_name.gstin', print_hide=1), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 145 | dict(fieldname='place_of_supply', label='Place of Supply', |
Nabin Hait | 619c42b | 2018-01-10 17:48:03 +0530 | [diff] [blame] | 146 | fieldtype='Data', insert_after='customer_gstin', |
| 147 | print_hide=1, read_only=0), |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 148 | dict(fieldname='company_gstin', label='Company GSTIN', |
| 149 | fieldtype='Data', insert_after='company_address', |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 150 | fetch_from='company_address.gstin', print_hide=1), |
vishdha | 98e33c3 | 2018-01-29 13:57:34 +0530 | [diff] [blame] | 151 | dict(fieldname='port_code', label='Port Code', |
| 152 | fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1, |
| 153 | depends_on="eval:doc.invoice_type=='Export' "), |
| 154 | dict(fieldname='shipping_bill_number', label=' Shipping Bill Number', |
| 155 | fieldtype='Data', insert_after='port_code', print_hide=1, |
| 156 | depends_on="eval:doc.invoice_type=='Export' "), |
| 157 | dict(fieldname='shipping_bill_date', label='Shipping Bill Date', |
| 158 | fieldtype='Date', insert_after='shipping_bill_number', print_hide=1, |
| 159 | depends_on="eval:doc.invoice_type=='Export' ") |
Nabin Hait | 879e162 | 2017-08-21 08:28:55 +0530 | [diff] [blame] | 160 | ] |
Prateeksha Singh | 95d8fd3 | 2017-09-04 11:14:04 +0530 | [diff] [blame] | 161 | |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 162 | inter_state_gst_field = [ |
| 163 | dict(fieldname='is_inter_state', label='Is Inter State', |
| 164 | fieldtype='Check', insert_after='disabled', print_hide=1) |
| 165 | ] |
| 166 | |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 167 | custom_fields = { |
| 168 | 'Address': [ |
Rushabh Mehta | 919a74a | 2017-06-22 16:37:04 +0530 | [diff] [blame] | 169 | dict(fieldname='gstin', label='Party GSTIN', fieldtype='Data', |
| 170 | insert_after='fax'), |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 171 | dict(fieldname='gst_state', label='GST State', fieldtype='Select', |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 172 | options='\n'.join(states), insert_after='gstin'), |
| 173 | dict(fieldname='gst_state_number', label='GST State Number', |
Nabin Hait | 562d942 | 2018-09-07 16:14:44 +0530 | [diff] [blame] | 174 | fieldtype='Data', insert_after='gst_state', read_only=1), |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 175 | ], |
Nabin Hait | b02c109 | 2018-02-05 16:09:51 +0530 | [diff] [blame] | 176 | 'Purchase Invoice': invoice_gst_fields + purchase_invoice_gst_fields, |
| 177 | 'Sales Invoice': invoice_gst_fields + sales_invoice_gst_fields, |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 178 | 'Delivery Note': sales_invoice_gst_fields, |
| 179 | 'Sales Taxes and Charges Template': inter_state_gst_field, |
| 180 | 'Purchase Taxes and Charges Template': inter_state_gst_field, |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 181 | 'Item': [ |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 182 | dict(fieldname='gst_hsn_code', label='HSN/SAC', |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 183 | fieldtype='Link', options='GST HSN Code', insert_after='item_group'), |
| 184 | ], |
Nabin Hait | 9c42161 | 2017-07-20 13:32:01 +0530 | [diff] [blame] | 185 | 'Quotation Item': [hsn_sac_field], |
| 186 | 'Supplier Quotation Item': [hsn_sac_field], |
Nabin Hait | f3f0dfe | 2017-07-06 14:49:34 +0530 | [diff] [blame] | 187 | 'Sales Order Item': [hsn_sac_field], |
| 188 | 'Delivery Note Item': [hsn_sac_field], |
| 189 | 'Sales Invoice Item': [hsn_sac_field], |
| 190 | 'Purchase Order Item': [hsn_sac_field], |
| 191 | 'Purchase Receipt Item': [hsn_sac_field], |
Pawan Mehta | f419635 | 2018-04-05 14:54:51 +0530 | [diff] [blame] | 192 | 'Purchase Invoice Item': [hsn_sac_field], |
| 193 | 'Employee': [ |
| 194 | dict(fieldname='ifsc_code', label='IFSC Code', |
Rushabh Mehta | 369afce | 2018-04-26 10:10:03 +0530 | [diff] [blame] | 195 | fieldtype='Data', insert_after='bank_ac_no', print_hide=1, |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 196 | depends_on='eval:doc.salary_mode == "Bank"') |
| 197 | ], |
| 198 | 'Company': [ |
| 199 | dict(fieldname='hra_section', label='HRA Settings', |
| 200 | fieldtype='Section Break', insert_after='asset_received_but_not_billed'), |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 201 | dict(fieldname='basic_component', label='Basic Component', |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 202 | fieldtype='Link', options='Salary Component', insert_after='hra_section'), |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 203 | dict(fieldname='hra_component', label='HRA Component', |
| 204 | fieldtype='Link', options='Salary Component', insert_after='basic_component'), |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 205 | dict(fieldname='arrear_component', label='Arrear Component', |
| 206 | fieldtype='Link', options='Salary Component', insert_after='hra_component') |
| 207 | ], |
| 208 | 'Employee Tax Exemption Declaration':[ |
| 209 | dict(fieldname='hra_section', label='HRA Exemption', |
| 210 | fieldtype='Section Break', insert_after='declarations'), |
| 211 | dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure', |
| 212 | fieldtype='Currency', insert_after='hra_section', read_only=1), |
| 213 | dict(fieldname='monthly_house_rent', label='Monthly House Rent', |
| 214 | fieldtype='Currency', insert_after='salary_structure_hra'), |
| 215 | dict(fieldname='rented_in_metro_city', label='Rented in Metro City', |
| 216 | fieldtype='Check', insert_after='monthly_house_rent'), |
| 217 | dict(fieldname='hra_column_break', fieldtype='Column Break', |
| 218 | insert_after='rented_in_metro_city'), |
| 219 | dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption', |
| 220 | fieldtype='Currency', insert_after='hra_column_break', read_only=1), |
| 221 | dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption', |
| 222 | fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1) |
| 223 | ], |
| 224 | 'Employee Tax Exemption Proof Submission': [ |
| 225 | dict(fieldname='hra_section', label='HRA Exemption', |
| 226 | fieldtype='Section Break', insert_after='tax_exemption_proofs'), |
| 227 | dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount', |
| 228 | fieldtype='Currency', insert_after='hra_section'), |
| 229 | dict(fieldname='rented_in_metro_city', label='Rented in Metro City', |
| 230 | fieldtype='Check', insert_after='house_rent_payment_amount'), |
| 231 | dict(fieldname='rented_from_date', label='Rented From Date', |
| 232 | fieldtype='Date', insert_after='rented_in_metro_city'), |
| 233 | dict(fieldname='rented_to_date', label='Rented To Date', |
| 234 | fieldtype='Date', insert_after='rented_from_date'), |
| 235 | dict(fieldname='hra_column_break', fieldtype='Column Break', |
| 236 | insert_after='rented_to_date'), |
| 237 | dict(fieldname='monthly_house_rent', label='Monthly House Rent', |
| 238 | fieldtype='Currency', insert_after='hra_column_break', read_only=1), |
| 239 | dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount', |
| 240 | fieldtype='Currency', insert_after='monthly_house_rent', read_only=1), |
| 241 | dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption', |
| 242 | fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1) |
| 243 | ] |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 244 | } |
| 245 | |
Rushabh Mehta | 69fa808 | 2018-07-17 18:22:51 +0530 | [diff] [blame] | 246 | create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update) |
Nabin Hait | 9c42161 | 2017-07-20 13:32:01 +0530 | [diff] [blame] | 247 | |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 248 | def make_fixtures(company=None): |
| 249 | docs = [] |
| 250 | company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company") |
| 251 | |
| 252 | set_salary_components(docs) |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 253 | set_tds_account(docs, company) |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 254 | |
| 255 | for d in docs: |
| 256 | try: |
| 257 | doc = frappe.get_doc(d) |
| 258 | doc.flags.ignore_permissions = True |
| 259 | doc.insert() |
| 260 | except frappe.NameError: |
| 261 | pass |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 262 | except frappe.DuplicateEntryError: |
| 263 | pass |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 264 | |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 265 | # create records for Tax Withholding Category |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 266 | set_tax_withholding_category(company) |
| 267 | |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 268 | def set_salary_components(docs): |
| 269 | docs.extend([ |
| 270 | {'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'}, |
| 271 | {'doctype': 'Salary Component', 'salary_component': 'Provident Fund', 'description': 'Provident fund', 'type': 'Deduction'}, |
| 272 | {'doctype': 'Salary Component', 'salary_component': 'House Rent Allowance', 'description': 'House Rent Allowance', 'type': 'Earning'}, |
| 273 | {'doctype': 'Salary Component', 'salary_component': 'Basic', 'description': 'Basic', 'type': 'Earning'}, |
| 274 | {'doctype': 'Salary Component', 'salary_component': 'Arrear', 'description': 'Arrear', 'type': 'Earning'}, |
| 275 | {'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'} |
| 276 | ]) |
| 277 | |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 278 | def set_tax_withholding_category(company): |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 279 | accounts = [] |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 280 | abbr = frappe.get_value("Company", company, "abbr") |
| 281 | tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name') |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 282 | |
| 283 | if company and tds_account: |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 284 | accounts = [dict(company=company, account=tds_account)] |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 285 | |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 286 | fiscal_year = get_fiscal_year(today(), company=accounts[0].get('company'))[0] |
| 287 | docs = get_tds_details(accounts, fiscal_year) |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 288 | |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 289 | for d in docs: |
| 290 | try: |
| 291 | doc = frappe.get_doc(d) |
| 292 | doc.flags.ignore_permissions = True |
| 293 | doc.insert() |
| 294 | except frappe.DuplicateEntryError: |
| 295 | doc = frappe.get_doc("Tax Withholding Category", d.get("name")) |
| 296 | doc.append("accounts", accounts[0]) |
| 297 | |
| 298 | # if fiscal year don't match with any of the already entered data, append rate row |
| 299 | fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year] |
| 300 | if not fy_exist: |
| 301 | doc.append("rates", d.get('rates')[0]) |
| 302 | |
| 303 | doc.save() |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 304 | |
| 305 | def set_tds_account(docs, company): |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 306 | abbr = frappe.get_value("Company", company, "abbr") |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 307 | docs.extend([ |
| 308 | { |
Ranjith Kurungadam | e51c175 | 2018-07-24 11:07:28 +0530 | [diff] [blame] | 309 | "doctype": "Account", "account_name": "TDS Payable", "account_type": "Tax", |
| 310 | "parent_account": "Duties and Taxes - {0}".format(abbr), "company": company |
Saurabh | 2d8a7ee | 2018-05-11 13:16:16 +0530 | [diff] [blame] | 311 | } |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 312 | ]) |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 313 | |
| 314 | def get_tds_details(accounts, fiscal_year): |
| 315 | # bootstrap default tax withholding sections |
| 316 | return [ |
| 317 | dict(name="TDS - 194C - Company", |
| 318 | category_name="Payment to Contractors (Single / Aggregate)", |
| 319 | doctype="Tax Withholding Category", accounts=accounts, |
| 320 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 321 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 322 | dict(name="TDS - 194C - Individual", |
| 323 | category_name="Payment to Contractors (Single / Aggregate)", |
| 324 | doctype="Tax Withholding Category", accounts=accounts, |
| 325 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 326 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 327 | dict(name="TDS - 194C - No PAN / Invalid PAN", |
| 328 | category_name="Payment to Contractors (Single / Aggregate)", |
| 329 | doctype="Tax Withholding Category", accounts=accounts, |
| 330 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 331 | "single_threshold": 30000, "cumulative_threshold": 100000}]), |
| 332 | dict(name="TDS - 194D - Company", |
| 333 | category_name="Insurance Commission", |
| 334 | doctype="Tax Withholding Category", accounts=accounts, |
| 335 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 336 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 337 | dict(name="TDS - 194D - Company Assessee", |
| 338 | category_name="Insurance Commission", |
| 339 | doctype="Tax Withholding Category", accounts=accounts, |
| 340 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 341 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 342 | dict(name="TDS - 194D - Individual", |
| 343 | category_name="Insurance Commission", |
| 344 | doctype="Tax Withholding Category", accounts=accounts, |
| 345 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 346 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 347 | dict(name="TDS - 194D - No PAN / Invalid PAN", |
| 348 | category_name="Insurance Commission", |
| 349 | doctype="Tax Withholding Category", accounts=accounts, |
| 350 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 351 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 352 | dict(name="TDS - 194DA - Company", |
| 353 | category_name="Non-exempt payments made under a life insurance policy", |
| 354 | doctype="Tax Withholding Category", accounts=accounts, |
| 355 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 356 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 357 | dict(name="TDS - 194DA - Individual", |
| 358 | category_name="Non-exempt payments made under a life insurance policy", |
| 359 | doctype="Tax Withholding Category", accounts=accounts, |
| 360 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1, |
| 361 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 362 | dict(name="TDS - 194DA - No PAN / Invalid PAN", |
| 363 | category_name="Non-exempt payments made under a life insurance policy", |
| 364 | doctype="Tax Withholding Category", accounts=accounts, |
| 365 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 366 | "single_threshold": 100000, "cumulative_threshold": 0}]), |
| 367 | dict(name="TDS - 194H - Company", |
| 368 | category_name="Commission / Brokerage", |
| 369 | doctype="Tax Withholding Category", accounts=accounts, |
| 370 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 371 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 372 | dict(name="TDS - 194H - Individual", |
| 373 | category_name="Commission / Brokerage", |
| 374 | doctype="Tax Withholding Category", accounts=accounts, |
| 375 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5, |
| 376 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 377 | dict(name="TDS - 194H - No PAN / Invalid PAN", |
| 378 | category_name="Commission / Brokerage", |
| 379 | doctype="Tax Withholding Category", accounts=accounts, |
| 380 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 381 | "single_threshold": 15000, "cumulative_threshold": 0}]), |
| 382 | dict(name="TDS - 194I - Rent - Company", |
| 383 | category_name="Rent", |
| 384 | doctype="Tax Withholding Category", accounts=accounts, |
| 385 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 386 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 387 | dict(name="TDS - 194I - Rent - Individual", |
| 388 | category_name="Rent", |
| 389 | doctype="Tax Withholding Category", accounts=accounts, |
| 390 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 391 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 392 | dict(name="TDS - 194I - Rent - No PAN / Invalid PAN", |
| 393 | category_name="Rent", |
| 394 | doctype="Tax Withholding Category", accounts=accounts, |
| 395 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 396 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 397 | dict(name="TDS - 194I - Rent/Machinery - Company", |
| 398 | category_name="Rent-Plant / Machinery", |
| 399 | doctype="Tax Withholding Category", accounts=accounts, |
| 400 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 401 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 402 | dict(name="TDS - 194I - Rent/Machinery - Individual", |
| 403 | category_name="Rent-Plant / Machinery", |
| 404 | doctype="Tax Withholding Category", accounts=accounts, |
| 405 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2, |
| 406 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 407 | dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN", |
| 408 | category_name="Rent-Plant / Machinery", |
| 409 | doctype="Tax Withholding Category", accounts=accounts, |
| 410 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 411 | "single_threshold": 180000, "cumulative_threshold": 0}]), |
| 412 | dict(name="TDS - 194J - Professional Fees - Company", |
| 413 | category_name="Professional Fees", |
| 414 | doctype="Tax Withholding Category", accounts=accounts, |
| 415 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 416 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 417 | dict(name="TDS - 194J - Professional Fees - Individual", |
| 418 | category_name="Professional Fees", |
| 419 | doctype="Tax Withholding Category", accounts=accounts, |
| 420 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 421 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 422 | dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN", |
| 423 | category_name="Professional Fees", |
| 424 | doctype="Tax Withholding Category", accounts=accounts, |
| 425 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 426 | "single_threshold": 30000, "cumulative_threshold": 0}]), |
| 427 | dict(name="TDS - 194J - Director Fees - Company", |
| 428 | category_name="Director Fees", |
| 429 | doctype="Tax Withholding Category", accounts=accounts, |
| 430 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 431 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 432 | dict(name="TDS - 194J - Director Fees - Individual", |
| 433 | category_name="Director Fees", |
| 434 | doctype="Tax Withholding Category", accounts=accounts, |
| 435 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 436 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 437 | dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN", |
| 438 | category_name="Director Fees", |
| 439 | doctype="Tax Withholding Category", accounts=accounts, |
| 440 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 441 | "single_threshold": 0, "cumulative_threshold": 0}]), |
| 442 | dict(name="TDS - 194 - Dividends - Company", |
| 443 | category_name="Dividends", |
| 444 | doctype="Tax Withholding Category", accounts=accounts, |
| 445 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 446 | "single_threshold": 2500, "cumulative_threshold": 0}]), |
| 447 | dict(name="TDS - 194 - Dividends - Individual", |
| 448 | category_name="Dividends", |
| 449 | doctype="Tax Withholding Category", accounts=accounts, |
| 450 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10, |
| 451 | "single_threshold": 2500, "cumulative_threshold": 0}]), |
| 452 | dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN", |
| 453 | category_name="Dividends", |
| 454 | doctype="Tax Withholding Category", accounts=accounts, |
| 455 | rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20, |
| 456 | "single_threshold": 2500, "cumulative_threshold": 0}]) |
| 457 | ] |