feat: Recurring Addtional Salary

This commit is contained in:
Anurag Mishra 2020-01-13 19:10:48 +05:30
parent 943457abd3
commit 2d7fcab2c9
4 changed files with 49 additions and 15 deletions

View File

@ -13,5 +13,5 @@ frappe.ui.form.on('Additional Salary', {
}
};
});
}
},
});

View File

@ -17,8 +17,10 @@
"ref_docname",
"column_break_5",
"company",
"is_recurring",
"from_date",
"to_date",
"payroll_date",
"salary_slip",
"type",
"department",
"amount",
@ -76,12 +78,13 @@
"fieldtype": "Column Break"
},
{
"depends_on": "eval:(doc.is_recurring==0)",
"description": "Date on which this component is applied",
"fieldname": "payroll_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Payroll Date",
"reqd": 1,
"mandatory_depends_on": "eval:(doc.is_recurring==0)",
"search_index": 1
},
{
@ -107,13 +110,6 @@
"options": "Company",
"reqd": 1
},
{
"fieldname": "salary_slip",
"fieldtype": "Link",
"label": "Salary Slip",
"options": "Salary Slip",
"read_only": 1
},
{
"fetch_from": "salary_component.type",
"fieldname": "type",
@ -131,6 +127,26 @@
"read_only": 1
},
{
"default": "0",
"fieldname": "is_recurring",
"fieldtype": "Check",
"label": "Is Recurring"
},
{
"depends_on": "eval:(doc.is_recurring==1)",
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From Date",
"mandatory_depends_on": "eval:(doc.is_recurring==1)"
},
{
"depends_on": "eval:(doc.is_recurring==1)",
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To Date",
"mandatory_depends_on": "eval:(doc.is_recurring==1)"
},
{
"fieldname": "ref_doctype",
"fieldtype": "Link",
"label": "Reference Document Type",

View File

@ -21,10 +21,23 @@ class AdditionalSalary(Document):
frappe.throw(_("Amount should not be less than zero."))
def validate_dates(self):
date_of_joining, relieving_date = frappe.db.get_value("Employee", self.employee,
date_of_joining, relieving_date = frappe.db.get_value("Employee", self.employee,
["date_of_joining", "relieving_date"])
if date_of_joining and getdate(self.payroll_date) < getdate(date_of_joining):
frappe.throw(_("Payroll date can not be less than employee's joining date"))
if not self.is_recurring and not self.payroll_date:
frappe.msgprint(_("Please enter Payroll Date."), indicator='blue', raise_exception=1)
if self.is_recurring and not self.from_date and not self.to_date:
frappe.msgprint(_("Please enter From Date and To Date."), indicator='blue', raise_exception=1)
if getdate(self.from_date) > getdate(self.to_date):
frappe.throw(_("From Date can not be greater than To Date."))
if date_of_joining:
if getdate(self.payroll_date) < getdate(date_of_joining):
frappe.throw(_("Payroll date can not be less than employee's joining date."))
elif getdate(self.from_date) < getdate(date_of_joining):
frappe.throw(_("From date can not be less than employee's joining date."))
elif getdate(self.to_date) > getdate(relieving_date):
frappe.throw(_("To date can not be greater than employee's relieving date."))
def get_amount(self, sal_start_date, sal_end_date):
start_date = getdate(sal_start_date)
@ -45,8 +58,12 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty
from `tabAdditional Salary`
where employee=%(employee)s
and docstatus = 1
and payroll_date between %(from_date)s and %(to_date)s
and type = %(component_type)s
and (payroll_date between %(from_date)s and %(to_date)s)
or (
(from_date between %(from_date)s and %(to_date)s)
or(to_date between %(from_date)s and %(to_date)s)
)
and type = %(component_type)s
group by salary_component, overwrite_salary_structure_amount
order by salary_component, overwrite_salary_structure_amount
""", {

View File

@ -410,6 +410,7 @@ class SalarySlip(TransactionBase):
if additional_components:
for additional_component in additional_components:
amount = additional_component.amount
print("-------------[>>>]", amount)
overwrite = additional_component.overwrite
self.update_component_row(frappe._dict(additional_component.struct_row), amount,
component_type, overwrite=overwrite)