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", "ref_docname",
"column_break_5", "column_break_5",
"company", "company",
"is_recurring",
"from_date",
"to_date",
"payroll_date", "payroll_date",
"salary_slip",
"type", "type",
"department", "department",
"amount", "amount",
@ -76,12 +78,13 @@
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"depends_on": "eval:(doc.is_recurring==0)",
"description": "Date on which this component is applied", "description": "Date on which this component is applied",
"fieldname": "payroll_date", "fieldname": "payroll_date",
"fieldtype": "Date", "fieldtype": "Date",
"in_list_view": 1, "in_list_view": 1,
"label": "Payroll Date", "label": "Payroll Date",
"reqd": 1, "mandatory_depends_on": "eval:(doc.is_recurring==0)",
"search_index": 1 "search_index": 1
}, },
{ {
@ -107,13 +110,6 @@
"options": "Company", "options": "Company",
"reqd": 1 "reqd": 1
}, },
{
"fieldname": "salary_slip",
"fieldtype": "Link",
"label": "Salary Slip",
"options": "Salary Slip",
"read_only": 1
},
{ {
"fetch_from": "salary_component.type", "fetch_from": "salary_component.type",
"fieldname": "type", "fieldname": "type",
@ -129,6 +125,26 @@
"options": "Additional Salary", "options": "Additional Salary",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "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", "fieldname": "ref_doctype",

View File

@ -23,8 +23,21 @@ class AdditionalSalary(Document):
def validate_dates(self): 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"]) ["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): def get_amount(self, sal_start_date, sal_end_date):
start_date = getdate(sal_start_date) start_date = getdate(sal_start_date)
@ -45,7 +58,11 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty
from `tabAdditional Salary` from `tabAdditional Salary`
where employee=%(employee)s where employee=%(employee)s
and docstatus = 1 and docstatus = 1
and payroll_date between %(from_date)s and %(to_date)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 and type = %(component_type)s
group by salary_component, overwrite_salary_structure_amount group by salary_component, overwrite_salary_structure_amount
order 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: if additional_components:
for additional_component in additional_components: for additional_component in additional_components:
amount = additional_component.amount amount = additional_component.amount
print("-------------[>>>]", amount)
overwrite = additional_component.overwrite overwrite = additional_component.overwrite
self.update_component_row(frappe._dict(additional_component.struct_row), amount, self.update_component_row(frappe._dict(additional_component.struct_row), amount,
component_type, overwrite=overwrite) component_type, overwrite=overwrite)