From 5a8e6427f4d1d8e58ffc1cca359afe91d1383b35 Mon Sep 17 00:00:00 2001 From: Ranjith Date: Thu, 10 May 2018 15:06:49 +0530 Subject: [PATCH] Tax Declaration, Proof Submission, validation --- .../employee_tax_exemption_declaration.js | 35 +++++++++++++++++-- .../employee_tax_exemption_declaration.py | 13 ++++++- ...employee_tax_exemption_proof_submission.js | 35 +++++++++++++++++-- ...employee_tax_exemption_proof_submission.py | 13 ++++++- erpnext/hr/utils.py | 13 +++++++ 5 files changed, 103 insertions(+), 6 deletions(-) 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 d204efc5bf..b31bf0ec45 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,7 +2,38 @@ // For license information, please see license.txt frappe.ui.form.on('Employee Tax Exemption Declaration', { - refresh: function(frm) { - + setup: function(frm) { + frm.set_query('employee', function() { + return { + filters: { + 'status': "Active" + } + } + }); + frm.set_query('payroll_period', function() { + if(frm.doc.employee && frm.doc.company){ + return { + filters: { + 'company': frm.doc.company + } + } + }else { + frappe.msgprint(__("Please select Employee")); + } + }); + frm.set_query('exemption_sub_category', 'declarations', function() { + return { + filters: { + 'is_active': 1 + } + } + }); + }, + employee: function(frm){ + if(frm.doc.employee){ + frm.add_fetch('employee', 'company', 'company'); + }else{ + frm.set_value('company', ''); + } } }); 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 1a5f195d02..52746d4cff 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 @@ -5,6 +5,17 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document +from frappe import _ +from erpnext.hr.utils import validate_tax_declaration class EmployeeTaxExemptionDeclaration(Document): - pass + def validate(self): + validate_tax_declaration(self.declarations) + + def before_submit(self): + if frappe.db.exists({"doctype": "Employee Tax Exemption Declaration", + "employee": self.employee, + "payroll_period": self.payroll_period, + "docstatus": 1}): + frappe.throw(_("Tax Declaration of {0} for period {1} already submitted.")\ + .format(self.employee, self.payroll_period), frappe.DocstatusTransitionError) diff --git a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js index d8036c48e9..99bec14b18 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js +++ b/erpnext/hr/doctype/employee_tax_exemption_proof_submission/employee_tax_exemption_proof_submission.js @@ -2,7 +2,38 @@ // For license information, please see license.txt frappe.ui.form.on('Employee Tax Exemption Proof Submission', { - refresh: function(frm) { - + setup: function(frm) { + frm.set_query('employee', function() { + return { + filters: { + 'status': "Active" + } + } + }); + frm.set_query('payroll_period', function() { + if(frm.doc.employee && frm.doc.company){ + return { + filters: { + 'company': frm.doc.company + } + } + }else { + frappe.msgprint(__("Please select Employee")); + } + }); + frm.set_query('exemption_sub_category', 'tax_exemption_proofs', function() { + return { + filters: { + 'is_active': 1 + } + } + }); + }, + employee: function(frm){ + if(frm.doc.employee){ + frm.add_fetch('employee', 'company', 'company'); + }else{ + frm.set_value('company', ''); + } } }); 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 1c31cc4080..a0c003cdc6 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 @@ -5,6 +5,17 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document +from frappe import _ +from erpnext.hr.utils import validate_tax_declaration class EmployeeTaxExemptionProofSubmission(Document): - pass + def validate(self): + validate_tax_declaration(self.tax_exemption_proofs) + #TODO: allow multiple? + # def before_submit(self): + # if frappe.db.exists({"doctype": "Employee Tax Exemption Proof Submission", + # "employee": self.employee, + # "payroll_period": self.payroll_period, + # "docstatus": 1}): + # frappe.throw(_("Proof Submission of {0} for period {1} already submitted.")\ + # .format(self.employee, self.payroll_period), frappe.DocstatusTransitionError) diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 057f406e80..040134b3bc 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -49,3 +49,16 @@ def update_employee(employee, details, cancel=False): new_data = get_datetime(new_data) setattr(employee, item.fieldname, new_data) return employee + +def validate_tax_declaration(declarations): + subcategories = [] + for declaration in declarations: + if declaration.exemption_sub_category in subcategories: + frappe.throw(_("More than one selection for {0} not \ + allowed").format(declaration.exemption_sub_category), frappe.ValidationError) + subcategories.append(declaration.exemption_sub_category) + max_amount = frappe.db.get_value("Employee Tax Exemption Sub Category", \ + declaration.exemption_sub_category, "max_amount") + if declaration.amount > max_amount: + frappe.throw(_("Max exemption amount for {0} is {1}").format(\ + declaration.exemption_sub_category, max_amount), frappe.ValidationError)