Merge pull request #1744 from expsa/bakry_hr

fix holiday balance and termination
This commit is contained in:
bakry 2024-11-13 13:42:59 +03:00 committed by GitHub
commit ed74df747d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 26 deletions

View File

@ -2,13 +2,13 @@
<odoo>
<data>
<template id="report_payroll_bank_pdf_docx">
<t t-foreach="data" t-as="v"><t>IFH,IFILE,CSV,,SASABBGSA003888815,<t><t t-esc="random_char"/></t><t t-set="date_value" t-value="pay_date"/><t t-esc="date_value.replace('-', '').replace('/', '').replace(':', '')"/>00,</t><t t-esc="datestamp" widget="datetime"></t>,<t><t t-esc="timestamp" widget="datetime"></t></t><t>,P,1.1,</t><t><t t-esc="number_of_records"/> </t>
<t t-foreach="data" t-as="v"><t>IFH,IFILE,CSV,ABCD5953001,SASABBGSA003888815,<t><t t-esc="random_char"/></t><t t-set="date_value" t-value="pay_date"/><t t-esc="date_value.replace('-', '').replace('/', '').replace(':', '')"/>00,</t><t t-esc="datestamp" widget="datetime"></t>,<t><t t-esc="timestamp" widget="datetime"></t></t><t>,P,1.0,</t><t><t t-esc="number_of_records"/> </t>
<t>BATHDR,ACH-CR,<t><t t-esc="counter"/></t>,,,,<t><t t-esc="salary_type"/></t>,Salary,,@1ST@,<t t-set="date_value" t-value="pay_date"/><t t-esc="date_value.replace('-', '').replace('/', '')"/>,00<t t-esc="company_pay_no"></t>,<t t-esc="currency"></t>,<t t-esc="round(total_amount_salary,2)"></t>,,,,,,,,<t t-esc="company_id"></t>,<t><t t-esc="company_hr_no"/></t>,<t><t t-esc="company_registry"/></t>,,,,<t><t t-esc="random_char2"/></t><t t-set="date_value" t-value="timestamp" widget="datetime"/><t t-esc="date_value.replace('-', '').replace('/', '').replace(':', '')"/>00</t><t t-if="bank_type=='rajhi'"><t t-foreach="v['docs']" t-as="o"><t></t>
<t>SECPTY,</t><t><t t-esc="o['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t> <t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t> </t></t>
<t>SECPTY,</t><t><t t-esc="o['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t><t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t> </t></t>
<t t-elif="bank_type=='alahli'"><t t-foreach="v['docs']" t-as="o"><t></t>
<t>SECPTY,</t><t><t t-esc="o['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t> <t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t></t></t>
<t>SECPTY,</t><t><t t-esc="o['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t><t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t></t></t>
<t t-elif="bank_type=='riyadh'"><t t-foreach="v['docs']" t-as="o"><t></t>
<t>SECPTY,</t><t><t t-esc="o+['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t> <t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t> </t></t></t>
<t>SECPTY,</t><t><t t-esc="o+['Account #']"/></t>,<t><t t-esc="o['Name']"/></t>,<t><t t-esc="o['ID']"/></t>,<t><t t-esc="o['Bank']"/></t>,,,<t><t t-esc="'%.2f'% o['Salary']"/></t>,,,,,,,N,N,,,,,,@SACH@,<t><t t-esc="o['National']"/></t>,<t><t t-esc="o['Basic']"/></t>,<t><t t-esc="o['Housing']"/></t><t>,<t t-esc="o['Other']"/></t>,<t><t t-esc="o['Deduction']"/></t>,<t>salary of <t t-esc="pay_slip"/></t> </t></t></t>
</template>
</data>
</odoo>

View File

@ -143,6 +143,8 @@ class HRHolidays(models.Model):
@api.depends('date_from','date_to', 'holiday_status_id')
def _leave_balance_date(self):
for rec in self:
to_work_days = 0
to_work_days2 = 0
leave = rec.holiday_status_id
current_date = (datetime.utcnow() + timedelta(hours=3)).date()
if rec.type == 'remove' and rec.employee_id.first_hiring_date and rec.date_from:
@ -155,11 +157,26 @@ class HRHolidays(models.Model):
for item in leave.duration_ids:
if item.date_from <= working_years < item.date_to:
holiday_duration = item.duration
to_work_days = fields.Datetime.from_string(rec.date_from) > \
###### get last cron date to compute leave_balance_date #
if leave:
balance_holiday = self.env['hr.holidays'].search([('employee_id', '=', rec.employee_id.id), ('type', '=', 'add'),
('holiday_status_id', '=', leave.id),('check_allocation_view', '=', 'balance')
], order='id desc', limit=1).holiday_ids
if balance_holiday:
last_cron_date = datetime.strptime(str(balance_holiday[-1].cron_run_date), DEFAULT_SERVER_DATE_FORMAT).date()
holi_date = (datetime.strptime(str(rec.date_from), "%Y-%m-%d %H:%M:%S")).date()
if last_cron_date < holi_date:
to_work_days2 = (holi_date - last_cron_date).days
#else:
#to_work_days2 = -(last_cron_date - holi_date).days
##### end ########
'''to_work_days = fields.Datetime.from_string(rec.date_from) > \
fields.Datetime.from_string(fields.Datetime.now()) and \
(datetime.strptime(str(rec.date_from), "%Y-%m-%d %H:%M:%S") -
(datetime.utcnow() + timedelta(hours=3))).days + 1 or 0
upcoming_leave = self.remaining_leaves_of_day_by_date(rec.employee_id, str(current_date), leave , is_month=False, is_years=False) * to_work_days
(datetime.utcnow() + timedelta(hours=3))).days + 1 or 0'''
upcoming_leave = self.remaining_leaves_of_day_by_date(rec.employee_id, str(current_date), leave , is_month=False, is_years=False) * to_work_days2
if upcoming_leave > 0 and leave.leave_type == 'annual':
rec.leave_balance_date = round(rec.leave_balance + upcoming_leave, 2)
exceed_days = leave.number_of_save_days + holiday_duration
@ -907,7 +924,6 @@ class HRHolidays(models.Model):
('check_allocation_view', '=', 'balance')
], limit=1, order="id desc")
if not already_exist:
# حسام مثيب ثواب الملوح السبيعي
balance_leaves = self.remaining_leaves_of_day_by_date(emp, str(first_hiring_date), item , is_month=False, is_years=False)
already_exist = self.env['hr.holidays'].create({
'name': 'Yearly Allocation of ' + item.name + ' Leaves',

View File

@ -36,9 +36,9 @@ class HrSalaryAdvance(models.Model):
gm_propos_amount = fields.Float(compute='_get_finance_gm_propos_amount', store=True,string='Approved Amount')
months = fields.Integer(default=1)
monthly_salary = fields.Float()
total_paid_inst = fields.Float(compute='get_total_paid_installment')
remaining_loan_amount = fields.Float(compute='get_remaining_loan_amount')
installment_amount = fields.Float(compute='get_installment_amount')
total_paid_inst = fields.Float(compute='get_total_paid_installment', store=True)
remaining_loan_amount = fields.Float(compute='get_remaining_loan_amount', store=True)
installment_amount = fields.Float(compute='get_installment_amount', store=True)
# previous_loan = fields.Boolean()
end_date = fields.Date(related='employee_id.contract_id.date_end')
@ -246,6 +246,7 @@ class HrSalaryAdvance(models.Model):
item.deduction_lines = self.env['loan.installment.line'].browse(items)
else:
raise exceptions.Warning(_('The employee does not have contract Start Date .'))
install_false = self.env['loan.installment.line'].search([('deduction_line', '=', False)]).unlink()
self._onchange_emp_expect_amount()
# @api.constrains('deduction_lines')

View File

@ -138,16 +138,15 @@ class HrLoanPaymentSuspension(models.Model):
@api.constrains('amount', 'installment_ids')
def _check_total_installments(self):
if self.type == 'suspension' or not (self.amount and self.installment_ids):
return True
if self.type == 'suspension' or not (self.amount and self.installment_ids): return True
inst_amount = self.installment_ids[0].deduction_line.installment_amount
inst_no = len(self.installment_ids)
if self.amount > round(sum(self.installment_ids.mapped('installment_amount')), 2):
if self.amount > round(sum(self.installment_ids.mapped('installment_amount')),2):
raise ValidationError(_('Sorry the amount you are paying exceeds the total of '
'the selected installments which is %s.'
'\n You can add more installments to pay or reduce the amount.')
% sum(self.installment_ids.mapped('installment_amount')))
elif ceil(self.amount / inst_amount) < inst_no:
% round(sum(self.installment_ids.mapped('installment_amount')),2))
elif ceil(self.amount / inst_amount) < inst_no and self.payment_type == 'flexible':
raise ValidationError(_('Sorry the amount you are paying can cover up to %s installments. \n'
'Please commit to this number or consider increasing the amount')
% ceil(self.amount / inst_amount))

View File

@ -1,7 +1,7 @@
id,name,model_id:id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_hr_loan_salary_advance_emp1,hr.loan.salary.advance.emp,model_hr_loan_salary_advance,base.group_user,1,1,1,1
access_loan_installment_line_emp2,loan.installment.line.emp,model_loan_installment_line,base.group_user,1,1,1,1
access_hr_account_moves_emp3,hr.account.moves.emp,model_hr_account_moves,base.group_user,1,1,1,0
access_hr_account_moves_emp3,hr.account.moves.emp,model_hr_account_moves,base.group_user,1,1,1,1
access_loan_request_type_emp4,loan.request.type.emp,model_loan_request_type,base.group_user,1,0,0,0
access_loan_request_type_manager5,loan.request.type.manager,model_loan_request_type,hr_loans_salary_advance.group_loan_manager,1,1,1,1
access_loan_payment_suspension_emp7,hr.loan.payment.suspension.emp,model_hr_loan_payment_suspension,base.group_user,1,1,1,1

1 id name model_id:id group_id/id perm_read perm_write perm_create perm_unlink
2 access_hr_loan_salary_advance_emp1 hr.loan.salary.advance.emp model_hr_loan_salary_advance base.group_user 1 1 1 1
3 access_loan_installment_line_emp2 loan.installment.line.emp model_loan_installment_line base.group_user 1 1 1 1
4 access_hr_account_moves_emp3 hr.account.moves.emp model_hr_account_moves base.group_user 1 1 1 0 1
5 access_loan_request_type_emp4 loan.request.type.emp model_loan_request_type base.group_user 1 0 0 0
6 access_loan_request_type_manager5 loan.request.type.manager model_loan_request_type hr_loans_salary_advance.group_loan_manager 1 1 1 1
7 access_loan_payment_suspension_emp7 hr.loan.payment.suspension.emp model_hr_loan_payment_suspension base.group_user 1 1 1 1

View File

@ -163,10 +163,10 @@ class HrTermination(models.Model):
if leave.holiday_ids and rec.last_work_date and leave.holiday_status_id.duration_ids:
cron_run_date = datetime.strptime(str(leave.holiday_ids[-1].cron_run_date), "%Y-%m-%d").date()
date_to_check = (datetime.utcnow() + timedelta(hours=3)).date()
last_working_date = datetime.strptime(str(rec.last_work_date), "%Y-%m-%d").date()
if cron_run_date < date_to_check:
date_to_check = cron_run_date
to_work_days = (datetime.strptime(str(rec.last_work_date), "%Y-%m-%d").date() -
date_to_check).days
to_work_days = (last_working_date - date_to_check).days
first_hiring_date = datetime.strptime(str(leave.hiring_date), "%Y-%m-%d").date()
last_work_date = datetime.strptime(str(rec.last_work_date), "%Y-%m-%d").date()
@ -175,15 +175,23 @@ class HrTermination(models.Model):
for item in leave.holiday_status_id.duration_ids:
if item.date_from <= working_years < item.date_to:
holiday_duration = item.duration
upcoming_leave = ((holiday_duration / 12) / 30.39) * to_work_days
leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave, 2)
###get last cron date to compute leave_balance_date
to_work_days2 = 0
if cron_run_date < last_working_date:
to_work_days2 = (last_working_date - cron_run_date).days
else:
to_work_days2 = -(cron_run_date - last_working_date).days
upcoming_leave2 = leave.remaining_leaves_of_day_by_date(rec.employee_id, str(date_to_check),\
leave.holiday_status_id , is_month=False, is_years=False) * to_work_days2
####################### END
#upcoming_leave = ((holiday_duration / 12) / 30.39) * to_work_days
leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave2, 2)
exceed_days = leave.holiday_status_id.number_of_save_days + holiday_duration
if leave_balance > exceed_days:
rec.leave_balance = exceed_days
else:
rec.leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave, 2)
rec.leave_balance = round(rec.employee_id.remaining_leaves + upcoming_leave2, 2)
self._compute_holiday_amount()
def current_date_hijri(self):
@ -424,7 +432,7 @@ class HrTermination(models.Model):
if self.contract_id:
if self.contract_id.advantages:
for item in self.contract_id.advantages:
if item.date_from and item.amount > 0:
if item.date_from and item.amount > 0 and self.last_work_date:
td = datetime.now().strftime('%Y-%m-%d')
today = datetime.strptime(str(td), "%Y-%m-%d").date()
start = datetime.strptime(str(item.date_from), "%Y-%m-%d").date()

View File

@ -11,8 +11,7 @@
<record id="hr_termination_manager_rule" model="ir.rule">
<field name="name">Manager: views terminations of its subordinates</field>
<field name="model_id" ref="model_hr_termination"/>
<field name="domain_force">['|','|',('department_id.manager_id','=',False),
('department_id.manager_id.user_id','child_of', [user.id]),
<field name="domain_force">['|',('department_id.manager_id.user_id','child_of', [user.id]),
('department_id.parent_id.manager_id.user_id','child_of', [user.id])]
</field>
<field name="groups"