99 lines
4.9 KiB
Python
99 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from email.policy import default
|
|
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class YuthonFixesApproval(models.Model):
|
|
_name = 'yuthon.fixes.approval'
|
|
_description = '假期修正审批'
|
|
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
|
|
|
|
name = fields.Char(string="标题")
|
|
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_holiday_fixes_code'))
|
|
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
|
original_days = fields.Float(string="原休假时长(天)")
|
|
original_hours = fields.Float(string="原休假时长(小时)", tracking=True)
|
|
now_type = fields.Selection([('days', '按天'), ('hours', '按小时')], string="修正类型", default="hours")
|
|
now_days = fields.Float(string="现休假时长(天)")
|
|
now_hours = fields.Float(string="现休假时长(小时)", tracking=True)
|
|
increase = fields.Float(string="增加时长(小时)")
|
|
decrease = fields.Float(string="减少时长(小时)")
|
|
holiday_status = fields.Selection([('annual', '年假'), ('overtime', '加班时')], string="休假类型", default="annual")
|
|
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
|
|
is_issues = fields.Boolean(string='是否上会')
|
|
issues_result = fields.Html(string="会议结果")
|
|
correction_quota_hour = fields.Float(string="修正假期时长(小时)", tracking=True)
|
|
correction_quota_day = fields.Float(string="修正假期时长(天)")
|
|
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
|
reason_application = fields.Text(string="申请事由")
|
|
documents_ids = fields.Many2many('ir.attachment', string="附件")
|
|
vacation_id = fields.Many2one('yuthon.vacation.reports')
|
|
active = fields.Boolean('Active', default=True, tracking=True)
|
|
remarks = fields.Text(string="备注")
|
|
work_end = fields.Boolean(string="结束")
|
|
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
|
|
default='normal')
|
|
|
|
def _get_default_name_title(self):
|
|
return self._description if self._description else self._name
|
|
|
|
name_title = fields.Char(default=_get_default_name_title)
|
|
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
|
|
|
|
@api.onchange('holiday_status')
|
|
def _onchange_holiday_status(self):
|
|
if self.holiday_status and self.vacation_id:
|
|
if self.holiday_status == 'annual':
|
|
self.original_hours = self.vacation_id.leave
|
|
else:
|
|
self.original_hours = self.vacation_id.working_overtime
|
|
|
|
|
|
def bottom_allocation(self):
|
|
pass
|
|
# for record in self:
|
|
# if record.now_type == 'days':
|
|
# type_request_unit = 'day'
|
|
# number_of_days = record.now_days
|
|
# elif record.now_type == 'hours':
|
|
# type_request_unit = 'hour'
|
|
# number_of_days = record.now_days/8
|
|
# else:
|
|
# type_request_unit = 'day'
|
|
# number_of_days = record.now_days
|
|
#
|
|
# record.leave_id.write({
|
|
# 'remarks':record.remarks,
|
|
# 'number_of_days': number_of_days,
|
|
# 'type_request_unit':type_request_unit,})
|
|
|
|
@api.onchange('correction_quota_hour')
|
|
def _onchange_correction_quota_hour(self):
|
|
if self.correction_quota_hour:
|
|
self.now_hours = self.correction_quota_hour + self.original_hours
|
|
|
|
@api.onchange('correction_quota_day')
|
|
def _onchange_correction_quota_day(self):
|
|
if self.correction_quota_day:
|
|
self.now_days = self.correction_quota_day + self.original_days
|
|
|
|
# @api.depends('holiday_status_id')
|
|
# def _compute_original_days(self):
|
|
# today = fields.Date.today()
|
|
# for record in self:
|
|
# allocation_ids = self.env['hr.leave.allocation'].search([('employee_id', '=', record.users_id.employee.id),
|
|
# ('holiday_status_id', '=', record.holiday_status_id.id),
|
|
# ('date_from', '<=', today),
|
|
# ('state', '=', 'validate')])
|
|
# for allocation in allocation_ids:
|
|
# record.original_days += allocation.number_of_days
|
|
|
|
@api.onchange('users_id', 'now_type')
|
|
def _onchange_name(self):
|
|
if self.users_id and self.now_type == 'hours':
|
|
if self.users_id and self.original_hours and self.now_hours and self.holiday_status_id:
|
|
self.name = self.users_id.name + f'原{self.holiday_status_id.name}'+ str(self.original_hours) + '小时' + '改为' + str(self.now_hours) + '小时'
|
|
|
|
|