From db197d593a90f03410c281a1d5b326524391d075 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sat, 20 Aug 2016 00:30:59 +0530 Subject: [PATCH] Demo updated for new salary structure --- erpnext/demo/setup_data.py | 34 +++++++++++++------ erpnext/demo/user/hr.py | 15 +++++--- .../process_payroll/process_payroll.py | 17 +++++++--- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/erpnext/demo/setup_data.py b/erpnext/demo/setup_data.py index 1be2cac51c..97dc89476c 100644 --- a/erpnext/demo/setup_data.py +++ b/erpnext/demo/setup_data.py @@ -290,9 +290,13 @@ def setup_item_price(): def setup_salary_structure(): f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year')) + ss = frappe.new_doc('Salary Structure') + ss.name = "Sample Salary Structure - " + str(f.year_start_date) for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']): - ss = frappe.new_doc('Salary Structure') - ss.employee = e.name + ss.append('employees', { + 'employee': e.name, + 'base': random.random() * 10000 + }) if not e.date_of_joining: continue @@ -300,16 +304,24 @@ def setup_salary_structure(): ss.from_date = e.date_of_joining if (e.date_of_joining and e.date_of_joining > f.year_start_date) else f.year_start_date ss.to_date = f.year_end_date - ss.append('earnings', { - 'salary_component': 'Basic', - 'amount': random.random() * 10000 - }) - ss.append('deductions', { - 'salary_component': 'Income Tax', - 'amount': random.random() * 1000 - }) - ss.insert() + ss.append('earnings', { + 'salary_component': 'Basic', + "abbr":'B', + 'condition': 'base > 5000', + 'formula': 'base*.2', + 'amount_based_on_formula': 1, + "idx": 1 + }) + ss.append('deductions', { + 'salary_component': 'Income Tax', + "abbr":'IT', + 'condition': 'base > 5000', + 'amount': random.random() * 1000, + "idx": 1 + }) + + ss.insert() def setup_salary_structure_for_timesheet(): for e in frappe.get_all('Salary Structure', fields=['name'], filters={'is_active': 'Yes'}, limit=2): diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py index 3d5ac83b91..73f330d507 100644 --- a/erpnext/demo/user/hr.py +++ b/erpnext/demo/user/hr.py @@ -92,13 +92,20 @@ def update_sanctioned_amount(expense_claim): expense.sanctioned_amount = sanctioned_amount def get_timesheet_based_salary_slip_employee(): - return frappe.get_all('Salary Structure', fields = ["distinct employee as name"], - filters = {'salary_slip_based_on_timesheet': 1}) + sal_struct = frappe.db.sql(""" + select name from `tabSalary Structure` + where salary_slip_based_on_timesheet = 1 + and docstatus != 2""") + if sal_struct: + employees = frappe.db.sql(""" + select employee from `tabSalary Structure Employee` + where parent IN %(sal_struct)s""", {"sal_struct": sal_struct}, as_dict=True) + return employees def make_timesheet_records(): employees = get_timesheet_based_salary_slip_employee() - for employee in employees: - ts = make_timesheet(employee.name, simulate = True, billable = 1, activity_type=get_random("Activity Type")) + for e in employees: + ts = make_timesheet(e.employee, simulate = True, billable = 1, activity_type=get_random("Activity Type")) rand = random.random() if rand >= 0.3: diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py index c80c660098..c7162b8cd3 100644 --- a/erpnext/hr/doctype/process_payroll/process_payroll.py +++ b/erpnext/hr/doctype/process_payroll/process_payroll.py @@ -10,6 +10,7 @@ from frappe.model.document import Document class ProcessPayroll(Document): + def get_emp_list(self): """ Returns list of active employees based on selected criteria @@ -18,15 +19,23 @@ class ProcessPayroll(Document): cond = self.get_filter_condition() cond += self.get_joining_releiving_condition() + sal_struct = frappe.db.sql(""" + select name from `tabSalary Structure` + where docstatus != 2 and + ifnull(salary_slip_based_on_timesheet,0) = 0""") + + if sal_struct: + cond += "and t2.parent IN %(sal_struct)s " + emp_list = frappe.db.sql(""" select t1.name - from `tabEmployee` t1, `tabSalary Structure` t2 - where t1.docstatus!=2 and t2.docstatus != 2 and - ifnull(t2.salary_slip_based_on_timesheet,0) = 0 and t1.name = t2.employee - %s """% cond) + from `tabEmployee` t1, `tabSalary Structure Employee` t2 + where t1.docstatus!=2 and t1.name = t2.employee + %s """% cond, {"sal_struct": sal_struct}) return emp_list + def get_filter_condition(self): self.check_mandatory()