添加功能

This commit is contained in:
zhouzhou
2024-11-25 18:05:14 +08:00
parent 642a582199
commit bb43481ee1
13 changed files with 168 additions and 18 deletions
+1
View File
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard
+2
View File
@@ -15,6 +15,8 @@
'security/ir.model.access.csv',
'security/yuthon_salary_company.xml',
'views/inherit_hr_payroll_structure_views.xml',
'views/inherit_hr_salary_rule_views.xml',
'wizard/yuthon_salary_wizard_views.xml',
],
'installable': True,
'application': True,
@@ -33,4 +33,4 @@ class HrPayrollStructure(models.Model):
return (False, 0)
return (False, 0) # 首位非0的放前面
res.sort(key=sort_by_sequence_number)
return res
return res
+13 -1
View File
@@ -3,5 +3,17 @@ import re
class InheritHrSalaryRule(models.Model):
_inherit = 'hr.salary.rule'
_order = 'sequence asc'
category_id = fields.Many2one('hr.salary.rule.category', required=False)
category_id = fields.Many2one('hr.salary.rule.category', required=False, string='类别')
yuthon_company = fields.Selection([('thtz', '天河投资集团'), ('thwg', '天河物管'), ('thlc', '天河粮储')],
string='所属公司')
def action_yuthon_salary_wizard(self):
return {
"type": "ir.actions.act_window",
"name": "批量更新工资项",
"res_model": "yuthon.salary.wizard",
"view_mode": "form",
"target": "new",
}
+2 -1
View File
@@ -1 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_yuthon_salary_wizard,access_yuthon_salary_wizard,model_yuthon_salary_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
2 access_yuthon_salary_wizard access_yuthon_salary_wizard model_yuthon_salary_wizard base.group_user 1 1 1 1
Binary file not shown.
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="hr_salary_rule_inherit" model="ir.ui.view">
<field name="name">hr.salary.rule.inherit</field>
<field name="model">hr.salary.rule</field>
<field name="inherit_id" ref="hr_payroll.hr_salary_rule_list"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="sequence" string="序号"/>
</xpath>
<xpath expr="//field[@name='category_id']" position="attributes">
<attribute name="column_invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="column_invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='code']" position="after">
<field name="yuthon_company"/>
</xpath>
</field>
</record>
<record id="hr_salary_rule_inherit_form" model="ir.ui.view">
<field name="name">hr.salary.rule.inherit.form</field>
<field name="model">hr.salary.rule</field>
<field name="inherit_id" ref="hr_payroll.hr_salary_rule_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='code']" position="before">
<field name="yuthon_company"/>
<field name="sequence"/>
</xpath>
</field>
</record>
<record id="all_data_write_salary" model="ir.actions.server">
<field name="name">批量导入职级</field>
<field name="model_id" ref="hr_payroll.model_hr_salary_rule"/>
<field name="binding_model_id" ref="hr_payroll.model_hr_salary_rule"/>
<field name="state">code</field>
<field name="code">action = model.action_yuthon_salary_wizard()</field>
</record>
</odoo>
+1
View File
@@ -0,0 +1 @@
from . import yuthon_salary_wizard
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
from pypinyin import pinyin, Style
import xlrd
import base64
import datetime
from datetime import datetime
class YuthonSalaryWizard(models.Model):
_name = 'yuthon.salary.wizard'
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(string="文件名")
def confirm(self):
"""
导入excel文件,按行读取数据并处理
"""
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, sh.nrows):
row = sh.row(rx)
self.salary_user_data(row)
return {
'name': '批量更新工资项',
'type': 'ir.actions.act_window',
'view_mode': 'tree',
'res_model': 'hr.salary.rule',
}
def salary_user_data(self,row):
name_pinyin = pinyin(row[1].value, style=Style.FIRST_LETTER)
abbreviation = "".join([p[0][0] for p in name_pinyin]).upper()
salary_name = self.env['hr.salary.rule'].search([('name', '=', row[1].value)])
text = row[2].value
struct_id = self.env['hr.payroll.structure'].search([('name', '=', text)])
yuthon_company_dict = {'天河投资集团': 'thtz', '天河物管': 'thwg', '天河粮储': 'thlc', '': ''}
yuthon_company_dict2 = {'天河投资集团': 'TT', '天河物管': 'TW', '天河粮储': 'TL', '': ''}
yuthon_company = yuthon_company_dict.get(row[3].value)
yuthon_company2 = yuthon_company_dict2.get(row[3].value)
salary_date = {
'sequence': row[0].value,
'code':yuthon_company2+abbreviation,
'name': row[1].value, # 姓名
'struct_id': struct_id.id, # 部门
'yuthon_company': yuthon_company,
'amount_fix' : row[4].value, # 固定金额
}
salary_name.create(salary_date)
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="salary_template_downloads_tian_he_action" model="ir.actions.act_url">
<field name="name">工资项模板 下载</field>
<field name="target">self</field>
<field name="url">/yuthon_salary/static/others/salary_template.xlsx</field>
</record>
<record id="yuthon_salary_wizard_form" model="ir.ui.view">
<field name="name">审批意见弹窗</field>
<field name="model">yuthon.salary.wizard</field>
<field name="arch" type="xml">
<form>
<sheet>
<header>
<button name="%(salary_template_downloads_tian_he_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>
@@ -8,7 +8,7 @@
<field name="code">model.will_task_time()</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">2</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="numbercall">-1</field>
+2 -1
View File
@@ -18,4 +18,5 @@ class YuthonTaskTime(models.Model):
'day': '天',
}
for n in self:
n.name = str(n.number) + task_unit_dict[n.task_unit]
if n.number and n.task_unit:
n.name = str(n.number) + task_unit_dict[n.task_unit]
+18 -13
View File
@@ -21,20 +21,25 @@ class YuthonWillTask(models.Model):
start_time = fields.Datetime(string='开始时间', default=fields.Date.today())
end_time = fields.Datetime(string='结束时间', default=lambda self: datetime.combine(datetime.now().date(), time(11, 0, 0)))
remind_mapping = {
'fifteen': timedelta(minutes=15),
'thirty': timedelta(minutes=30),
'one_hour': timedelta(hours=1),
'two_hour': timedelta(hours=2),
'one_day': timedelta(days=1),
}
def will_task_time(self):
for task in self.env['yuthon.will.task'].search([]):
time_difference = task.end_time - datetime.now()
for remind, duration in self.remind_mapping.items():
if task.remind == remind and time_difference <= duration:
task.add_comment()
tasks = self.env['yuthon.will.task'].search([])
for task in tasks:
for task_time in task.task_time_ids:
time_difference = task.end_time - datetime.now()
duration = self._compute_duration(task_time)
if time_difference <= duration:
task.add_comment() # 将task_time对象传递给add_comment方法
break # 触发一个提醒后就跳出内循环
def _compute_duration(self, task_time):
if task_time.task_unit == 'min':
return timedelta(minutes=task_time.number)
elif task_time.task_unit == 'hour':
return timedelta(hours=task_time.number)
elif task_time.task_unit == 'day':
return timedelta(days=task_time.number)
else:
return timedelta.max
def add_comment(self):
self.ensure_one()