Demo updated for new salary structure

This commit is contained in:
Kanchan Chauhan 2016-08-20 00:30:59 +05:30
parent 4cda566139
commit db197d593a
3 changed files with 47 additions and 19 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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()