添加功能

This commit is contained in:
zhou
2025-05-17 15:41:12 +08:00
parent d641fc8753
commit 2827adcec7
6 changed files with 36 additions and 35 deletions
@@ -124,11 +124,10 @@ class SoongWorkflowCommentWizard(models.TransientModel):
self.ensure_one()
cx = self.env.context.copy() or {}
record_id = self.env[self.res_model].search([('id', '=', self.res_id)])
menu_id = self.env['ir.ui.menu'].search([('name', '=', record_id._description)])
for employee in self.employee_ids:
action_id = self.env['ir.actions.act_window'].search([('res_model', '=', self.res_model)])[0]
# url = f'https://oa.thtzjt.com/web?oauth_access_token={employee.user_id.oauth_access_token}&oauth_uid={employee.wecom_userid}#id={record_id.id}&cids=2&action={menu_id.action.id}&model={record_id._name}&view_type=form'
url = f'https://oa.thtzjt.com/web#id={record_id.id}&cids=2&action={menu_id.action.id}&model={record_id._name}&view_type=form&menu_id={menu_id.id}'# &menu_id={menu_id.id}
url = f'https://oa.thtzjt.com/web#id={record_id.id}&cids=2&action={action_id.id}&model={record_id._name}&view_type=form'# &menu_id={menu_id.id}
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='oa',
user_id=employee.wecom_userid,
title=record_id._description,
+15 -24
View File
@@ -316,6 +316,7 @@ class HolidaysRequestBatch(models.Model):
name = fields.Char(string='标题')
create_date = fields.Date(string='创建日期', default=fields.Datetime.today())
employee_id = fields.Many2one(related='users_id.employee_id', string="员工", store=True)
company_id = fields.Many2one(related='users_id.employee_id.company_id', string="公司", store=True)
users_id = fields.Many2one('res.users', string="请假人", default=lambda self: self.env.user.id)
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
user_role_id = fields.Many2one(related='users_id.employee_id.user_role_id', string="角色")
@@ -365,29 +366,10 @@ class HolidaysRequestBatch(models.Model):
self.leave_ids.action_validate()
self.hour_leave_ids.action_validate()
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
number_hours = 0
company_id = vals.get('company_id')
if company_id:
company = self.env['res.company'].browse(company_id)
company.name = '天河物管'
if company.name == '天河物管':
if 'hour_leave_ids' in vals:
for leave_info in vals.get('hour_leave_ids', []):
hours_text = leave_info[2]['number_of_hours_text']
match = re.search(r'\d+', hours_text)
if match:
number_hours += float(match.group())
valid_hours = [2, 4, 6, 8]
if number_hours not in valid_hours:
raise ValidationError("休假时长必须为 2、4、6 或 8 小时才可以保存!")
return super(HolidaysRequestBatch, self).create(vals_list)
@api.constrains('hour_leave_ids')
def _check_hour_leave_hours(self):
"""检查小时请假记录的小时数是否为0"""
number_hours = 0
for record in self:
if record.hour_leave_ids and not record.leave_ids:
for line in record.hour_leave_ids:
@@ -396,6 +378,12 @@ class HolidaysRequestBatch(models.Model):
match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '')
if match and float(match.group(1)) == 0:
raise ValidationError(_("请假小时数不能为0!"))
if record.company_id.name == '天河物管':
match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '')
number_hours += float(match.group(1))
valid_hours = [2, 4, 6, 8]
if number_hours not in valid_hours:
raise ValidationError("休假时长必须为 2、4、6 或 8 小时才可以保存!")
@api.onchange('leave_ids', 'hour_leave_ids', 'employee_id')
def _onchange_leave_dates(self):
@@ -422,11 +410,14 @@ class HolidaysRequestBatch(models.Model):
if self.hour_leave_ids and not self.leave_ids:
# 只按小时请假的情况
first_hour_leave = self.hour_leave_ids[0]
date_str = first_hour_leave.request_date_from.strftime('%Y%-m%-%d')
start_time = first_hour_leave.request_hour_from
end_time = first_hour_leave.request_hour_to
date_str = first_hour_leave.request_date_from.strftime('%Y-%m-%d')
time_options = dict(self._fields['request_hour_from_real'].selection)
start_time_key = first_hour_leave.request_hour_from
end_time_key = first_hour_leave.request_hour_to
start_time_formatted = time_options.get(start_time_key, start_time_key)
end_time_formatted = time_options.get(end_time_key, end_time_key)
hours = first_hour_leave.number_of_hours_text if first_hour_leave.number_of_hours_text else 0
title = f"{self.employee_id.name}的请假 {date_str},{start_time}~{end_time}"
title = f"{self.employee_id.name}的请假 {date_str},{start_time_formatted}~{end_time_formatted}"
if hours:
title += f",{hours}"
self.name = title
@@ -14,9 +14,9 @@
<attribute name="limit">20</attribute>
<attribute name="advanced_filter">True</attribute>
</xpath>
<!-- <header>-->
<!-- <button name="all_put_department_change" type="object" string="部门变更" class="oe_highlight"/>-->
<!-- </header>-->
<xpath expr="//tree" position="inside">
<button class="oe_stat_button" name="all_put_department_change" string="部门变更" type="object"/>
</xpath>
<xpath expr="//field[@name='total_employee']" position="attributes">
<attribute name="column_invisible">1</attribute>
</xpath>
@@ -59,4 +59,11 @@
<field name="state">code</field>
<field name="code">records.do_department_to_res_groups()</field>
</record>
<record id="yuthon_department_change_groups" model="ir.actions.server">
<field name="name">批量提交部门变更</field>
<field name="model_id" ref="hr.model_hr_department"/>
<field name="binding_model_id" ref="hr.model_hr_department"/>
<field name="state">code</field>
<field name="code">records.all_put_department_change()</field>
</record>
</odoo>
@@ -47,12 +47,14 @@ class YuthonDepartmentChange(models.Model):
for record in self:
for approval in record.approval_ids:
approval.department_id.write({'name': approval.new_name})
approval.is_department = True
class DepartmentChangeApprovalLine(models.Model):
_name = 'department.change.approval.line'
_description = '部门变更审批明细'
department_change_id = fields.Many2one('yuthon.department.change', string='关联部门变更')
department_id = fields.Many2one('hr.department', string='部门')
is_department = fields.Boolean(string="字段隐藏")
department_id = fields.Many2one('hr.department', string='原部门名称')
name = fields.Char(related='department_id.name', string='原部门名称')
new_name = fields.Char(string='新部门名称')
@@ -58,9 +58,10 @@
<page string="部门变更明细">
<field name="approval_ids">
<tree editable="bottom">
<field name="is_department"/>
<field name="department_change_id" column_invisible="1"/>
<field name="department_id" column_invisible="1"/>
<field name="name"/>
<field name="department_id" column_invisible="is_department"/>
<field name="name" column_invisible="not is_department"/>
<field name="new_name" required="1"/>
</tree>
</field>
+4 -3
View File
@@ -33,6 +33,7 @@
<xpath expr="//sheet" position="before">
<header>
<button class="oe_stat_button" name="send_wecom_employee" string="同步企业微信部门" groups="hr.group_hr_manager" type="object" icon="fa-bars"/>
</header>
</xpath>
<xpath expr="//field[@name='color']" position="after">
@@ -48,9 +49,9 @@
<field name="inherit_id" ref="hr.view_department_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="inside">
<header>
<button class="oe_stat_button" name="send_wecom_employee" string="同步企业微信部门" groups="hr.group_hr_manager" type="object" icon="fa-bars"/>
</header>
<!-- <header>-->
<!-- <button class="oe_stat_button" name="send_wecom_employee" string="同步企业微信部门" groups="hr.group_hr_manager" type="object" icon="fa-bars"/>-->
<!-- </header>-->
</xpath>
</field>
</record>