Merge pull request #6127 from KanchanChauhan/demo-fixes-salary
Demo updated for new salary structure
diff --git a/erpnext/demo/setup_data.py b/erpnext/demo/setup_data.py
index 1be2cac..97dc894 100644
--- a/erpnext/demo/setup_data.py
+++ b/erpnext/demo/setup_data.py
@@ -290,9 +290,13 @@
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 @@
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 3d5ac83..73f330d 100644
--- a/erpnext/demo/user/hr.py
+++ b/erpnext/demo/user/hr.py
@@ -92,13 +92,20 @@
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 c80c660..c7162b8 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.py
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.py
@@ -10,6 +10,7 @@
class ProcessPayroll(Document):
+
def get_emp_list(self):
"""
Returns list of active employees based on selected criteria
@@ -18,15 +19,23 @@
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()