Merge pull request !1918 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-03-19 09:35:32 +00:00
committed by Gitee
11 changed files with 139 additions and 11 deletions
+1
View File
@@ -18,6 +18,7 @@
'views/yuthon_holiday_setting_views.xml',
'wizard/yuthon_fixes_wizard_views.xml',
'wizard/leave_allocation_wizard_views.xml',
'wizard/yuthon_leave_wizard_views.xml',
],
'assets': {
'web.assets_backend': [
@@ -11,6 +11,14 @@ from odoo.tools.misc import format_date
class HrLeave(models.Model):
_inherit = 'hr.leave'
def action_leave_wizard(self):
return {
"type": "ir.actions.act_window",
"name": "批量请假单",
"res_model": "yuthon.leave.wizard",
"view_mode": "form",
"target": "new",
}
@api.model
def default_get(self, fields_list):
@@ -5,3 +5,4 @@ access_yuthon_fixes_approval,yuthon_fixes_approval,model_yuthon_fixes_approval,b
access_yuthon_fixes_wizard,yuthon_fixes_wizard,model_yuthon_fixes_wizard,base.group_user,1,1,1,1
access_yuthon_holiday_setting,yuthon_holiday_setting,model_yuthon_holiday_setting,base.group_user,1,1,1,1
access_leave_allocation_wizard,leave_allocation_wizard,model_leave_allocation_wizard,base.group_user,1,1,1,1
access_yuthon_leave_wizard,yuthon_leave_wizard,model_yuthon_leave_wizard,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
5 access_yuthon_fixes_wizard yuthon_fixes_wizard model_yuthon_fixes_wizard base.group_user 1 1 1 1
6 access_yuthon_holiday_setting yuthon_holiday_setting model_yuthon_holiday_setting base.group_user 1 1 1 1
7 access_leave_allocation_wizard leave_allocation_wizard model_leave_allocation_wizard base.group_user 1 1 1 1
8 access_yuthon_leave_wizard yuthon_leave_wizard model_yuthon_leave_wizard base.group_user 1 1 1 1
@@ -97,4 +97,11 @@
</xpath>
</field>
</record>
<record id="all_data_write_hr_leave" model="ir.actions.server">
<field name="name">导入请假单</field>
<field name="model_id" ref="hr_holidays.model_hr_leave"/>
<field name="binding_model_id" ref="hr_holidays.model_hr_leave"/>
<field name="state">code</field>
<field name="code">action = model.action_leave_wizard()</field>
</record>
</odoo>
+2 -1
View File
@@ -1,2 +1,3 @@
from . import yuthon_fixes_wizard
from . import leave_allocation_wizard
from . import leave_allocation_wizard
from . import yuthon_leave_wizard
@@ -0,0 +1,71 @@
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
import re
import xlrd
import base64
import datetime
from datetime import datetime
import pandas as pd
class YuthonLeaveWizard(models.Model):
_name = 'yuthon.leave.wizard'
_description = '请假单导入'
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(string="文件名")
def confirm(self):
"""
导入excel文件,按行读取数据并处理
:return: 导入员工信息表并更新
"""
if not self.excel_file:
raise ValidationError('请上传文件。')
book = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel_file))
sh = book.sheet_by_index(0)
for rx in range(1,2):
row = sh.row(rx)
self.leave_import(row)
def leave_import(self, row):
employee_id = self.env['hr.employee'].search([('name', '=', row[2].value)], limit=1)
status_name = re.search(r'\((.*?)\)', row[0].value).group(1)
number_of_days_display = float(re.search(r'((\d+\.\d+)天)', row[5].value).group(1))
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', status_name)])
dt_from = datetime.strptime(row[3].value, '%Y-%m-%d %H:%M')
dt_to = datetime.strptime(row[4].value, '%Y-%m-%d %H:%M')
def get_key_from_datetime(dt):
hour = dt.hour
minute = dt.minute
if minute == 0:
key = str(hour)
elif minute == 30:
key = str(hour + 0.5)
else:
return None
return key
key_from = get_key_from_datetime(dt_from)
key_to = get_key_from_datetime(dt_to)
hr_leave_model = self.env['hr.leave']
selection_options = hr_leave_model._fields['request_hour_from'].selection
def get_display_value(key):
for option in selection_options:
if option[0] == key:
return option[1]
return None
request_hour_from = get_display_value(key_from)
request_hour_to = get_display_value(key_to)
leave = self.env['hr.leave'].create({
'employee_id': employee_id.id,
'holiday_status_id': holiday_status_id.id,
'request_date_from': dt_to,
'request_date_to': dt_from,
'request_hour_from': request_hour_from.split(':')[0],
'request_hour_to': request_hour_to.split(':')[0],
'request_unit_hours':True,
'number_of_days_display': number_of_days_display})
leave.action_approve()
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="leave_template_downloads_action" model="ir.actions.act_url">
<field name="name">模板下载</field>
<field name="target">self</field>
<field name="url">.</field>
</record>
<record id="leave_wizard_form" model="ir.ui.view">
<field name="name">初始化假期弹窗</field>
<field name="model">yuthon.leave.wizard</field>
<field name="arch" type="xml">
<form>
<sheet>
<header>
<button name="%(leave_template_downloads_action)d" string="模板下载" type="action"
class="btn btn-primary"/>
</header>
<group>
<group>
<field name="excel_file" filename="excel_name"/>
<field name="excel_name" invisible="1"/>
</group>
<group>
</group>
</group>
</sheet>
<footer>
<button name="confirm" string="确认" type="object" class="oe_highlight"/>
<button string="返回" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>
@@ -76,6 +76,7 @@ class YuthonHrEmployee(models.Model):
entry_date = fields.Date(string="入职时间")
confirmation_date = fields.Date(string="转正时间")
company_old = fields.Char(string="司龄", compute='_compute_company_old')
company_old_year = fields.Integer(string="司龄(年)", compute='_compute_company_old')
open_start_time = fields.Date(string="参加工作时间")
cumulative_work_month = fields.Integer(string="累计工作月数", compute='_compute_social_insurance_info', store=True)
@@ -113,6 +114,7 @@ class YuthonHrEmployee(models.Model):
holiday_hours = fields.Float(string="假期额度")
all_overtime_hours = fields.Float(string="总加班小时", compute="_compute_all_overtime_hours", store=True)
replacement_card_count = fields.Integer(string="补卡次数")
is_annual_salary = fields.Boolean(string="是否年薪")
# 假期
user_year_holiday_hours = fields.Float(string="已用年假")
remainder_year_holiday_hours = fields.Float(string="剩余年假")
@@ -287,18 +289,19 @@ class YuthonHrEmployee(models.Model):
"target": "new",
}
@api.depends('open_start_time')
@api.depends('entry_date')
def _compute_company_old(self):
"""司龄计算"""
for record in self:
if record.open_start_time:
if record.entry_date:
today = datetime.now().date()
years_diff = today.year - record.open_start_time.year
months_diff = today.month - record.open_start_time.month
if today.month < record.open_start_time.month:
years_diff = today.year - record.entry_date.year
months_diff = today.month - record.entry_date.month
if today.month < record.entry_date.month:
years_diff -= 1
months_diff += 12
record.company_old = str(years_diff) + '年' + str(months_diff) + '月'
record.company_old_year = years_diff
else:
record.company_old = None
@@ -115,6 +115,7 @@
<field name="entry_date"/>
<field name="confirmation_date"/>
<field name="company_old"/>
<field name="company_old_year"/>
<field name="open_start_time"/>
<field name="cumulative_work_month"/>
<field name="cumulative_work_years"/>
@@ -123,6 +124,7 @@
<field name="compute_char"/>
<field name="social_insurance_date"/>
<field name="social_insurance_time"/>
<field name="is_annual_salary"/>
</group>
<group string="其他">
<field name="archiving_agency"/>
@@ -25,7 +25,7 @@ class YuthonHrEmployeeWizard(models.Model):
sh = book.sheet_by_index(0)
for rx in range(2, sh.nrows):
row = sh.row(rx)
self.salary_group_import(row)
self.employee_user_data(row)
return {
'name': '批量更新员工',
'type': 'ir.actions.act_window',
@@ -43,7 +43,7 @@ class YuthonHrEmployeeWizard(models.Model):
number = row[0].value
employee_date = {
'number':number,
'open_start_time': date1,
'entry_date': date1,
'interrupt_work_month': interrupt_work_month,
}
if employee_name:
@@ -25,9 +25,9 @@
<field name="active">False</field>
</record>
<!-- 假期 -->
<record id="hr_holidays.menu_hr_holidays_root" model="ir.ui.menu">
<field name="active">False</field>
</record>
<!-- <record id="hr_holidays.menu_hr_holidays_root" model="ir.ui.menu">-->
<!-- <field name="active">False</field>-->
<!-- </record>-->
<!--工资 -->
<record id="hr_work_entry_contract_enterprise.menu_hr_payroll_root" model="ir.ui.menu">
<field name="active">False</field>