commit
3f1ea07275
|
|
@ -97,45 +97,41 @@ class ReportAttendancePublic(models.AbstractModel):
|
|||
from_date = data['form']['from_date']
|
||||
to_date = data['form']['to_date']
|
||||
domain = [('date', '>=', from_date), ('date', '<=', to_date)]
|
||||
data = []
|
||||
final_dic = {}
|
||||
key_list = []
|
||||
total_dic = {}
|
||||
mykey = []
|
||||
|
||||
resource = self.env['resource.calendar'].browse(resource_calender_id)
|
||||
if resource and not employee_ids:
|
||||
if resource.employee_ids:
|
||||
for emp in resource.employee_ids:
|
||||
employee_ids.append(emp.id)
|
||||
# if resource_calender_id:
|
||||
# contract_ids = self.env['hr.contract'].search([('state', '=', 'program_directory'), ('resource_calendar_id', '=', resource_calender_id)])
|
||||
# for con in contract_ids:
|
||||
# employee_ids.append(con.employee_id.id)
|
||||
# print(">>>>>>>>>>>>>>>>>>>>>>>employeesemployees",employees)
|
||||
if resource_calender_id and not employee_ids:
|
||||
resource = self.env['resource.calendar'].browse(resource_calender_id)
|
||||
employee_ids = resource.employee_ids.ids
|
||||
|
||||
if employee_ids:
|
||||
last_employee_ids = list(set(employee_ids))
|
||||
domain.append(('employee_id', 'in', last_employee_ids))
|
||||
domain.append(('employee_id', 'in', list(set(employee_ids))))
|
||||
|
||||
attendance_transaction_ids = self.env['hr.attendance.transaction'].search(domain)
|
||||
employees = attendance_transaction_ids.mapped('employee_id.name')
|
||||
employee_ids = attendance_transaction_ids.mapped('employee_id')
|
||||
emp_data = []
|
||||
for emp in employee_ids:
|
||||
emp_data.append({'job': emp.sudo().job_id.name, 'department': emp.department_id.name,
|
||||
'emp_no': emp.emp_no, 'emp_namw': emp.name})
|
||||
grouped_data = collections.defaultdict(list)
|
||||
emp_data_dict = {}
|
||||
for item in emp_data:
|
||||
grouped_data[item['emp_namw']].append(item)
|
||||
for key, value in grouped_data.items():
|
||||
emp_data_dict[key] = list(value)
|
||||
|
||||
employee_records = attendance_transaction_ids.mapped('employee_id')
|
||||
employees = employee_records.mapped('name')
|
||||
|
||||
emp_data_dict = collections.defaultdict(list)
|
||||
for emp in employee_records:
|
||||
emp_data_dict[emp.name].append({
|
||||
'job': emp.sudo().job_id.name,
|
||||
'department': emp.department_id.name,
|
||||
'emp_no': emp.emp_no,
|
||||
'emp_namw': emp.name,
|
||||
})
|
||||
|
||||
if type == 'late':
|
||||
if shift_mode != 'both':
|
||||
if shift_mode == 'first':
|
||||
attendance_transaction_ids = attendance_transaction_ids.filtered(lambda r: r.sequence == 1)
|
||||
elif shift_mode == 'second':
|
||||
attendance_transaction_ids = attendance_transaction_ids.filtered(lambda r: r.sequence == 2)
|
||||
data = []
|
||||
final_dic = collections.defaultdict(list)
|
||||
key_list = []
|
||||
total_dic = {}
|
||||
grouped_attendance = collections.defaultdict(list)
|
||||
for resource in attendance_transaction_ids:
|
||||
grouped_attendance[resource.employee_id.name].append(resource)
|
||||
note = ''
|
||||
if resource.is_absent:
|
||||
note = 'غياب'
|
||||
|
|
@ -170,49 +166,36 @@ class ReportAttendancePublic(models.AbstractModel):
|
|||
'employee_name': resource.employee_id.name
|
||||
})
|
||||
data = sorted(data, key=lambda d: (d['date'], d['calendar_id']))
|
||||
for emp in employees:
|
||||
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
|
||||
total_lateness = sum(list_cat.mapped('lateness'))
|
||||
total_early_exit = sum(list_cat.mapped('early_exit'))
|
||||
total_late_early = str(datetime.timedelta(minutes=total_early_exit + total_lateness))
|
||||
total_extra_hours = sum(list_cat.mapped('additional_hours'))
|
||||
total_extra_hours = str(datetime.timedelta(minutes=total_extra_hours))
|
||||
list_missing_punch = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and
|
||||
not r.public_holiday and
|
||||
not r.normal_leave and
|
||||
((r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
|
||||
for emp_name, records in grouped_attendance.items():
|
||||
total_lateness = sum(r.lateness for r in records)
|
||||
total_early_exit = sum(r.early_exit for r in records)
|
||||
total_extra_hours = sum(r.additional_hours for r in records)
|
||||
total_missing_punch = sum(
|
||||
1 for r in records if not r.public_holiday and not r.normal_leave and
|
||||
((r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
|
||||
)
|
||||
total_missing_punch = len(list_missing_punch)
|
||||
|
||||
list_absent = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.is_absent == True)
|
||||
total_absent = len(list_absent)
|
||||
list_not_log_in = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.sign_in == 0.0)
|
||||
total_not_sig_in = len(list_not_log_in)
|
||||
list_not_log_out = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.sign_out == 0.0)
|
||||
list_leave = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and (r.normal_leave or r.approve_personal_permission))
|
||||
total_not_sig_out = len(list_not_log_out)
|
||||
total_leave = len(list_leave)
|
||||
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
|
||||
"total_extra_hours": total_extra_hours, "total_late_early": total_late_early,
|
||||
total_absent = sum(1 for r in records if r.is_absent)
|
||||
total_not_sig_in = sum(1 for r in records if r.sign_in == 0.0)
|
||||
total_not_sig_out = sum(1 for r in records if r.sign_out == 0.0)
|
||||
total_leave = sum(1 for r in records if r.normal_leave or r.approve_personal_permission)
|
||||
total_dic[emp_name] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
|
||||
"total_extra_hours": str(datetime.timedelta(minutes=total_extra_hours)), "total_late_early": str(datetime.timedelta(minutes=total_lateness + total_early_exit)),
|
||||
"total_leave": total_leave, 'total_absent': total_absent,
|
||||
'total_not_sig_in': total_not_sig_in,
|
||||
'total_not_sig_out': total_not_sig_out,
|
||||
'total_missing_punch':total_missing_punch}
|
||||
grouped = collections.defaultdict(list)
|
||||
|
||||
for item in data:
|
||||
grouped[item['employee_name']].append(item)
|
||||
for key, value in grouped.items():
|
||||
final_dic[key] = list(value)
|
||||
key_list.append(key)
|
||||
final_dic[item['employee_name']].append(item)
|
||||
key_list.append(item['employee_name'])
|
||||
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return final_dic, mykey, total_dic, emp_data_dict
|
||||
return final_dic, mykey, total_dic, dict(emp_data_dict)
|
||||
|
||||
elif type == 'absent':
|
||||
data = []
|
||||
final_dic = collections.defaultdict(list)
|
||||
key_list = []
|
||||
for resource in attendance_transaction_ids.filtered(lambda r: r.is_absent == True):
|
||||
data.append({
|
||||
'date': resource.date,
|
||||
|
|
@ -220,25 +203,30 @@ class ReportAttendancePublic(models.AbstractModel):
|
|||
'employee_id_department_id_name': resource.employee_id.department_id.name,
|
||||
'day': datetime.datetime.strptime(str(resource.date), '%Y-%m-%d').date().strftime('%A'),
|
||||
})
|
||||
grouped = collections.defaultdict(list)
|
||||
for item in data:
|
||||
grouped[item['employee_id_department_id_name']].append(item)
|
||||
for key, value in grouped.items():
|
||||
final_dic[key] = list(value)
|
||||
key_list.append(key)
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return final_dic, mykey, '', emp_data_dict
|
||||
elif type == 'employee':
|
||||
for emp in employees:
|
||||
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
|
||||
total_lateness = sum(list_cat.mapped('lateness'))
|
||||
total_lateness = str(datetime.timedelta(minutes=total_lateness))
|
||||
total_early_exit = sum(list_cat.mapped('early_exit'))
|
||||
total_early_exit = str(datetime.timedelta(minutes=total_early_exit))
|
||||
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit}
|
||||
key_list.append(emp)
|
||||
for item in data:
|
||||
final_dic[item['employee_id_department_id_name']].append(item)
|
||||
key_list.append(item['employee_id_department_id_name'])
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return '', mykey, total_dic, emp_data_dict
|
||||
return dict(final_dic), mykey, '', dict(emp_data_dict)
|
||||
elif type == 'employee':
|
||||
key_list = []
|
||||
total_dic = {}
|
||||
grouped_attendance = collections.defaultdict(list)
|
||||
for record in attendance_transaction_ids:
|
||||
grouped_attendance[record.employee_id.name].append(record)
|
||||
|
||||
for emp_name, records in grouped_attendance.items():
|
||||
total_lateness = sum(r.lateness for r in records)
|
||||
total_early_exit = sum(r.early_exit for r in records)
|
||||
|
||||
total_dic[emp_name] = {
|
||||
'total_lateness': str(datetime.timedelta(minutes=total_lateness)),
|
||||
'total_early_exit': str(datetime.timedelta(minutes=total_early_exit)),
|
||||
}
|
||||
key_list.append(emp_name)
|
||||
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return '', mykey, total_dic, dict(emp_data_dict)
|
||||
|
||||
|
||||
@api.model
|
||||
|
|
@ -325,10 +313,6 @@ class ReportAttendancePublic(models.AbstractModel):
|
|||
'early_exit_approved': hhmm(sum(row['early_exit_approved_int'] for row in summary_rows)),
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return {
|
||||
'doc_ids': data['ids'],
|
||||
'doc_model': data['model'],
|
||||
|
|
@ -361,44 +345,40 @@ class ReportAttendancegeneral(models.AbstractModel):
|
|||
from_date = data['form']['from_date']
|
||||
to_date = data['form']['to_date']
|
||||
domain = [('date', '>=', from_date), ('date', '<=', to_date)]
|
||||
data = []
|
||||
final_dic = {}
|
||||
key_list = []
|
||||
total_dic = {}
|
||||
mykey = []
|
||||
resource = self.env['resource.calendar'].browse(resource_calender_id)
|
||||
if resource and not employee_ids:
|
||||
if resource.employee_ids:
|
||||
for emp in resource.employee_ids:
|
||||
employee_ids.append(emp.id)
|
||||
# if resource_calender_id:
|
||||
# contract_ids = self.env['hr.contract'].search([('state', '=', 'program_directory'), ('resource_calendar_id', '=', resource_calender_id)])
|
||||
# for con in contract_ids:
|
||||
# employee_ids.append(con.employee_id.id)
|
||||
# print(">>>>>>>>>>>>>>>>>>>>>>>employeesemployees",employees)
|
||||
|
||||
if resource_calender_id and not employee_ids:
|
||||
resource = self.env['resource.calendar'].browse(resource_calender_id)
|
||||
employee_ids = resource.employee_ids.ids
|
||||
|
||||
if employee_ids:
|
||||
last_employee_ids = list(set(employee_ids))
|
||||
domain.append(('employee_id', 'in', last_employee_ids))
|
||||
domain.append(('employee_id', 'in', list(set(employee_ids))))
|
||||
|
||||
attendance_transaction_ids = self.env['hr.attendance.transaction'].search(domain)
|
||||
employees = attendance_transaction_ids.mapped('employee_id.name')
|
||||
employee_ids = attendance_transaction_ids.mapped('employee_id')
|
||||
emp_data = []
|
||||
for emp in employee_ids:
|
||||
emp_data.append({'job': emp.sudo().job_id.name, 'department': emp.department_id.name,
|
||||
'emp_no': emp.emp_no, 'emp_namw': emp.name})
|
||||
grouped_data = collections.defaultdict(list)
|
||||
emp_data_dict = {}
|
||||
for item in emp_data:
|
||||
grouped_data[item['emp_namw']].append(item)
|
||||
for key, value in grouped_data.items():
|
||||
emp_data_dict[key] = list(value)
|
||||
employee_records = attendance_transaction_ids.mapped('employee_id')
|
||||
employees = employee_records.mapped('name')
|
||||
|
||||
emp_data_dict = collections.defaultdict(list)
|
||||
for emp in employee_records:
|
||||
emp_data_dict[emp.name].append({
|
||||
'job': emp.sudo().job_id.name,
|
||||
'department': emp.department_id.name,
|
||||
'emp_no': emp.emp_no,
|
||||
'emp_namw': emp.name,
|
||||
})
|
||||
|
||||
if type == 'late':
|
||||
if shift_mode != 'both':
|
||||
if shift_mode == 'first':
|
||||
attendance_transaction_ids = attendance_transaction_ids.filtered(lambda r: r.sequence == 1)
|
||||
elif shift_mode == 'second':
|
||||
attendance_transaction_ids = attendance_transaction_ids.filtered(lambda r: r.sequence == 2)
|
||||
data = []
|
||||
final_dic = collections.defaultdict(list)
|
||||
total_dic = {}
|
||||
key_list = []
|
||||
grouped_attendance = collections.defaultdict(list)
|
||||
for resource in attendance_transaction_ids:
|
||||
grouped_attendance[resource.employee_id.name].append(resource)
|
||||
note = ''
|
||||
if resource.is_absent:
|
||||
note = 'غياب'
|
||||
|
|
@ -434,50 +414,37 @@ class ReportAttendancegeneral(models.AbstractModel):
|
|||
})
|
||||
|
||||
data = sorted(data, key=lambda d: d['date'])
|
||||
for emp in employees:
|
||||
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
|
||||
total_lateness = sum(list_cat.mapped('lateness'))
|
||||
total_early_exit = sum(list_cat.mapped('early_exit'))
|
||||
total_late_early = str(datetime.timedelta(minutes=total_early_exit + total_lateness))
|
||||
total_extra_hours = sum(list_cat.mapped('additional_hours'))
|
||||
total_extra_hours = str(datetime.timedelta(minutes=total_extra_hours))
|
||||
|
||||
list_missing_punch = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and
|
||||
not r.public_holiday and
|
||||
not r.normal_leave and
|
||||
((r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
|
||||
for emp_name, recs in grouped_attendance.items():
|
||||
total_lateness = sum(r.lateness for r in recs)
|
||||
total_early_exit = sum(r.early_exit for r in recs)
|
||||
total_extra_hours = sum(r.additional_hours for r in recs)
|
||||
total_missing_punch = sum(
|
||||
1 for r in recs if not r.public_holiday and not r.normal_leave and (
|
||||
(r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
|
||||
)
|
||||
total_missing_punch = len(list_missing_punch)
|
||||
|
||||
list_absent = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.is_absent == True)
|
||||
total_absent = len(list_absent)
|
||||
list_not_log_in = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.sign_in == 0.0)
|
||||
total_not_sig_in = len(list_not_log_in)
|
||||
list_not_log_out = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and r.sign_out == 0.0)
|
||||
list_leave = attendance_transaction_ids.filtered(
|
||||
lambda r: r.employee_id.name == emp and (r.normal_leave or r.approve_personal_permission))
|
||||
total_not_sig_out = len(list_not_log_out)
|
||||
total_leave = len(list_leave)
|
||||
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
|
||||
"total_extra_hours": total_extra_hours, "total_late_early": total_late_early,
|
||||
total_absent = sum(1 for r in recs if r.is_absent)
|
||||
total_not_sig_in = sum(1 for r in recs if r.sign_in == 0.0)
|
||||
total_not_sig_out = sum(1 for r in recs if r.sign_out == 0.0)
|
||||
total_leave = sum(1 for r in recs if r.normal_leave or r.approve_personal_permission)
|
||||
total_dic[emp_name] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
|
||||
"total_extra_hours": str(datetime.timedelta(minutes=total_extra_hours)), "total_late_early": str(datetime.timedelta(minutes=total_lateness + total_early_exit)),
|
||||
"total_leave": total_leave, 'total_absent': total_absent,
|
||||
'total_not_sig_in': total_not_sig_in,
|
||||
'total_not_sig_out': total_not_sig_out,
|
||||
'total_missing_punch':total_missing_punch}
|
||||
grouped = collections.defaultdict(list)
|
||||
|
||||
for item in data:
|
||||
grouped[item['employee_name']].append(item)
|
||||
for key, value in grouped.items():
|
||||
final_dic[key] = list(value)
|
||||
key_list.append(key)
|
||||
final_dic[item['employee_name']].append(item)
|
||||
key_list.append(item['employee_name'])
|
||||
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return final_dic, mykey, total_dic, emp_data_dict
|
||||
return final_dic, mykey, total_dic, dict(emp_data_dict)
|
||||
|
||||
elif type == 'absent':
|
||||
data = []
|
||||
grouped = collections.defaultdict(list)
|
||||
key_list = []
|
||||
|
||||
for resource in attendance_transaction_ids.filtered(lambda r: r.is_absent == True):
|
||||
data.append({
|
||||
'date': resource.date,
|
||||
|
|
@ -485,25 +452,30 @@ class ReportAttendancegeneral(models.AbstractModel):
|
|||
'employee_id_department_id_name': resource.employee_id.department_id.name,
|
||||
'day': datetime.datetime.strptime(str(resource.date), '%Y-%m-%d').date().strftime('%A'),
|
||||
})
|
||||
grouped = collections.defaultdict(list)
|
||||
for item in data:
|
||||
grouped[item['employee_id_department_id_name']].append(item)
|
||||
for key, value in grouped.items():
|
||||
final_dic[key] = list(value)
|
||||
key_list.append(key)
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return final_dic, mykey, '', emp_data_dict
|
||||
elif type == 'employee':
|
||||
for emp in employees:
|
||||
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
|
||||
total_lateness = sum(list_cat.mapped('lateness'))
|
||||
total_lateness = str(datetime.timedelta(minutes=total_lateness))
|
||||
total_early_exit = sum(list_cat.mapped('early_exit'))
|
||||
total_early_exit = str(datetime.timedelta(minutes=total_early_exit))
|
||||
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit}
|
||||
key_list.append(emp)
|
||||
|
||||
for item in data:
|
||||
grouped[item['employee_id_department_id_name']].append(item)
|
||||
key_list.append(item['employee_id_department_id_name'])
|
||||
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return '', mykey, total_dic, emp_data_dict
|
||||
return dict(grouped), mykey, '', dict(emp_data_dict)
|
||||
elif type == 'employee':
|
||||
grouped_attendance = collections.defaultdict(list)
|
||||
key_list = []
|
||||
total_dic = {}
|
||||
for rec in attendance_transaction_ids:
|
||||
grouped_attendance[rec.employee_id.name].append(rec)
|
||||
for emp_name, recs in grouped_attendance.items():
|
||||
total_lateness = sum(r.lateness for r in recs)
|
||||
total_early_exit = sum(r.early_exit for r in recs)
|
||||
total_dic[emp_name] = {
|
||||
'total_lateness': str(datetime.timedelta(minutes=total_lateness)),
|
||||
'total_early_exit': str(datetime.timedelta(minutes=total_early_exit)),
|
||||
}
|
||||
key_list.append(emp_name)
|
||||
|
||||
mykey = list(dict.fromkeys(key_list))
|
||||
return '', mykey, total_dic, dict(emp_data_dict)
|
||||
|
||||
|
||||
@api.model
|
||||
|
|
|
|||
|
|
@ -316,60 +316,7 @@ class SalaryRuleInput(models.Model):
|
|||
# if we don't give the contract, then the rules to apply should be for all current contracts of the employee
|
||||
contract_ids = payslip.contract_id.ids or \
|
||||
self.get_contract(payslip.employee_id, payslip.date_from, payslip.date_to)
|
||||
lines = [(0, 0, line) for line in self._get_payslip_lines(contract_ids, payslip.id)]
|
||||
|
||||
payslip.write({'line_ids': lines, 'number': number, 'level_id': payslip.contract_id.salary_level.id,
|
||||
'group_id': payslip.contract_id.salary_group.id,
|
||||
'degree_id': payslip.contract_id.salary_degree.id, })
|
||||
|
||||
for line in payslip.line_ids:
|
||||
if line.category_id.rule_type == 'allowance' or line.category_id.rule_type == 'deduction':
|
||||
flag = True
|
||||
|
||||
if flag:
|
||||
allowances = payslip.line_ids.filtered(
|
||||
lambda a: a.amount != 0 and a.rate != 0 and a.category_id.rule_type == 'allowance')
|
||||
payslip.allowance_ids = [(6, 0, allowances.ids)]
|
||||
deductions = payslip.line_ids.filtered(
|
||||
lambda a: a.amount != 0 and a.rate != 0 and a.category_id.rule_type == 'deduction')
|
||||
for d in deductions:
|
||||
if d.amount > 0:
|
||||
d.amount = -d.amount
|
||||
else:
|
||||
d.amount = d.amount
|
||||
payslip.deduction_ids = [(6, 0, deductions.ids)]
|
||||
|
||||
# Loans #
|
||||
loans = self.env['hr.loan.salary.advance'].search([('employee_id', '=', payslip.employee_id.id),
|
||||
('request_type.refund_from', '=', 'salary'),
|
||||
('state', '=', 'pay')]).filtered(
|
||||
lambda item: item.employee_id.state == 'open')
|
||||
if loans:
|
||||
for loan in loans:
|
||||
for l in loan.deduction_lines:
|
||||
if not l.paid and (
|
||||
str(l.installment_date) <= str(payslip.date_from) or str(l.installment_date) <= str(payslip.date_to)):
|
||||
employee_loan_id = payslip.loan_ids.filtered(
|
||||
lambda item: item.name == loan.request_type.name)
|
||||
if not employee_loan_id:
|
||||
payslip_loans.append({
|
||||
'name': loan.request_type.name,
|
||||
'code': loan.code,
|
||||
'amount': round((-l.installment_amount),2),
|
||||
'date': l.installment_date,
|
||||
'account_id': loan.request_type.account_id.id,
|
||||
'loan_id': loan.id
|
||||
})
|
||||
l.paid = True
|
||||
l.payment_date = payslip.date_to
|
||||
else:
|
||||
payslip.loan_ids = [(0, 0, loan_item) for loan_item in payslip_loans]
|
||||
|
||||
# check remaining loan and change state to closed
|
||||
if loan.remaining_loan_amount <= 0.0 < loan.gm_propos_amount:
|
||||
loan.state = 'closed'
|
||||
|
||||
payslip.loan_ids = [(0, 0, loan_item) for loan_item in payslip_loans]
|
||||
# lines = [(0, 0, line) for line in self._get_payslip_lines(contract_ids, payslip.id)]
|
||||
|
||||
# Holidays #
|
||||
holidays = self.env['hr.holidays'].search([('employee_id', '=', payslip.employee_id.id),
|
||||
|
|
@ -419,7 +366,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Unpaid Holidays For this month",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'unpaid',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -443,7 +390,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Unpaid Holidays For this month",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'unpaid',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -467,7 +414,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Unpaid Holidays For this month",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'unpaid',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id
|
||||
|
|
@ -489,7 +436,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Unpaid Holidays For this month",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'unpaid',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -506,7 +453,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Paid Holidays By percentage",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'percentage',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': holiday.holiday_status_id.percentage,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -516,7 +463,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Paid Holidays By percentage",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'percentage',
|
||||
'number_of_days': holiday.number_of_days_temp,
|
||||
'number_of_hours': holiday.holiday_status_id.percentage,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -529,7 +476,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Paid Holidays By percentage",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'percentage',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': holiday.holiday_status_id.percentage,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -544,7 +491,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Paid Holidays By percentage",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'percentage',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': holiday.holiday_status_id.percentage,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -566,7 +513,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Additional Paid Holidays",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'addition',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -590,7 +537,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Additional Paid Holidays",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'addition',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -614,7 +561,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Additional Paid Holidays",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'addition',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id
|
||||
|
|
@ -636,7 +583,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Additional Paid Holidays",
|
||||
'sequence': 1,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 2,
|
||||
'code': 'addition',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -741,7 +688,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Exclusion or Reconcile Paid Holidays",
|
||||
'sequence': 2,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 4,
|
||||
'code': 'exclusion',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -761,7 +708,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Exclusion or Reconcile Paid Holidays",
|
||||
'sequence': 2,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 4,
|
||||
'code': 'exclusion',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -781,7 +728,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Exclusion or Reconcile Paid Holidays",
|
||||
'sequence': 2,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 4,
|
||||
'code': 'exclusion',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -799,7 +746,7 @@ class SalaryRuleInput(models.Model):
|
|||
'name': "Exclusion or Reconcile Paid Holidays",
|
||||
'sequence': 2,
|
||||
'payslip_id': payslip.id,
|
||||
'code': 4,
|
||||
'code': 'exclusion',
|
||||
'number_of_days': number_of_days,
|
||||
'number_of_hours': 0.0,
|
||||
'contract_id': payslip.contract_id.id})]
|
||||
|
|
@ -887,6 +834,61 @@ class SalaryRuleInput(models.Model):
|
|||
raise exceptions.Warning(_("Salary is less than 0 this month for the following employees \n %s") % (
|
||||
pay.employee_id.name))
|
||||
|
||||
lines = [(0, 0, line) for line in self._get_payslip_lines(contract_ids, payslip.id)]
|
||||
payslip.write({'line_ids': lines, 'number': number, 'level_id': payslip.contract_id.salary_level.id,
|
||||
'group_id': payslip.contract_id.salary_group.id,
|
||||
'degree_id': payslip.contract_id.salary_degree.id, })
|
||||
|
||||
for line in payslip.line_ids:
|
||||
if line.category_id.rule_type == 'allowance' or line.category_id.rule_type == 'deduction':
|
||||
flag = True
|
||||
|
||||
if flag:
|
||||
allowances = payslip.line_ids.filtered(
|
||||
lambda a: a.amount != 0 and a.rate != 0 and a.category_id.rule_type == 'allowance')
|
||||
payslip.allowance_ids = [(6, 0, allowances.ids)]
|
||||
deductions = payslip.line_ids.filtered(
|
||||
lambda a: a.amount != 0 and a.rate != 0 and a.category_id.rule_type == 'deduction')
|
||||
for d in deductions:
|
||||
if d.amount > 0:
|
||||
d.amount = -d.amount
|
||||
else:
|
||||
d.amount = d.amount
|
||||
payslip.deduction_ids = [(6, 0, deductions.ids)]
|
||||
|
||||
# Loans #
|
||||
loans = self.env['hr.loan.salary.advance'].search([('employee_id', '=', payslip.employee_id.id),
|
||||
('request_type.refund_from', '=', 'salary'),
|
||||
('state', '=', 'pay')]).filtered(
|
||||
lambda item: item.employee_id.state == 'open')
|
||||
if loans:
|
||||
for loan in loans:
|
||||
for l in loan.deduction_lines:
|
||||
if not l.paid and (
|
||||
str(l.installment_date) <= str(payslip.date_from) or str(l.installment_date) <= str(
|
||||
payslip.date_to)):
|
||||
employee_loan_id = payslip.loan_ids.filtered(
|
||||
lambda item: item.name == loan.request_type.name)
|
||||
if not employee_loan_id:
|
||||
payslip_loans.append({
|
||||
'name': loan.request_type.name,
|
||||
'code': loan.code,
|
||||
'amount': round((-l.installment_amount), 2),
|
||||
'date': l.installment_date,
|
||||
'account_id': loan.request_type.account_id.id,
|
||||
'loan_id': loan.id
|
||||
})
|
||||
l.paid = True
|
||||
l.payment_date = payslip.date_to
|
||||
else:
|
||||
payslip.loan_ids = [(0, 0, loan_item) for loan_item in payslip_loans]
|
||||
|
||||
# check remaining loan and change state to closed
|
||||
if loan.remaining_loan_amount <= 0.0 < loan.gm_propos_amount:
|
||||
loan.state = 'closed'
|
||||
|
||||
payslip.loan_ids = [(0, 0, loan_item) for loan_item in payslip_loans]
|
||||
|
||||
self.write({'state': 'computed'})
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue