training payment module notes

This commit is contained in:
Esraa-Exp 2025-02-09 14:17:13 +02:00
parent 74a735d3f4
commit e032777d30
3 changed files with 33 additions and 105 deletions

View File

@ -48,3 +48,9 @@ msgstr ""
#: model:ir.model,name:hr_training_payment.model_hr_official_mission_type
msgid "hr.official.mission.type"
msgstr ""
#. module: hr_training_payment
#: code:addons/hr_training_payment/models/hr_official_mission.py:0
#, python-format
msgid "You must Enter Purchase Product in Training Type Configuration"
msgstr "يجب ادخال منتج طلب الشراء في إعداد نوع المهام"

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, exceptions
from odoo import models, fields, api, exceptions,_
from datetime import datetime, date, timedelta
from odoo.exceptions import ValidationError
import calendar
@ -14,8 +15,13 @@ class HrOfficialMission(models.Model):
def approve(self):
# check if there is dealing with financial
self.employee_ids.chick_not_overtime()
if self.mission_type.work_state == 'training':
self.employee_ids.chick_not_overtime()
if not self.mission_type.pr_product_id.id:
raise ValidationError(_("You must Enter Purchase Product in Training Type Configuration"))
product_line = {
'product_id': self.mission_type.pr_product_id.id,
'qty': 1,
@ -34,108 +40,24 @@ 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})
self.call_cron_function()
else:
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
}
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)]
})
# 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)
# 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.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.employee_id.contract_id.id,
'out_rule': True,
'state': 'confirm',
'comments': self.mission_purpose})
line.advantage_id = advantage_arc.id
print(advantage_arc,"the type is payroll advantage created>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
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:
invoice_line_vals = {
'name': 'Training Cost for Course Name %s Training Center %s' % (
item.course_name.name, item.partner_id.name),
'price_unit': item.Training_cost,
# 'account_id': self.mission_type.journal_id.default_credit_account_id.id,
'account_id': item.partner_id.property_account_payable_id.id,
# 'partner_id': item.employee_id.user_id.partner_id.id
}
invoice = self.env['account.move'].create({
'state': 'draft',
'move_type': 'in_invoice',
'journal_id': item.mission_type.journal_id.id,
'partner_id': item.partner_id.id,
'invoice_date': date.today(),
'ref': 'Training Cost for Course Name %s ' % item.course_name.name,
'invoice_line_ids': [(0, 0, invoice_line_vals)]
})
item.write({'Tra_cost_invo_id': invoice.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})
self.call_cron_function()
res = super(HrOfficialMission, self).approve()
return res
def draft_state(self):
res = super(HrOfficialMission, self).draft_state()
if self.purchase_request_id:
self.purchase_request_id.sudo().unlink()
return res

View File

@ -9,7 +9,7 @@
<field name="inherit_id" ref="exp_official_mission.employee_official_mission_type_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='work_state']" position="after">
<field name="pr_product_id" attrs="{'invisible':[('work_state','!=','training')]}"/>
<field name="pr_product_id" attrs="{'invisible':[('work_state','!=','training')],'required':[('work_state','=','training')]}"/>
</xpath>
</field>
</record>