Tax Declaration, Proof Submission, validation
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 d204efc..b31bf0e 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 1a5f195..52746d4 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 d8036c4..99bec14 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 1c31cc4..a0c003c 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 057f406..040134b 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -49,3 +49,16 @@
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)