审批二开

This commit is contained in:
pengyuthon
2024-05-27 18:35:32 +08:00
parent 108c189c05
commit ca79e6c698
14 changed files with 87 additions and 196 deletions
+1 -1
View File
@@ -177,7 +177,7 @@
<field name="can_edit" column_invisible="True"/>
<field name="can_edit_user_id" column_invisible="True"/>
<field name="user_id" string="Approver" readonly="not can_edit_user_id or status != 'new'" force_save="1" />
<field name="required" readonly="not can_edit" force_save="1"/>
<!-- <field name="required" readonly="not can_edit" force_save="1"/>-->
<field name="status"/>
<field name="company_id" column_invisible="True"/>
</tree>
+1 -1
View File
@@ -17,7 +17,7 @@
'views/inherit_approval_category_views.xml',
'views/inherit_approval_request_views.xml',
'views/approval_process_views.xml',
'views/demo_request_view.xml',
'views/demo_approval_request.xml',
'wizard/approval_notice_wizard_views.xml',
],
'installable': True,
+1 -1
View File
@@ -1,4 +1,4 @@
from . import demo_request
from . import demo_approval_request
from . import inherit_approval_category
from . import inherit_approval_approver
from . import inherit_approval_process
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError
class DemoApprovalRequest(models.Model):
_inherit = "approval.request"
_description = '默认审批 demo.approval.request'
demo1 = fields.Char(string="demo1")
demo2 = fields.Char(string="demo2")
demo3 = fields.Char(string="demo3")
-8
View File
@@ -1,8 +0,0 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError
class ApprovalCategory(models.Model):
_name = 'demo.request'
_inherit = ["approval.request"]
@@ -8,37 +8,25 @@ class ApprovalProcess(models.Model):
_name = 'approval.process'
_rec_name = 'approval_category_id'
approvals_other_user_ids = fields.Many2many('res.users', string="传阅人")
approval_category_id = fields.Many2one('approval.category', string="流程名称")
approvals_other_user_ids = fields.Many2many('res.users', string="传阅人", compute="_compute_other_user", store=True)
user_ids = fields.One2many('approval.users', 'approval_process_id', string="审批流程")
other_user_ids = fields.One2many('approval.other.users', 'approval_process_id', string="传阅人流程")
def _create_users(self):
self.ensure_one()
user_ids = []
users_user_ids = self.user_ids
if users_user_ids:
for user in users_user_ids:
if user.approval_department_id:
department = self.sudo().env["hr.department"].browse(user.approval_department_id.id)
employees = self.sudo().env["hr.employee"].search([("department_id", "=", department.id)])
for employee in employees:
user_ids.append(employee.user_id.id)
if user.approval_job_lv_id:
job_lv = self.sudo().env["yuthon.job.lv"].browse(user.approval_job_lv_id.id)
employees = self.sudo().env["hr.employee"].search([("job_lv_id", "=", job_lv.id)])
for employee in employees:
user_ids.append(employee.user_id.id)
if user.user_ids:
user_ids += user.user_ids.ids
return user_ids
@api.model_create_multi
def create(self, vals_list):
res = super(ApprovalProcess, self).create(vals_list)
for vals in vals_list:
approval_category_id = self.env['approval.category'].search([('id', '=', vals['approval_category_id'])])
approval_category_id.write({'approval_process_id': res.id})
return res
@api.onchange('other_user_ids')
def onchange_approvals_other_user_ids(self):
user_ids_list = []
for other_user in self.other_user_ids:
user_ids_list += other_user.user_ids.ids
self.approvals_other_user_ids = user_ids_list
@api.depends('other_user_ids')
def _compute_other_user(self):
other_user_list = []
for other in self.other_user_ids:
other_user_list += other.user_ids.ids
self.approvals_other_user_ids = other_user_list
class ApprovalUsers(models.Model):
@@ -47,14 +35,23 @@ class ApprovalUsers(models.Model):
sequence = fields.Integer(default=1, string="审批顺序")
approval_process_id = fields.Many2one('approval.process', string='审批流程')
approval_department_id = fields.Many2one('hr.department', string='审批部门')
approval_job_lv_id = fields.Many2one('yuthon.job.lv', string='审批角色')
user_ids = fields.Many2many('res.users', string="审批人")
approval_user_role_id = fields.Many2one('yuthon.user.role', string='审批角色')
user_ids = fields.Many2many('res.users', string="审批人", compute="compute_user_ids", store=True, readonly=False)
@api.constrains('sequence')
def _constrains_sequence(self):
for res in self:
if res.sequence <= 0:
raise ValidationError('审批阶段:必须大于0')
@api.depends('approval_department_id', 'approval_user_role_id')
def compute_user_ids(self):
for employee in self:
employee_ids = employee.env['hr.employee']
department_domain = ('department_id', '=', employee.approval_department_id.id)
user_role_domain = ('user_role_ids', '=', employee.approval_user_role_id.id)
if employee.approval_department_id and not employee.approval_user_role_id:
employee.user_ids = employee_ids.search([department_domain]).user_id
elif employee.approval_user_role_id and not employee.approval_department_id:
employee.user_ids = employee_ids.search([user_role_domain]).user_id
elif employee.approval_user_role_id and employee.approval_department_id:
employee.user_ids = employee_ids.search([department_domain, user_role_domain]).user_id
else:
employee.user_ids = []
class ApprovalOtherUsers(models.Model):
@@ -62,5 +59,24 @@ class ApprovalOtherUsers(models.Model):
approval_process_id = fields.Many2one('approval.process', string='审批流程')
approval_department_id = fields.Many2one('hr.department', string='审批部门')
approval_job_lv_id = fields.Many2one('yuthon.job.lv', string='审批角色')
user_ids = fields.Many2many('res.users', string="审批人")
approval_user_role_id = fields.Many2one('yuthon.user.role', string='审批角色')
user_ids = fields.Many2many('res.users', string="传阅人", compute="compute_user_ids", store=True, readonly=False)
@api.depends('approval_department_id', 'approval_user_role_id')
def compute_user_ids(self):
res_users_list = []
for employee in self:
employee_ids = employee.env['hr.employee']
department_domain = ('department_id', '=', employee.approval_department_id.id)
user_role_domain = ('user_role_ids', '=', employee.approval_user_role_id.id)
if employee.approval_department_id and not employee.approval_user_role_id:
employee.user_ids = employee_ids.search([department_domain]).user_id
res_users_list += employee.user_ids.ids
elif employee.approval_user_role_id and not employee.approval_department_id:
employee.user_ids = employee_ids.search([user_role_domain]).user_id
res_users_list += employee.user_ids.ids
elif employee.approval_user_role_id and employee.approval_department_id:
employee.user_ids = employee_ids.search([department_domain, user_role_domain]).user_id
res_users_list += employee.user_ids.ids
else:
employee.user_ids = []
@@ -1,5 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_demo_request,demo_request,model_demo_request,base.group_user,1,1,1,1
access_approval_process,approval_process,model_approval_process,base.group_user,1,1,1,1
access_approval_users,approval_users,model_approval_users,base.group_user,1,1,1,1
access_approval_other_users,approval_other_users,model_approval_other_users,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
access_demo_request demo_request model_demo_request base.group_user 1 1 1 1
2 access_approval_process approval_process model_approval_process base.group_user 1 1 1 1
3 access_approval_users approval_users model_approval_users base.group_user 1 1 1 1
4 access_approval_other_users approval_other_users model_approval_other_users base.group_user 1 1 1 1
@@ -26,7 +26,7 @@
<tree editable="bottom">
<field name="sequence"/>
<field name="approval_department_id"/>
<field name="approval_job_lv_id"/>
<field name="approval_user_role_id"/>
<field name="user_ids" widget="many2many_tags"/>
</tree>
</field>
@@ -36,7 +36,7 @@
<tree editable="bottom">
<field name="approval_process_id" column_invisible="True"/>
<field name="approval_department_id"/>
<field name="approval_job_lv_id"/>
<field name="approval_user_role_id"/>
<field name="user_ids" widget="many2many_tags"/>
</tree>
</field>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="approvals_category_type_code_demo_request" model="ir.ui.view">
<field name="name">approvals.category.type.code.demo.request</field>
<field name="model">approval.request</field>
<field name="inherit_id" ref="approvals.approval_request_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="demo1"/>
<field name="demo2"/>
<field name="demo3"/>
</xpath>
</field>
</record>
</odoo>
-144
View File
@@ -1,144 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="approvals_category_type_code_demo_request" model="ir.ui.view">
<field name="name">approvals.category.type.code.demo.request</field>
<field name="model">demo.request</field>
<field name="arch" type="xml">
<form string="Request" create="false">
<header>
<field name="user_status" invisible="1"/>
<field name="has_access_to_request" invisible="1"/>
<button name="action_confirm" string="提交" type="object" invisible="not approver_ids or request_status != 'new'" class="btn-primary" data-hotkey="q"/>
<button name="action_hsiang" string="驳回" type="object" invisible="request_status in ['approved', 'refused', 'cancel'] or user_status != 'pending'" class="btn-primary" data-hotkey="q"/>
<button name="action_quash" string="撤销" type="object" invisible="request_status in ['approved', 'refused', 'cancel'] or user_status != 'pending'" class="btn-primary" data-hotkey="q"/>
<button name="action_approve" string="批准" type="object" invisible="request_status in ['approved', 'refused', 'cancel'] or user_status != 'pending'" data-hotkey="v"/>
<button name="action_refuse" string="拒绝" type="object" invisible="request_status in ['approved', 'refused', 'cancel'] or user_status != 'pending'" data-hotkey="z"/>
<button name="action_withdraw" string="撤回" type="object" invisible="request_status == 'new' or user_status in ['waiting', 'pending', 'cancel'] or not user_status" data-hotkey="y"/>
<button name="action_draft" string="返回草稿" type="object" invisible="request_status != 'cancel' or not user_status and not has_access_to_request" data-hotkey="w"/>
<button name="action_cancel" string="取消" type="object" invisible="request_status in ['new', 'cancel'] or not user_status and not has_access_to_request" data-hotkey="x"/>
<widget name="attach_document" string="附加文档" action="message_post" invisible="attachment_number &lt; 1"/>
<widget name="attach_document" string="附加文档" action="message_post" highlight="1" invisible="attachment_number &gt;= 1"/>
<field name="request_status" widget="statusbar"/>
</header>
<sheet>
<field name="has_date" invisible="1"/>
<field name="has_period" invisible="1"/>
<field name="has_quantity" invisible="1"/>
<field name="has_amount" invisible="1"/>
<field name="has_reference" invisible="1"/>
<field name="has_partner" invisible="1"/>
<field name="has_payment_method" invisible="1"/>
<field name="has_location" invisible="1"/>
<field name="has_product" invisible="1"/>
<field name="requirer_document" invisible="1"/>
<field name="approval_minimum" invisible="1"/>
<field name="approval_type" invisible="1"/>
<field name="change_request_owner" invisible="1"/>
<div class="o_not_full oe_button_box" name="button_box">
<button name="action_get_attachment_view" class="oe_stat_button" icon="fa-book" type="object" invisible="attachment_number == 0">
<field name="attachment_number" widget="statinfo" string="Documents" options="{'reload_on_button': true}"/>
</button>
</div>
<div class="oe_avatar">
<field name="category_image" widget="image" options="{'preview_image': 'category_image', 'size': [80, 80]}" class="bg-view" />
</div>
<div class="oe_title">
<label for="name"/>
<h1>
<field name="automated_sequence" invisible="1"/>
<field name="name" string="审批名称" placeholder="E.g: Expenses Paris business trip"
required="1"
readonly="automated_sequence"/>
</h1>
</div>
<group>
<group name="request_main">
<field name="request_owner_id" string="申请发起人" domain="[('share', '=', False)]" readonly="not change_request_owner or request_status != 'new'" widget="many2one_avatar_user"/>
<field name="category_id" string="类别" readonly="request_status != 'new'" force_save="1"/>
<field name="date_confirmed" string="确认日期" groups="base.group_no_one" readonly="1"/>
<label for="date" string="Date" invisible="has_date == 'no'"/>
<div invisible="has_date == 'no'">
<div>
<field name="date" class="oe_inline" readonly="request_status != 'new'" required="has_date == 'required'"/>
</div>
</div>
<label for="date_start" string="开始日期" invisible="has_period == 'no'"/>
<div invisible="has_period == 'no'">
<div>
<span>从: </span><field name="date_start" class="oe_inline" readonly="request_status != 'new'" required="has_period == 'required'"/>
</div>
<div>
<span>到: </span><field name="date_end" class="oe_inline ms-4" readonly="request_status != 'new'" required="has_period == 'required'"/>
</div>
</div>
<field name="location" string="位置" invisible="has_location == 'no'" readonly="request_status != 'new'" required="has_location == 'required'" placeholder="e.g. Brussels" />
<field name="partner_id" string="联系人" invisible="has_partner == 'no'" readonly="request_status != 'new'" required="has_partner == 'required'"/>
</group>
<group name="request_details">
<field name="quantity" invisible="has_quantity == 'no' or has_product != 'no'" readonly="request_status != 'new'" required="has_quantity == 'required' and has_product == 'no'"/>
<field name="amount" invisible="has_amount == 'no'" readonly="request_status != 'new'" required="has_amount == 'required'"/>
<field name="reference" invisible="has_reference == 'no'" required="has_reference == 'required'"/>
<field name="company_id"/>
</group>
</group>
<notebook>
<page string="产品" name="products"
invisible="has_product == 'no'">
<field name="product_line_ids"
context="{'tree_view_ref': 'approvals.approval_product_line_view_tree', 'kanban_view_ref': 'approvals.approval_product_kanban_mobile_view'}"
readonly="request_status != 'new'"/>
</page>
<page string="描述" name="description">
<field name="reason" readonly="request_status != 'new'"/>
</page>
<page string="审批人" name="approvers">
<field name="approver_ids" mode="tree,kanban" readonly="request_status != 'new'">
<tree editable="bottom" decoration-success="status=='approved'" decoration-warning="status in ['pending', 'waiting']" decoration-danger="status=='refused'" no_open="1">
<field name="existing_request_user_ids" column_invisible="True"/>
<field name="sequence" column_invisible="True"/>
<field name="can_edit" column_invisible="True"/>
<field name="can_edit_user_id" column_invisible="True"/>
<field name="user_id" string="审批人" readonly="not can_edit_user_id or status != 'new'" force_save="1" />
<field name="required" readonly="not can_edit" force_save="1"/>
<field name="status"/>
<field name="company_id" column_invisible="True"/>
</tree>
<kanban class="o_kanban_mobile">
<field name="company_id"/>
<field name="user_id"/>
<field name="status"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_card oe_kanban_global_click">
<div class="o_kanban_content">
<t t-esc="record.user_id.value"/>
<t t-if="record.status.raw_value">
<t t-set="classname" t-value="{'approved': 'text-bg-success', 'pending': 'text-bg-warning', 'refused': 'text-bg-danger'}[record.status.raw_value] || 'text-bg-light'"/>
<span t-esc="record.status.raw_value" t-attf-class="float-end rounded-pill {{ classname }}"/>
</t>
</div>
</div>
</t>
</templates>
</kanban>
<form>
<group>
<field name="company_id" invisible="1"/>
<field name="existing_request_user_ids" invisible="1"/>
<field name="user_id"/>
</group>
</form>
</field>
</page>
</notebook>
</sheet>
<div class="o_attachment_preview"/>
<div class="oe_chatter">
<field name="message_follower_ids" groups="base.group_user"/>
<field name="activity_ids"/>
<field name="message_ids"/>
</div>
</form>
</field>
</record>
</odoo>
@@ -14,6 +14,7 @@ class ResUsers(models.Model):
employee_data = {
'name': employee.name,
'company_id': employee.env.company.id,
'user_id': employee.id,
}
self.env['hr.employee'].create(employee_data)
else:
@@ -26,7 +26,7 @@ class YuthonHrEmployee(models.Model):
('part_time', '兼职人员'), ('practice', '正式工')], string="用工形式")
user_number = fields.Char(string="员工编号")
job_lv_id = fields.Many2one('yuthon.job.lv', string="最新职级")
main_user_role = fields.Many2many('yuthon.user.role', string="角色")
user_role_ids = fields.Many2many('yuthon.user.role', string="角色")
# 个人信息
user_salary = fields.Float(string="基本工资")
job_lv_salary = fields.Float(string="职级工资")
@@ -101,7 +101,7 @@
</xpath>
<!-- 人事字段的添加-form -->
<xpath expr="//field[@name='work_email']" position="after">
<field name="main_user_role" widget="many2many_tags"/>
<field name="user_role_ids" widget="many2many_tags"/>
</xpath>
<xpath expr="//field[@name='job_id']" position="after">
<field name="number"/>
@@ -54,7 +54,7 @@ class YuthonHrEmployeeWizard(models.Model):
'department_id': department_id.id,
'user_sex': 'boy' if row[2].value == '男' else 'girl',
'birthday': datetime.strptime(row[3].value, '%Y-%m-%d').date(),
'main_user_role': role_list_ids,
'user_role_ids': role_list_ids,
'mobile_phone': row[5].value,
'work_phone': row[6].value,
'work_email': row[7].value,