sudo
This commit is contained in:
parent
637ef6c705
commit
8fd70a5197
|
|
@ -2413,7 +2413,6 @@ class HrPayslipRun(models.Model):
|
|||
|
||||
# Override function compute sheet in Payslip Batches
|
||||
|
||||
|
||||
def compute_sheet(self):
|
||||
payslips = self.env['hr.payslip']
|
||||
[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
|
||||
start_time = time.time()
|
||||
|
||||
#worked_days, emps, dictionary = [], [], []
|
||||
worked_days, emps, dictionary,emp_last_payslip,emp_priv_payslip = [], [], [], [],[]
|
||||
# worked_days, emps, dictionary = [], [], []
|
||||
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()
|
||||
|
||||
if self.department_ids:
|
||||
|
|
@ -2434,7 +2434,7 @@ class HrPayslipRun(models.Model):
|
|||
employee_contracts = self.env['hr.contract'].search(
|
||||
[('salary_scale', '=', self.salary_scale.id), ('state', '=', 'program_directory')]).filtered(
|
||||
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:
|
||||
emps.append(contract.employee_id.id)
|
||||
else:
|
||||
|
|
@ -2448,42 +2448,45 @@ class HrPayslipRun(models.Model):
|
|||
employees = self.env['hr.employee'].browse(data['employee_ids'])
|
||||
|
||||
################### 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),
|
||||
('payslip_run_id', '!=', self.id)])
|
||||
last_payslips = self.env['hr.payslip'].search(
|
||||
[('date_from', '>=', self.date_start), ('date_from', '<=', self.date_end),
|
||||
('payslip_run_id', '!=', self.id)])
|
||||
if last_payslips:
|
||||
for priv_pay in last_payslips:
|
||||
if employees:
|
||||
for emp in employees:
|
||||
if emp.id == priv_pay.employee_id.id:
|
||||
emp_last_payslip.append(emp.name)
|
||||
else :
|
||||
for emp in emps:
|
||||
if emp.id == priv_pay.employee_id.id:
|
||||
emp_last_payslip.append(emp.name)
|
||||
if emp_last_payslip:
|
||||
raise exceptions.Warning(
|
||||
_("Sorry, Salary has already been calculated This Month for Employees \n %s") % (emp_last_payslip))
|
||||
for priv_pay in last_payslips:
|
||||
if employees:
|
||||
for emp in employees:
|
||||
if emp.id == priv_pay.employee_id.id:
|
||||
emp_last_payslip.append(emp.name)
|
||||
else:
|
||||
for emp in emps:
|
||||
if emp.id == priv_pay.employee_id.id:
|
||||
emp_last_payslip.append(emp.name)
|
||||
if emp_last_payslip:
|
||||
raise exceptions.Warning(
|
||||
_("Sorry, Salary has already been calculated This Month for Employees \n %s") % (emp_last_payslip))
|
||||
########################################################################################
|
||||
last_month = self.date_start - relativedelta(months=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),
|
||||
('payslip_run_id', '!=', self.id)]).employee_id
|
||||
priv_payslips_month = self.env['hr.payslip'].search(
|
||||
[('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),
|
||||
('payslip_run_id', '!=', self.id)]).employee_id
|
||||
|
||||
if employees:
|
||||
diff_employee= employees-priv_payslips_month
|
||||
diff_employee = employees - priv_payslips_month
|
||||
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 :
|
||||
for emp in diff_employee:
|
||||
if emp in old_payslips:
|
||||
emp_priv_payslip.append(emp.name)
|
||||
if emp_priv_payslip:
|
||||
raise exceptions.Warning(
|
||||
_("Sorry, The Previous month's salary has Not been calculated for Employees \n %s") % (emp_priv_payslip))
|
||||
# if diff_employee and diff_employee in old_payslips :
|
||||
if diff_employee:
|
||||
for emp in diff_employee:
|
||||
if emp in old_payslips:
|
||||
emp_priv_payslip.append(emp.name)
|
||||
if emp_priv_payslip:
|
||||
raise exceptions.Warning(
|
||||
_("Sorry, The Previous month's salary has Not been calculated for Employees \n %s") % (
|
||||
emp_priv_payslip))
|
||||
|
||||
################### End ################################################################
|
||||
if employees:
|
||||
|
|
@ -2496,7 +2499,7 @@ class HrPayslipRun(models.Model):
|
|||
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(str(from_date), "%Y-%m-%d")))
|
||||
slip_data['value'].update({
|
||||
'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,
|
||||
})
|
||||
###########
|
||||
|
|
@ -2525,7 +2528,7 @@ class HrPayslipRun(models.Model):
|
|||
'company_id': employee.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
|
|
@ -2541,7 +2544,7 @@ class HrPayslipRun(models.Model):
|
|||
'number_of_days': duration,
|
||||
'number_of_hours': hours,
|
||||
'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:
|
||||
item_payslip = employee_slip_line
|
||||
payslips += item_payslip
|
||||
|
|
@ -2563,7 +2566,7 @@ class HrPayslipRun(models.Model):
|
|||
elif month_range > 30 and contract_end_date.day > 30:
|
||||
duration = relativedelta(contract_end_date, contract_start_date).days
|
||||
if duration == 0:
|
||||
duration = duration + 1
|
||||
duration = duration + 1
|
||||
elif month_range == 28 and contract_end_date.day == 28:
|
||||
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
|
||||
if not employee_slip_line:
|
||||
|
||||
|
||||
res = {
|
||||
'employee_id': employee.id,
|
||||
'name': slip_data['value'].get('name'),
|
||||
|
|
@ -2592,10 +2594,9 @@ class HrPayslipRun(models.Model):
|
|||
'company_id': employee.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
|
||||
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
# if p.employee_id != employee and p not in payslips:
|
||||
|
|
@ -2646,7 +2647,7 @@ class HrPayslipRun(models.Model):
|
|||
'company_id': employee.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
|
|
@ -2662,7 +2663,7 @@ class HrPayslipRun(models.Model):
|
|||
'number_of_days': duration,
|
||||
'number_of_hours': hours,
|
||||
'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:
|
||||
item_payslip = employee_slip_line
|
||||
payslips += item_payslip
|
||||
|
|
@ -2694,7 +2695,7 @@ class HrPayslipRun(models.Model):
|
|||
'company_id': employee.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
|
||||
payslips += self.env['hr.payslip'].create(res)
|
||||
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||
else:
|
||||
res = {
|
||||
'employee_id': employee.id,
|
||||
|
|
@ -2712,7 +2713,7 @@ class HrPayslipRun(models.Model):
|
|||
'company_id': employee.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
|
||||
payslips += self.env['hr.payslip'].create(res)
|
||||
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||
else:
|
||||
if employee.leaving_date and str(employee.first_hiring_date) < from_date:
|
||||
if str(employee.leaving_date) <= from_date:
|
||||
|
|
@ -2757,7 +2758,7 @@ class HrPayslipRun(models.Model):
|
|||
'credit_note': self.credit_note,
|
||||
'company_id': emp.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
|
|
@ -2773,7 +2774,7 @@ class HrPayslipRun(models.Model):
|
|||
'number_of_days': duration,
|
||||
'number_of_hours': hours,
|
||||
'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:
|
||||
item_payslip = employee_slip_line
|
||||
payslips += item_payslip
|
||||
|
|
@ -2794,7 +2795,7 @@ class HrPayslipRun(models.Model):
|
|||
elif month_range > 30 and contract_end_date.day > 30:
|
||||
duration = relativedelta(contract_end_date, contract_start_date).days
|
||||
if duration == 0:
|
||||
duration = duration + 1
|
||||
duration = duration + 1
|
||||
elif month_range == 28 and contract_end_date.day == 28:
|
||||
duration = relativedelta(contract_end_date, contract_start_date).days + 3
|
||||
elif month_range == 29 and contract_end_date.day == 29:
|
||||
|
|
@ -2817,7 +2818,7 @@ class HrPayslipRun(models.Model):
|
|||
'credit_note': self.credit_note,
|
||||
'company_id': emp.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
|
|
@ -2833,7 +2834,7 @@ class HrPayslipRun(models.Model):
|
|||
'number_of_days': duration,
|
||||
'number_of_hours': hours,
|
||||
'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:
|
||||
item_payslip = employee_slip_line
|
||||
payslips += item_payslip
|
||||
|
|
@ -2864,7 +2865,7 @@ class HrPayslipRun(models.Model):
|
|||
'credit_note': self.credit_note,
|
||||
'company_id': emp.company_id.id,
|
||||
'percentage': self.percentage}
|
||||
item_payslip = self.env['hr.payslip'].create(res)
|
||||
item_payslip = self.env['hr.payslip'].sudo().create(res)
|
||||
payslips += item_payslip
|
||||
# if pays:
|
||||
# for p in pays:
|
||||
|
|
@ -2880,7 +2881,7 @@ class HrPayslipRun(models.Model):
|
|||
'number_of_days': duration,
|
||||
'number_of_hours': hours,
|
||||
'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:
|
||||
item_payslip = employee_slip_line
|
||||
payslips += item_payslip
|
||||
|
|
@ -2891,7 +2892,7 @@ class HrPayslipRun(models.Model):
|
|||
# else:
|
||||
# payslips += item_payslip
|
||||
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 str(emp.leaving_date) <= from_date:
|
||||
pass
|
||||
|
|
@ -2914,9 +2915,9 @@ class HrPayslipRun(models.Model):
|
|||
# if pays:
|
||||
# for p in pays:
|
||||
# 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:
|
||||
payslips += self.env['hr.payslip'].create(res)
|
||||
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||
else:
|
||||
res = {
|
||||
'employee_id': emp.id,
|
||||
|
|
@ -2936,9 +2937,9 @@ class HrPayslipRun(models.Model):
|
|||
# if pays:
|
||||
# for p in pays:
|
||||
# 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:
|
||||
payslips += self.env['hr.payslip'].create(res)
|
||||
payslips += self.env['hr.payslip'].sudo().create(res)
|
||||
else:
|
||||
if emp.leaving_date and str(emp.first_hiring_date) < from_date:
|
||||
if str(emp.leaving_date) <= from_date:
|
||||
|
|
|
|||
Loading…
Reference in New Issue