From a8e047afc85f97e65a3366f5603ec853f1af1f5f Mon Sep 17 00:00:00 2001 From: Ranjith Kurungadam Date: Thu, 14 Jun 2018 17:56:16 +0530 Subject: [PATCH] HRA tax exemption Indian regional (#14520) * remove HRA fields fom declaration, proof submission * HRA fields, methods India regional * Company - remove Payroll Settings * HRA India regional, override methods * Patch to add HRA fields for India --- erpnext/hooks.py | 4 +- .../employee_tax_exemption_declaration.js | 49 --- .../employee_tax_exemption_declaration.json | 227 +------------- .../employee_tax_exemption_declaration.py | 17 +- ...ployee_tax_exemption_proof_submission.json | 288 +----------------- ...employee_tax_exemption_proof_submission.py | 52 +--- erpnext/hr/utils.py | 68 +---- erpnext/patches.txt | 1 + .../patches/v11_0/add_hra_fields_for_india.py | 6 + erpnext/regional/india/setup.py | 49 ++- erpnext/regional/india/utils.py | 90 +++++- erpnext/setup/doctype/company/company.json | 100 +----- 12 files changed, 180 insertions(+), 771 deletions(-) create mode 100644 erpnext/patches/v11_0/add_hra_fields_for_india.py diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 9f1afd920f..f88dd03a57 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -272,7 +272,9 @@ regional_overrides = { 'erpnext.tests.test_regional.test_method': 'erpnext.regional.india.utils.test_method', 'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_header': 'erpnext.regional.india.utils.get_itemised_tax_breakup_header', 'erpnext.controllers.taxes_and_totals.get_itemised_tax_breakup_data': 'erpnext.regional.india.utils.get_itemised_tax_breakup_data', - 'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details' + 'erpnext.accounts.party.get_regional_address_details': 'erpnext.regional.india.utils.get_regional_address_details', + 'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption', + 'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period' }, 'United Arab Emirates': { 'erpnext.controllers.taxes_and_totals.update_itemised_tax_data': 'erpnext.regional.united_arab_emirates.utils.update_itemised_tax_data' diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js index 4ef3af4f66..9560df53e1 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js +++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.js @@ -2,11 +2,6 @@ // For license information, please see license.txt frappe.ui.form.on('Employee Tax Exemption Declaration', { - refresh: function(frm){ - if(frm.doc.__islocal){ - frm.set_df_property('hra_declaration_section', 'hidden', 1); - } - }, setup: function(frm) { frm.set_query('employee', function() { return { @@ -39,49 +34,5 @@ frappe.ui.form.on('Employee Tax Exemption Declaration', { } } }); - }, - employee: function(frm){ - frm.trigger('set_null_value'); - }, - company: function(frm) { - if(frm.doc.company){ - frappe.call({ - method: "frappe.client.get_value", - args: { - doctype: "Company", - filters: {"name": frm.doc.company}, - fieldname: "hra_component" - }, - callback: function(r){ - if(r.message.hra_component){ - frm.set_df_property('hra_declaration_section', 'hidden', 0); - } - } - }); - } - }, - monthly_house_rent: function(frm) { - frm.trigger("calculate_hra_exemption"); - }, - rented_in_metro_city: function(frm) { - frm.trigger("calculate_hra_exemption"); - }, - calculate_hra_exemption: function(frm) { - frappe.call({ - method: "calculate_hra_exemption", - doc: frm.doc, - callback: function(r) { - if (!r.exc){ - frm.refresh_fields(); - } - } - }); - }, - set_null_value(frm){ - let fields = ['salary_structure_hra', 'monthly_house_rent','annual_hra_exemption', - 'monthly_hra_exemption', 'total_exemption_amount', 'payroll_period']; - fields.forEach(function(field) { - frm.set_value(field, ''); - }); } }); diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json index 473150b825..f287be989f 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json +++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json @@ -305,231 +305,6 @@ "set_only_once": 0, "translatable": 0, "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "", - "fieldname": "hra_declaration_section", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "HRA Declaration", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "salary_structure_hra", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "HRA as per Salary Structure", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "monthly_house_rent", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Monthly House Rent", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rented_in_metro_city", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Rented in Metro City", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "coloum_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": " ", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "annual_hra_exemption", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Annual HRA Exemption", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "monthly_hra_exemption", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Monthly HRA Exemption", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 } ], "has_web_view": 0, @@ -542,7 +317,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-05-30 18:09:50.662362", + "modified": "2018-06-09 17:44:32.705557", "modified_by": "Administrator", "module": "HR", "name": "Employee Tax Exemption Declaration", diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py index a9b1e33af5..186b2e1052 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py +++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py @@ -6,17 +6,15 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe import _ -from erpnext.hr.utils import validate_tax_declaration, calculate_eligible_hra_exemption +from erpnext.hr.utils import validate_tax_declaration, calculate_annual_eligible_hra_exemption class EmployeeTaxExemptionDeclaration(Document): def validate(self): validate_tax_declaration(self.declarations) - self.calculate_hra_exemption() self.total_exemption_amount = 0 + self.calculate_hra_exemption() for item in self.declarations: self.total_exemption_amount += item.amount - if self.annual_hra_exemption: - self.total_exemption_amount += self.annual_hra_exemption def before_submit(self): if frappe.db.exists({"doctype": "Employee Tax Exemption Declaration", @@ -27,8 +25,9 @@ class EmployeeTaxExemptionDeclaration(Document): .format(self.employee, self.payroll_period), frappe.DocstatusTransitionError) def calculate_hra_exemption(self): - exemptions = calculate_eligible_hra_exemption(self.company, self.employee, \ - self.monthly_house_rent, self.rented_in_metro_city) - self.salary_structure_hra = exemptions["hra_amount"] - self.annual_hra_exemption = exemptions["annual_exemption"] - self.monthly_hra_exemption = exemptions["monthly_exemption"] + hra_exemption = calculate_annual_eligible_hra_exemption(self) + if hra_exemption: + self.total_exemption_amount += hra_exemption["annual_exemption"] + self.salary_structure_hra = hra_exemption["hra_amount"] + self.annual_hra_exemption = hra_exemption["annual_exemption"] + self.monthly_hra_exemption = hra_exemption["monthly_exemption"] diff --git a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json index 32203d8604..38ee20de0d 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json +++ b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.json @@ -305,292 +305,6 @@ "translatable": 0, "unique": 0 }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "section_break_9", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "house_rent_payment_amount", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": " House Rent Payment Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rented_in_metro_city", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Rented in Metro City", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rented_from_date", - "fieldtype": "Date", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Rented From Date", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rented_to_date", - "fieldtype": "Date", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Rented To Date", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_12", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "monthly_house_rent", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Monthly House Rent", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "monthly_hra_exemption", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Monthly Eligible Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "total_eligible_hra_exemption", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Total Eligible HRA Exemption", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, { "allow_bulk_edit": 0, "allow_in_quick_entry": 0, @@ -698,7 +412,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-05-30 20:26:05.714414", + "modified": "2018-06-09 17:43:46.071900", "modified_by": "Administrator", "module": "HR", "name": "Employee Tax Exemption Proof Submission", diff --git a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.py b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.py index 503cfe051e..acaa660a93 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.py +++ b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.py @@ -6,52 +6,20 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe import _ -from frappe.utils import date_diff, flt -from erpnext.hr.utils import validate_tax_declaration, calculate_eligible_hra_exemption +from erpnext.hr.utils import validate_tax_declaration, calculate_hra_exemption_for_period class EmployeeTaxExemptionProofSubmission(Document): def validate(self): validate_tax_declaration(self.tax_exemption_proofs) - if self.house_rent_payment_amount: - self.validate_house_rent_dates() - self.get_monthly_hra() - self.calculate_hra_exemption() - self.calculate_total_exemption() - - def get_monthly_hra(self): - factor = self.get_rented_days_factor() - self.monthly_house_rent = self.house_rent_payment_amount / factor - - def validate_house_rent_dates(self): - if date_diff(self.rented_to_date, self.rented_from_date) < 14: - frappe.throw(_("House Rented dates should be atleast 15 days apart")) - - proofs = frappe.db.sql("""select name from `tabEmployee Tax Exemption Proof Submission` - where docstatus=1 and employee='{0}' and payroll_period='{1}' and - (rented_from_date between '{2}' and '{3}' or rented_to_date between - '{2}' and '{2}')""".format(self.employee, self.payroll_period, - self.rented_from_date, self.rented_to_date)) - if proofs: - frappe.throw(_("House rent paid days overlap with {0}").format(proofs[0][0])) - - def calculate_hra_exemption(self): - exemptions = calculate_eligible_hra_exemption(self.company, self.employee, \ - self.monthly_house_rent, self.rented_in_metro_city) - self.monthly_hra_exemption = exemptions["monthly_exemption"] - if self.monthly_hra_exemption: - factor = self.get_rented_days_factor(rounded=False) - self.total_eligible_hra_exemption = self.monthly_hra_exemption * factor - else: - self.monthly_hra_exemption, self.total_eligible_hra_exemption = 0, 0 - - def get_rented_days_factor(self, rounded=True): - factor = flt(date_diff(self.rented_to_date, self.rented_from_date) + 1)/30 - factor = round(factor * 2)/2 - return factor if factor else 0.5 - - def calculate_total_exemption(self): self.total_amount = 0 + self.calculate_hra_exemption() for proof in self.tax_exemption_proofs: self.total_amount += proof.amount - if self.monthly_house_rent and self.total_eligible_hra_exemption: - self.total_amount += self.total_eligible_hra_exemption + + def calculate_hra_exemption(self): + hra_exemption = calculate_hra_exemption_for_period(self) + if hra_exemption: + self.total_amount += hra_exemption["total_eligible_hra_exemption"] + self.monthly_hra_exemption = hra_exemption["monthly_exemption"] + self.monthly_house_rent = hra_exemption["monthly_house_rent"] + self.total_eligible_hra_exemption = hra_exemption["total_eligible_hra_exemption"] diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 68ec8b0b88..d8636ede09 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -2,12 +2,11 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -import frappe +import frappe, erpnext from frappe import _ from frappe.utils import formatdate, format_datetime, getdate, get_datetime, nowdate, flt, cstr from frappe.model.document import Document from frappe.desk.form import assign_to -from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee class EmployeeBoardingController(Document): @@ -299,59 +298,6 @@ def get_salary_assignment(employee, date): }, as_dict=1) return assignment[0] if assignment else None -def calculate_eligible_hra_exemption(company, employee, monthly_house_rent, rented_in_metro_city): - hra_component = frappe.db.get_value("Company", company, "hra_component") - annual_exemption, monthly_exemption, hra_amount = 0, 0, 0 - if hra_component: - assignment = get_salary_assignment(employee, getdate()) - if assignment and frappe.db.exists("Salary Detail", { - "parent": assignment.salary_structure, - "salary_component": hra_component, "parentfield": "earnings"}): - hra_amount = get_hra_from_salary_slip(employee, assignment.salary_structure, hra_component) - if hra_amount: - if monthly_house_rent: - annual_exemption = calculate_hra_exemption(assignment.salary_structure, - assignment.base, hra_amount, monthly_house_rent, - rented_in_metro_city) - if annual_exemption > 0: - monthly_exemption = annual_exemption / 12 - else: - annual_exemption = 0 - return {"hra_amount": hra_amount, "annual_exemption": annual_exemption, "monthly_exemption": monthly_exemption} - -def get_hra_from_salary_slip(employee, salary_structure, hra_component): - salary_slip = make_salary_slip(salary_structure, employee=employee) - for earning in salary_slip.earnings: - if earning.salary_component == hra_component: - return earning.amount - -def calculate_hra_exemption(salary_structure, base, monthly_hra, monthly_house_rent, rented_in_metro_city): - # TODO make this configurable - exemptions = [] - frequency = frappe.get_value("Salary Structure", salary_structure, "payroll_frequency") - # case 1: The actual amount allotted by the employer as the HRA. - exemptions.append(get_annual_component_pay(frequency, monthly_hra)) - actual_annual_rent = monthly_house_rent * 12 - annual_base = get_annual_component_pay(frequency, base) - # case 2: Actual rent paid less 10% of the basic salary. - exemptions.append(flt(actual_annual_rent) - flt(annual_base * 0.1)) - # case 3: 50% of the basic salary, if the employee is staying in a metro city (40% for a non-metro city). - exemptions.append(annual_base * 0.5 if rented_in_metro_city else annual_base * 0.4) - # return minimum of 3 cases - return min(exemptions) - -def get_annual_component_pay(frequency, amount): - if frequency == "Daily": - return amount * 365 - elif frequency == "Weekly": - return amount * 52 - elif frequency == "Fortnightly": - return amount * 26 - elif frequency == "Monthly": - return amount * 12 - elif frequency == "Bimonthly": - return amount * 6 - def get_sal_slip_total_benefit_given(employee, payroll_period, component=False): total_given_benefit_amount = 0 query = """ @@ -395,3 +341,15 @@ def get_holidays_for_employee(employee, start_date, end_date): holidays = [cstr(i) for i in holidays] return holidays + +@erpnext.allow_regional +def calculate_annual_eligible_hra_exemption(doc): + # Don't delete this method, used for localization + # Indian HRA Exemption Calculation + return {} + +@erpnext.allow_regional +def calculate_hra_exemption_for_period(doc): + # Don't delete this method, used for localization + # Indian HRA Exemption Calculation + return {} diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8b683d8655..302422566a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -549,3 +549,4 @@ erpnext.patches.v11_0.rename_members_with_naming_series #04-06-2018 erpnext.patches.v11_0.set_update_field_and_value_in_workflow_state erpnext.patches.v11_0.update_total_qty_field erpnext.patches.v11_0.update_sales_partner_type +erpnext.patches.v11_0.add_hra_fields_for_india diff --git a/erpnext/patches/v11_0/add_hra_fields_for_india.py b/erpnext/patches/v11_0/add_hra_fields_for_india.py new file mode 100644 index 0000000000..f511036e63 --- /dev/null +++ b/erpnext/patches/v11_0/add_hra_fields_for_india.py @@ -0,0 +1,6 @@ +import frappe +from erpnext.regional.india.setup import make_custom_fields + +def execute(): + if frappe.db.exists("Company", {"country": "India"}): + make_custom_fields() diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index 0b7521398a..1a28f7757e 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -191,7 +191,52 @@ def make_custom_fields(): 'Employee': [ dict(fieldname='ifsc_code', label='IFSC Code', fieldtype='Data', insert_after='bank_ac_no', print_hide=1, - depends_on='eval:doc.salary_mode == "Bank"') ] + depends_on='eval:doc.salary_mode == "Bank"') + ], + 'Company': [ + dict(fieldname='hra_section', label='HRA Settings', + fieldtype='Section Break', insert_after='asset_received_but_not_billed'), + dict(fieldname='hra_component', label='HRA Component', + fieldtype='Link', options='Salary Component', insert_after='hra_section'), + dict(fieldname='arrear_component', label='Arrear Component', + fieldtype='Link', options='Salary Component', insert_after='hra_component') + ], + 'Employee Tax Exemption Declaration':[ + dict(fieldname='hra_section', label='HRA Exemption', + fieldtype='Section Break', insert_after='declarations'), + dict(fieldname='salary_structure_hra', label='HRA as per Salary Structure', + fieldtype='Currency', insert_after='hra_section', read_only=1), + dict(fieldname='monthly_house_rent', label='Monthly House Rent', + fieldtype='Currency', insert_after='salary_structure_hra'), + dict(fieldname='rented_in_metro_city', label='Rented in Metro City', + fieldtype='Check', insert_after='monthly_house_rent'), + dict(fieldname='hra_column_break', fieldtype='Column Break', + insert_after='rented_in_metro_city'), + dict(fieldname='annual_hra_exemption', label='Annual HRA Exemption', + fieldtype='Currency', insert_after='hra_column_break', read_only=1), + dict(fieldname='monthly_hra_exemption', label='Monthly HRA Exemption', + fieldtype='Currency', insert_after='annual_hra_exemption', read_only=1) + ], + 'Employee Tax Exemption Proof Submission': [ + dict(fieldname='hra_section', label='HRA Exemption', + fieldtype='Section Break', insert_after='tax_exemption_proofs'), + dict(fieldname='house_rent_payment_amount', label='House Rent Payment Amount', + fieldtype='Currency', insert_after='hra_section'), + dict(fieldname='rented_in_metro_city', label='Rented in Metro City', + fieldtype='Check', insert_after='house_rent_payment_amount'), + dict(fieldname='rented_from_date', label='Rented From Date', + fieldtype='Date', insert_after='rented_in_metro_city'), + dict(fieldname='rented_to_date', label='Rented To Date', + fieldtype='Date', insert_after='rented_from_date'), + dict(fieldname='hra_column_break', fieldtype='Column Break', + insert_after='rented_to_date'), + dict(fieldname='monthly_house_rent', label='Monthly House Rent', + fieldtype='Currency', insert_after='hra_column_break', read_only=1), + dict(fieldname='monthly_hra_exemption', label='Monthly Eligible Amount', + fieldtype='Currency', insert_after='monthly_house_rent', read_only=1), + dict(fieldname='total_eligible_hra_exemption', label='Total Eligible HRA Exemption', + fieldtype='Currency', insert_after='monthly_hra_exemption', read_only=1) + ] } create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch) @@ -250,4 +295,4 @@ def set_tds_account(docs, company): 'doctype': 'Account', 'account_name': 'TDS', 'account_type': 'Tax', 'parent_account': 'Duties and Taxes', 'company': company } - ]) \ No newline at end of file + ]) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index d47419b91d..273912b95f 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -1,9 +1,11 @@ import frappe, re from frappe import _ -from frappe.utils import cstr +from frappe.utils import cstr, flt, date_diff, getdate from erpnext.regional.india import states, state_numbers from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount from erpnext.controllers.accounts_controller import get_taxes_and_charges +from erpnext.hr.utils import get_salary_assignment +from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip def validate_gstin_for_india(doc, method): if not hasattr(doc, 'gstin'): @@ -107,3 +109,89 @@ def get_regional_address_details(out, doctype, company): return out["taxes_and_charges"] = default_tax out.taxes = get_taxes_and_charges(master_doctype, default_tax) + +def calculate_annual_eligible_hra_exemption(doc): + hra_component = frappe.db.get_value("Company", doc.company, "hra_component") + annual_exemption, monthly_exemption, hra_amount = 0, 0, 0 + if hra_component: + assignment = get_salary_assignment(doc.employee, getdate()) + if assignment and frappe.db.exists("Salary Detail", { + "parent": assignment.salary_structure, + "salary_component": hra_component, "parentfield": "earnings"}): + hra_amount = get_hra_from_salary_slip(doc.employee, assignment.salary_structure, hra_component) + if hra_amount: + if doc.monthly_house_rent: + annual_exemption = calculate_hra_exemption(assignment.salary_structure, + assignment.base, hra_amount, doc.monthly_house_rent, + doc.rented_in_metro_city) + if annual_exemption > 0: + monthly_exemption = annual_exemption / 12 + else: + annual_exemption = 0 + return {"hra_amount": hra_amount, "annual_exemption": annual_exemption, "monthly_exemption": monthly_exemption} + +def get_hra_from_salary_slip(employee, salary_structure, hra_component): + salary_slip = make_salary_slip(salary_structure, employee=employee) + for earning in salary_slip.earnings: + if earning.salary_component == hra_component: + return earning.amount + +def calculate_hra_exemption(salary_structure, base, monthly_hra, monthly_house_rent, rented_in_metro_city): + # TODO make this configurable + exemptions = [] + frequency = frappe.get_value("Salary Structure", salary_structure, "payroll_frequency") + # case 1: The actual amount allotted by the employer as the HRA. + exemptions.append(get_annual_component_pay(frequency, monthly_hra)) + actual_annual_rent = monthly_house_rent * 12 + annual_base = get_annual_component_pay(frequency, base) + # case 2: Actual rent paid less 10% of the basic salary. + exemptions.append(flt(actual_annual_rent) - flt(annual_base * 0.1)) + # case 3: 50% of the basic salary, if the employee is staying in a metro city (40% for a non-metro city). + exemptions.append(annual_base * 0.5 if rented_in_metro_city else annual_base * 0.4) + # return minimum of 3 cases + return min(exemptions) + +def get_annual_component_pay(frequency, amount): + if frequency == "Daily": + return amount * 365 + elif frequency == "Weekly": + return amount * 52 + elif frequency == "Fortnightly": + return amount * 26 + elif frequency == "Monthly": + return amount * 12 + elif frequency == "Bimonthly": + return amount * 6 + +def validate_house_rent_dates(doc): + if not doc.rented_to_date or not doc.rented_from_date: + frappe.throw(_("House rented dates required for exemption calculation")) + if date_diff(doc.rented_to_date, doc.rented_from_date) < 14: + frappe.throw(_("House rented dates should be atleast 15 days apart")) + proofs = frappe.db.sql("""select name from `tabEmployee Tax Exemption Proof Submission` + where docstatus=1 and employee='{0}' and payroll_period='{1}' and + (rented_from_date between '{2}' and '{3}' or rented_to_date between + '{2}' and '{3}')""".format(doc.employee, doc.payroll_period, + doc.rented_from_date, doc.rented_to_date)) + if proofs: + frappe.throw(_("House rent paid days overlap with {0}").format(proofs[0][0])) + +def calculate_hra_exemption_for_period(doc): + monthly_rent, eligible_hra = 0, 0 + if doc.house_rent_payment_amount: + validate_house_rent_dates(doc) + # TODO receive rented months or validate dates are start and end of months? + # Calc monthly rent, round to nearest .5 + factor = flt(date_diff(doc.rented_to_date, doc.rented_from_date) + 1)/30 + factor = round(factor * 2)/2 + monthly_rent = doc.house_rent_payment_amount / factor + # update field used by calculate_annual_eligible_hra_exemption + doc.monthly_house_rent = monthly_rent + exemptions = calculate_annual_eligible_hra_exemption(doc) + + if exemptions["monthly_exemption"]: + # calc total exemption amount + eligible_hra = exemptions["monthly_exemption"] * factor + exemptions["monthly_house_rent"] = monthly_rent + exemptions["total_eligible_hra_exemption"] = eligible_hra + return exemptions diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 32f0ec4820..527a032c73 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -2069,104 +2069,6 @@ "set_only_once": 0, "translatable": 0, "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "section_break_66", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Payroll Settings", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "hra_component", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "HRA Component", - "length": 0, - "no_copy": 0, - "options": "Salary Component", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "arrear_component", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Arrear Component", - "length": 0, - "no_copy": 0, - "options": "Salary Component", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 }, { "allow_bulk_edit": 0, @@ -2689,7 +2591,7 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2018-05-29 13:25:15.872138", + "modified": "2018-06-09 13:25:15.872138", "modified_by": "Administrator", "module": "Setup", "name": "Company",