commit
defc02a119
|
|
@ -2413,7 +2413,6 @@ class HrPayslipRun(models.Model):
|
||||||
|
|
||||||
# Override function compute sheet in Payslip Batches
|
# Override function compute sheet in Payslip Batches
|
||||||
|
|
||||||
|
|
||||||
def compute_sheet(self):
|
def compute_sheet(self):
|
||||||
payslips = self.env['hr.payslip']
|
payslips = self.env['hr.payslip']
|
||||||
[data] = self.read()
|
[data] = self.read()
|
||||||
|
|
@ -2423,10 +2422,11 @@ class HrPayslipRun(models.Model):
|
||||||
holiday_end_date = str(self.holiday_end_date) if self.holiday_end_date else False
|
holiday_end_date = str(self.holiday_end_date) if self.holiday_end_date else False
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
#worked_days, emps, dictionary = [], [], []
|
# worked_days, emps, dictionary = [], [], []
|
||||||
worked_days, emps, dictionary,emp_last_payslip,emp_priv_payslip = [], [], [], [],[]
|
worked_days, emps, dictionary, emp_last_payslip, emp_priv_payslip = [], [], [], [], []
|
||||||
|
|
||||||
if datetime.strptime(str(from_date), "%Y-%m-%d").date().month == datetime.strptime(str(to_date),"%Y-%m-%d").date().month:
|
if datetime.strptime(str(from_date), "%Y-%m-%d").date().month == datetime.strptime(str(to_date),
|
||||||
|
"%Y-%m-%d").date().month:
|
||||||
month_date = datetime.strptime(str(from_date), "%Y-%m-%d").date()
|
month_date = datetime.strptime(str(from_date), "%Y-%m-%d").date()
|
||||||
|
|
||||||
if self.department_ids:
|
if self.department_ids:
|
||||||
|
|
@ -2434,7 +2434,7 @@ class HrPayslipRun(models.Model):
|
||||||
employee_contracts = self.env['hr.contract'].search(
|
employee_contracts = self.env['hr.contract'].search(
|
||||||
[('salary_scale', '=', self.salary_scale.id), ('state', '=', 'program_directory')]).filtered(
|
[('salary_scale', '=', self.salary_scale.id), ('state', '=', 'program_directory')]).filtered(
|
||||||
lambda item: item.employee_id.department_id == dep and item.employee_id.state == 'open'
|
lambda item: item.employee_id.department_id == dep and item.employee_id.state == 'open'
|
||||||
and str(item.employee_id.first_hiring_date) <= to_date)
|
and str(item.employee_id.first_hiring_date) <= to_date)
|
||||||
for contract in employee_contracts:
|
for contract in employee_contracts:
|
||||||
emps.append(contract.employee_id.id)
|
emps.append(contract.employee_id.id)
|
||||||
else:
|
else:
|
||||||
|
|
@ -2448,42 +2448,45 @@ class HrPayslipRun(models.Model):
|
||||||
employees = self.env['hr.employee'].browse(data['employee_ids'])
|
employees = self.env['hr.employee'].browse(data['employee_ids'])
|
||||||
|
|
||||||
################### Employee run payslip one in month and previously month #######
|
################### Employee run payslip one in month and previously month #######
|
||||||
last_payslips = self.env['hr.payslip'].search([('date_from', '>=', self.date_start),('date_from', '<=', self.date_end),
|
last_payslips = self.env['hr.payslip'].search(
|
||||||
('payslip_run_id', '!=', self.id)])
|
[('date_from', '>=', self.date_start), ('date_from', '<=', self.date_end),
|
||||||
|
('payslip_run_id', '!=', self.id)])
|
||||||
if last_payslips:
|
if last_payslips:
|
||||||
for priv_pay in last_payslips:
|
for priv_pay in last_payslips:
|
||||||
if employees:
|
if employees:
|
||||||
for emp in employees:
|
for emp in employees:
|
||||||
if emp.id == priv_pay.employee_id.id:
|
if emp.id == priv_pay.employee_id.id:
|
||||||
emp_last_payslip.append(emp.name)
|
emp_last_payslip.append(emp.name)
|
||||||
else :
|
else:
|
||||||
for emp in emps:
|
for emp in emps:
|
||||||
if emp.id == priv_pay.employee_id.id:
|
if emp.id == priv_pay.employee_id.id:
|
||||||
emp_last_payslip.append(emp.name)
|
emp_last_payslip.append(emp.name)
|
||||||
if emp_last_payslip:
|
if emp_last_payslip:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_("Sorry, Salary has already been calculated This Month for Employees \n %s") % (emp_last_payslip))
|
_("Sorry, Salary has already been calculated This Month for Employees \n %s") % (emp_last_payslip))
|
||||||
########################################################################################
|
########################################################################################
|
||||||
last_month = self.date_start - relativedelta(months=1)
|
last_month = self.date_start - relativedelta(months=1)
|
||||||
end_last_month = self.date_start - relativedelta(days=1)
|
end_last_month = self.date_start - relativedelta(days=1)
|
||||||
priv_payslips_month = self.env['hr.payslip'].search([('date_from', '>=', last_month),('date_from', '<=', end_last_month),
|
priv_payslips_month = self.env['hr.payslip'].search(
|
||||||
('payslip_run_id', '!=', self.id)]).employee_id
|
[('date_from', '>=', last_month), ('date_from', '<=', end_last_month),
|
||||||
|
('payslip_run_id', '!=', self.id)]).employee_id
|
||||||
old_payslips = self.env['hr.payslip'].search([('date_from', '<', self.date_start),
|
old_payslips = self.env['hr.payslip'].search([('date_from', '<', self.date_start),
|
||||||
('payslip_run_id', '!=', self.id)]).employee_id
|
('payslip_run_id', '!=', self.id)]).employee_id
|
||||||
|
|
||||||
if employees:
|
if employees:
|
||||||
diff_employee= employees-priv_payslips_month
|
diff_employee = employees - priv_payslips_month
|
||||||
else:
|
else:
|
||||||
diff_employee= emps-priv_payslips_month
|
diff_employee = emps - priv_payslips_month
|
||||||
|
|
||||||
#if diff_employee and diff_employee in old_payslips :
|
# if diff_employee and diff_employee in old_payslips :
|
||||||
if diff_employee :
|
if diff_employee:
|
||||||
for emp in diff_employee:
|
for emp in diff_employee:
|
||||||
if emp in old_payslips:
|
if emp in old_payslips:
|
||||||
emp_priv_payslip.append(emp.name)
|
emp_priv_payslip.append(emp.name)
|
||||||
if emp_priv_payslip:
|
if emp_priv_payslip:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_("Sorry, The Previous month's salary has Not been calculated for Employees \n %s") % (emp_priv_payslip))
|
_("Sorry, The Previous month's salary has Not been calculated for Employees \n %s") % (
|
||||||
|
emp_priv_payslip))
|
||||||
|
|
||||||
################### End ################################################################
|
################### End ################################################################
|
||||||
if employees:
|
if employees:
|
||||||
|
|
@ -2496,7 +2499,7 @@ class HrPayslipRun(models.Model):
|
||||||
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(str(from_date), "%Y-%m-%d")))
|
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(str(from_date), "%Y-%m-%d")))
|
||||||
slip_data['value'].update({
|
slip_data['value'].update({
|
||||||
'name': _('Salary Slip of %s for %s') % (
|
'name': _('Salary Slip of %s for %s') % (
|
||||||
employee.name, tools.ustr(babel.dates.format_date(date=ttyme, format='MMMM-y',locale=locale))),
|
employee.name, tools.ustr(babel.dates.format_date(date=ttyme, format='MMMM-y', locale=locale))),
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
})
|
})
|
||||||
###########
|
###########
|
||||||
|
|
@ -2525,7 +2528,7 @@ class HrPayslipRun(models.Model):
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
|
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
|
|
@ -2541,7 +2544,7 @@ class HrPayslipRun(models.Model):
|
||||||
'number_of_days': duration,
|
'number_of_days': duration,
|
||||||
'number_of_hours': hours,
|
'number_of_hours': hours,
|
||||||
'contract_id': employee.contract_id.id}
|
'contract_id': employee.contract_id.id}
|
||||||
worked_days += self.env['hr.payslip.worked_days'].create(days)
|
worked_days += self.env['hr.payslip.worked_days'].sudo().create(days)
|
||||||
else:
|
else:
|
||||||
item_payslip = employee_slip_line
|
item_payslip = employee_slip_line
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
@ -2563,7 +2566,7 @@ class HrPayslipRun(models.Model):
|
||||||
elif month_range > 30 and contract_end_date.day > 30:
|
elif month_range > 30 and contract_end_date.day > 30:
|
||||||
duration = relativedelta(contract_end_date, contract_start_date).days
|
duration = relativedelta(contract_end_date, contract_start_date).days
|
||||||
if duration == 0:
|
if duration == 0:
|
||||||
duration = duration + 1
|
duration = duration + 1
|
||||||
elif month_range == 28 and contract_end_date.day == 28:
|
elif month_range == 28 and contract_end_date.day == 28:
|
||||||
duration = relativedelta(contract_end_date, contract_start_date).days + 3
|
duration = relativedelta(contract_end_date, contract_start_date).days + 3
|
||||||
|
|
||||||
|
|
@ -2576,7 +2579,6 @@ class HrPayslipRun(models.Model):
|
||||||
hours = (float((contract_end_date - contract_start_date).seconds) / 86400) * 24
|
hours = (float((contract_end_date - contract_start_date).seconds) / 86400) * 24
|
||||||
if not employee_slip_line:
|
if not employee_slip_line:
|
||||||
|
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
'employee_id': employee.id,
|
'employee_id': employee.id,
|
||||||
'name': slip_data['value'].get('name'),
|
'name': slip_data['value'].get('name'),
|
||||||
|
|
@ -2592,10 +2594,9 @@ class HrPayslipRun(models.Model):
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
|
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
||||||
|
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
# if p.employee_id != employee and p not in payslips:
|
# if p.employee_id != employee and p not in payslips:
|
||||||
|
|
@ -2646,7 +2647,7 @@ class HrPayslipRun(models.Model):
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
|
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
|
|
@ -2662,7 +2663,7 @@ class HrPayslipRun(models.Model):
|
||||||
'number_of_days': duration,
|
'number_of_days': duration,
|
||||||
'number_of_hours': hours,
|
'number_of_hours': hours,
|
||||||
'contract_id': employee.contract_id.id}
|
'contract_id': employee.contract_id.id}
|
||||||
worked_days += self.env['hr.payslip.worked_days'].create(days)
|
worked_days += self.env['hr.payslip.worked_days'].sudo().create(days)
|
||||||
else:
|
else:
|
||||||
item_payslip = employee_slip_line
|
item_payslip = employee_slip_line
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
@ -2694,7 +2695,7 @@ class HrPayslipRun(models.Model):
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
|
|
||||||
payslips += self.env['hr.payslip'].create(res)
|
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
else:
|
else:
|
||||||
res = {
|
res = {
|
||||||
'employee_id': employee.id,
|
'employee_id': employee.id,
|
||||||
|
|
@ -2712,7 +2713,7 @@ class HrPayslipRun(models.Model):
|
||||||
'company_id': employee.company_id.id,
|
'company_id': employee.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
|
|
||||||
payslips += self.env['hr.payslip'].create(res)
|
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
else:
|
else:
|
||||||
if employee.leaving_date and str(employee.first_hiring_date) < from_date:
|
if employee.leaving_date and str(employee.first_hiring_date) < from_date:
|
||||||
if str(employee.leaving_date) <= from_date:
|
if str(employee.leaving_date) <= from_date:
|
||||||
|
|
@ -2757,7 +2758,7 @@ class HrPayslipRun(models.Model):
|
||||||
'credit_note': self.credit_note,
|
'credit_note': self.credit_note,
|
||||||
'company_id': emp.company_id.id,
|
'company_id': emp.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
|
|
@ -2773,7 +2774,7 @@ class HrPayslipRun(models.Model):
|
||||||
'number_of_days': duration,
|
'number_of_days': duration,
|
||||||
'number_of_hours': hours,
|
'number_of_hours': hours,
|
||||||
'contract_id': emp.contract_id.id}
|
'contract_id': emp.contract_id.id}
|
||||||
worked_days += self.env['hr.payslip.worked_days'].create(days)
|
worked_days += self.env['hr.payslip.worked_days'].sudo().create(days)
|
||||||
else:
|
else:
|
||||||
item_payslip = employee_slip_line
|
item_payslip = employee_slip_line
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
@ -2794,7 +2795,7 @@ class HrPayslipRun(models.Model):
|
||||||
elif month_range > 30 and contract_end_date.day > 30:
|
elif month_range > 30 and contract_end_date.day > 30:
|
||||||
duration = relativedelta(contract_end_date, contract_start_date).days
|
duration = relativedelta(contract_end_date, contract_start_date).days
|
||||||
if duration == 0:
|
if duration == 0:
|
||||||
duration = duration + 1
|
duration = duration + 1
|
||||||
elif month_range == 28 and contract_end_date.day == 28:
|
elif month_range == 28 and contract_end_date.day == 28:
|
||||||
duration = relativedelta(contract_end_date, contract_start_date).days + 3
|
duration = relativedelta(contract_end_date, contract_start_date).days + 3
|
||||||
elif month_range == 29 and contract_end_date.day == 29:
|
elif month_range == 29 and contract_end_date.day == 29:
|
||||||
|
|
@ -2817,7 +2818,7 @@ class HrPayslipRun(models.Model):
|
||||||
'credit_note': self.credit_note,
|
'credit_note': self.credit_note,
|
||||||
'company_id': emp.company_id.id,
|
'company_id': emp.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
|
|
@ -2833,7 +2834,7 @@ class HrPayslipRun(models.Model):
|
||||||
'number_of_days': duration,
|
'number_of_days': duration,
|
||||||
'number_of_hours': hours,
|
'number_of_hours': hours,
|
||||||
'contract_id': emp.contract_id.id}
|
'contract_id': emp.contract_id.id}
|
||||||
worked_days += self.env['hr.payslip.worked_days'].create(days)
|
worked_days += self.env['hr.payslip.worked_days'].sudo().create(days)
|
||||||
else:
|
else:
|
||||||
item_payslip = employee_slip_line
|
item_payslip = employee_slip_line
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
@ -2864,7 +2865,7 @@ class HrPayslipRun(models.Model):
|
||||||
'credit_note': self.credit_note,
|
'credit_note': self.credit_note,
|
||||||
'company_id': emp.company_id.id,
|
'company_id': emp.company_id.id,
|
||||||
'percentage': self.percentage}
|
'percentage': self.percentage}
|
||||||
item_payslip = self.env['hr.payslip'].create(res)
|
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
|
|
@ -2880,7 +2881,7 @@ class HrPayslipRun(models.Model):
|
||||||
'number_of_days': duration,
|
'number_of_days': duration,
|
||||||
'number_of_hours': hours,
|
'number_of_hours': hours,
|
||||||
'contract_id': emp.contract_id.id}
|
'contract_id': emp.contract_id.id}
|
||||||
worked_days += self.env['hr.payslip.worked_days'].create(days)
|
worked_days += self.env['hr.payslip.worked_days'].sudo().create(days)
|
||||||
else:
|
else:
|
||||||
item_payslip = employee_slip_line
|
item_payslip = employee_slip_line
|
||||||
payslips += item_payslip
|
payslips += item_payslip
|
||||||
|
|
@ -2891,7 +2892,7 @@ class HrPayslipRun(models.Model):
|
||||||
# else:
|
# else:
|
||||||
# payslips += item_payslip
|
# payslips += item_payslip
|
||||||
else:
|
else:
|
||||||
if not employee_slip_line and str(emp.first_hiring_date) < from_date:
|
if not employee_slip_line and str(emp.first_hiring_date) < from_date:
|
||||||
if emp.leaving_date:
|
if emp.leaving_date:
|
||||||
if str(emp.leaving_date) <= from_date:
|
if str(emp.leaving_date) <= from_date:
|
||||||
pass
|
pass
|
||||||
|
|
@ -2914,9 +2915,9 @@ class HrPayslipRun(models.Model):
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
# if p.employee_id != emp and p not in payslips:
|
# if p.employee_id != emp and p not in payslips:
|
||||||
# payslips += self.env['hr.payslip'].create(res)
|
# payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
# else:
|
# else:
|
||||||
payslips += self.env['hr.payslip'].create(res)
|
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
else:
|
else:
|
||||||
res = {
|
res = {
|
||||||
'employee_id': emp.id,
|
'employee_id': emp.id,
|
||||||
|
|
@ -2936,9 +2937,9 @@ class HrPayslipRun(models.Model):
|
||||||
# if pays:
|
# if pays:
|
||||||
# for p in pays:
|
# for p in pays:
|
||||||
# if p.employee_id != emp and p not in payslips:
|
# if p.employee_id != emp and p not in payslips:
|
||||||
# payslips += self.env['hr.payslip'].create(res)
|
# payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
# else:
|
# else:
|
||||||
payslips += self.env['hr.payslip'].create(res)
|
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||||
else:
|
else:
|
||||||
if emp.leaving_date and str(emp.first_hiring_date) < from_date:
|
if emp.leaving_date and str(emp.first_hiring_date) < from_date:
|
||||||
if str(emp.leaving_date) <= from_date:
|
if str(emp.leaving_date) <= from_date:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue