training payment fix

This commit is contained in:
Esraa-Exp 2025-03-02 15:44:18 +02:00
parent ef558e5300
commit 661cabdfe0
1 changed files with 84 additions and 15 deletions

View File

@ -11,15 +11,86 @@ class HrOfficialMission(models.Model):
purchase_request_id = fields.Many2one(comodel_name='purchase.request', string="Purchase Request")
def approve(self):
# check if there is dealing with financial
if self.mission_type.work_state == 'training':
self.employee_ids.chick_not_overtime()
if self.employee_ids and self.mission_type.related_with_financial:
# move amounts to journal entries
if self.move_type == 'accounting':
if self.mission_type.account_id and self.mission_type.journal_id:
for item in self.employee_ids:
if item.amount > 0.0:
debit_line_vals = {
'name': item.employee_id.name + ' in official mission "%s" ' % self.mission_type.name,
'debit': item.amount,
'account_id': self.mission_type.account_id.id,
'partner_id': item.employee_id.user_id.partner_id.id
}
credit_line_vals = {
'name': item.employee_id.name + ' in official mission "%s" ' % self.mission_type.name,
'credit': item.amount,
'account_id': self.mission_type.journal_id.default_account_id.id,
'partner_id': item.employee_id.user_id.partner_id.id
}
if not item.account_move_id:
move = self.env['account.move'].create({
'state': 'draft',
'journal_id': self.mission_type.journal_id.id,
'date': date.today(),
'ref': 'Official mission for employee "%s" ' % item.employee_id.name,
'line_ids': [(0, 0, debit_line_vals), (0, 0, credit_line_vals)],
'res_model': 'hr.official.mission',
'res_id': self.id
})
# fill account move for each employee
item.write({'account_move_id': move.id})
else:
raise exceptions.Warning(
_('You do not have account or journal in mission type "%s" ') % self.mission_type.name)
if self.Training_cost > 0.0:
# move amounts to advantages of employee in contract
elif self.move_type == 'payroll':
# get start and end date of the current month
current_date = date.today()
month_start = date(current_date.year, current_date.month, 1)
month_end = date(current_date.year, current_date.month, calendar.mdays[current_date.month])
for line in self.employee_ids:
if line.sudo().employee_id.contract_id:
advantage_arc = line.env['contract.advantage'].create({
'benefits_discounts': self.official_mission.id,
'date_from': month_start,
'date_to': month_end,
'amount': line.amount,
'official_mission_id': True,
'employee_id': line.employee_id.id,
'contract_advantage_id': line.sudo().employee_id.contract_id.id,
'out_rule': True,
'state': 'confirm',
'comments': self.mission_purpose})
line.advantage_id = advantage_arc.id
else:
raise exceptions.Warning(_(
'Employee "%s" has no contract Please create contract to add line to advantages')
% line.employee_id.name)
for item in self:
# create ticket request from all employee
if item.issuing_ticket == 'yes':
for emp in item.employee_ids:
ticket = self.env['hr.ticket.request'].create({
'employee_id': emp.employee_id.id,
'mission_request_id': item.id,
'mission_check': True,
'request_for': item.ticket_cash_request_for,
'request_type': item.ticket_cash_request_type.id,
'cost_of_tickets': item.get_ticket_cost(emp.employee_id),
'destination': item.destination.id,
})
item.write({'ticket_request_id': ticket.id})
# move invoice training cost our trining center
if item.Training_cost > 0:
if not self.mission_type.pr_product_id.id:
raise ValidationError(_("You must Enter Purchase Product in Training Type Configuration"))
@ -41,17 +112,15 @@ class HrOfficialMission(models.Model):
})
self.purchase_request_id = purchase_request.id
self.state = "approve"
if self.mission_type.work_state and self.mission_type.duration_type == 'days':
for emp in self.employee_ids:
if emp.date_to >= fields.Date.today() >= emp.date_from:
emp.employee_id.write(
{'work_state': self.mission_type.work_state, 'active_mission_id': emp.id})
emp.employee_id.write({'work_state': self.mission_type.work_state, 'active_mission_id': emp.id})
self.call_cron_function()
else:
res = super(HrOfficialMission, self).approve()
return res