添加功能
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import api, fields, models, tools, _
|
||||
from datetime import datetime, time, timedelta
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class OvertimeApprovals(models.Model):
|
||||
_name = 'overtime.approval'
|
||||
_description = "加班审批"
|
||||
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin','soong.workflow.mixin']
|
||||
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'soong.workflow.mixin']
|
||||
_rec_name = 'name'
|
||||
|
||||
yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司")
|
||||
name = fields.Char(string="标题")
|
||||
code = fields.Char(string="编号",default=lambda self: self.env['ir.sequence'].next_by_code('overtime_approval'))
|
||||
users_id = fields.Many2one('res.users', string="申请人",default=lambda self: self.env.user.id)
|
||||
overtime_approval_ids = fields.One2many('overtime.user.line', 'overtime_approval_id', string="加班审批行",default=lambda self: self._default_user_lines())
|
||||
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('overtime_approval'))
|
||||
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
||||
overtime_approval_ids = fields.One2many('overtime.user.line', 'overtime_approval_id', string="加班审批行",
|
||||
default=lambda self: self._default_user_lines())
|
||||
reason_application = fields.Char(string="事由")
|
||||
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
|
||||
is_issues = fields.Boolean(string='是否上会')
|
||||
details = fields.Text(string="加班说明")
|
||||
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
||||
|
||||
@api.onchange('overtime_department_id')
|
||||
def onchange_overtime_users(self):
|
||||
users_data_list = []
|
||||
@@ -62,20 +64,32 @@ class OvertimeApprovals(models.Model):
|
||||
def _default_user_lines(self):
|
||||
return [(0, 0, {'users_id': self.env.user.id})]
|
||||
|
||||
def put_hr_employee(self):
|
||||
for overtime_id in self.overtime_approval_ids:
|
||||
employee_id = self.env['hr.employee'].search([('id', '=', overtime_id.users_id.employee_id.id)])
|
||||
if overtime_id.type_overtime == 'work':
|
||||
employee_id.write({'normal_overtime_hours': employee_id.normal_overtime_hours + overtime_id.hours})
|
||||
elif overtime_id.type_overtime == 'weekend':
|
||||
employee_id.write({'weekend_overtime_hours': employee_id.weekend_overtime_hours + overtime_id.hours})
|
||||
else:
|
||||
employee_id.write({'holiday_overtime_hours': employee_id.holiday_overtime_hours + overtime_id.hours})
|
||||
overtime_id.overtime_hours = employee_id.holiday_overtime_hours + employee_id.weekend_overtime_hours + employee_id.normal_overtime_hours
|
||||
|
||||
class OvertimeUserLine(models.Model):
|
||||
_name = 'overtime.user.line'
|
||||
_rec_name = 'overtime_approval_id'
|
||||
_description = "加班明细行"
|
||||
|
||||
overtime_approval_id = fields.Many2one('overtime.approval', string="加班单号")
|
||||
users_id = fields.Many2one('res.users',string="加班人员")
|
||||
users_id = fields.Many2one('res.users', string="加班人员")
|
||||
department_id = fields.Many2one('hr.department', string="部门")
|
||||
overtime_hours = fields.Float(string="本月加班时长")
|
||||
documents_ids = fields.Many2many('ir.attachment', string="附件")
|
||||
start_time = fields.Datetime(string="开始时间")
|
||||
end_time = fields.Datetime(string="结束时间")
|
||||
hours = fields.Float(string="加班时长", compute="_compute_hours")
|
||||
type_overtime = fields.Selection([('work', '工作日加班'), ('weekend', '周末加班'), ('holiday', '节假日加班')], string="加班类型")
|
||||
type_overtime = fields.Selection([('work', '工作日加班'), ('weekend', '周末加班'), ('holiday', '节假日加班')],
|
||||
string="加班类型", compute="_compute_overtime_type")
|
||||
|
||||
@api.depends('start_time', 'end_time')
|
||||
def _compute_hours(self):
|
||||
@@ -86,14 +100,45 @@ class OvertimeUserLine(models.Model):
|
||||
else:
|
||||
record.hours = 0
|
||||
|
||||
# def attendance_button(self):
|
||||
# return {
|
||||
# 'type': 'ir.actions.client',
|
||||
# 'tag': 'display_notification',
|
||||
# 'target': 'new',
|
||||
# 'params': {
|
||||
# 'title': '考勤信息',
|
||||
# 'message': _(self.user_id.name + "的签到时间:2024-7-12 8:00:00 签出时间:2024-7-12 20:00:00"),
|
||||
# 'sticky': True
|
||||
# }
|
||||
# }
|
||||
@api.depends('start_time', 'end_time')
|
||||
def _compute_overtime_type(self):
|
||||
for record in self:
|
||||
if record.start_time and record.end_time:
|
||||
if record.start_time > record.end_time:
|
||||
raise UserError("开始时间不能晚于结束时间")
|
||||
start_date = fields.Datetime.from_string(record.start_time)
|
||||
end_date = fields.Datetime.from_string(record.end_time)
|
||||
public_holidays = self.env['resource.calendar.leaves'].search([])
|
||||
for holiday in public_holidays:
|
||||
holiday_start = fields.Datetime.from_string(holiday.date_from)
|
||||
holiday_end = fields.Datetime.from_string(holiday.date_to)
|
||||
if start_date <= holiday_end and end_date >= holiday_start:
|
||||
record.type_overtime = 'holiday'
|
||||
break
|
||||
else:
|
||||
if start_date.weekday() < 5 and end_date.weekday() < 5: # Not Saturday or Sunday
|
||||
record.type_overtime = 'work'
|
||||
elif start_date.weekday() >= 5 or end_date.weekday() >= 5: # Saturday or Sunday
|
||||
record.type_overtime = 'weekend'
|
||||
else:
|
||||
record.type_overtime = False
|
||||
|
||||
|
||||
# def is_holiday(self, date):
|
||||
# holiday_obj = self.env['resource.calendar.leaves']
|
||||
# holidays = holiday_obj.search([
|
||||
# ('date_from', '<=', date),
|
||||
# ('date_to', '>=', date)
|
||||
# ])
|
||||
# return bool(holidays)
|
||||
# def attendance_button(self):
|
||||
# return {
|
||||
# 'type': 'ir.actions.client',
|
||||
# 'tag': 'display_notification',
|
||||
# 'target': 'new',
|
||||
# 'params': {
|
||||
# 'title': '考勤信息',
|
||||
# 'message': _(self.user_id.name + "的签到时间:2024-7-12 8:00:00 签出时间:2024-7-12 20:00:00"),
|
||||
# 'sticky': True
|
||||
# }
|
||||
# }
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
<field name="model">overtime.approval</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<button name="put_hr_employee" type="object" string="Approve" class="oe_highlight"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
|
||||
@@ -91,7 +91,7 @@ class YuthonHrEmployee(models.Model):
|
||||
weekend_overtime_hours = fields.Float(string="周末加班时间(小时)")
|
||||
holiday_overtime_hours = fields.Float(string="节假日加班时间(小时)")
|
||||
holiday_hours = fields.Float(string="假期额度")
|
||||
all_overtime_hours = fields.Float(string="总加班小时")
|
||||
all_overtime_hours = fields.Float(string="总加班小时", compute="_compute_all_overtime_hours", store=True)
|
||||
replacement_card_count = fields.Integer(string="补卡次数")
|
||||
# 假期
|
||||
user_year_holiday_hours = fields.Float(string="已用年假")
|
||||
@@ -265,4 +265,8 @@ class YuthonHrEmployee(models.Model):
|
||||
else:
|
||||
record.user_state = ''
|
||||
|
||||
@api.depends('normal_overtime_hours','weekend_overtime_hours','holiday_overtime_hours')
|
||||
def _compute_all_overtime_hours(self):
|
||||
for record in self:
|
||||
record.all_overtime_hours = record.normal_overtime_hours + record.weekend_overtime_hours + record.holiday_overtime_hours
|
||||
|
||||
|
||||
@@ -129,9 +129,9 @@
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='public']//group[@name='departure']" position="after">
|
||||
<group name="overtime" string="加班">
|
||||
<field name="normal_overtime_hours"/>
|
||||
<field name="weekend_overtime_hours"/>
|
||||
<field name="holiday_overtime_hours"/>
|
||||
<field name="normal_overtime_hours" readonly="1"/>
|
||||
<field name="weekend_overtime_hours" readonly="1"/>
|
||||
<field name="holiday_overtime_hours" readonly="1"/>
|
||||
<field name="holiday_hours"/>
|
||||
<field name="all_overtime_hours"/>
|
||||
<field name="replacement_card_count"/>
|
||||
|
||||
@@ -62,7 +62,8 @@
|
||||
</div>
|
||||
<div class="mb-3 field-room_id">
|
||||
<label for="attachment" class="form-label">附件</label>
|
||||
<input type="file" class="form-control-file" name="attachment" id="attachment" style="background-color:#eee;"/>
|
||||
<input type="file" class="form-control-file" name="attachment" id="attachment"
|
||||
style="background-color:#eee;"/>
|
||||
</div>
|
||||
<div class="mb-3 field-room_id">
|
||||
<label for="phone" class="form-label">电话</label>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
@@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
'name': "Yuthon sps approvl",
|
||||
'summary': "进销存审批单",
|
||||
'description': """进销存审批单 """,
|
||||
'category': 'zhou',
|
||||
'version': '0.1',
|
||||
'license': 'LGPL-3',
|
||||
'depends': ['base','soong_workflow','yuthon_issue','hr','documents','product','mail'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/yuthon_office_supplies_views.xml',
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="yuthon_sps_code_sequence" model="ir.sequence">
|
||||
<field name="name">办公用品申请编号</field>
|
||||
<field name="code">yuthon_office_supplies_code</field>
|
||||
<field name="prefix">BG%(y)s%(month)s%(day)s</field>
|
||||
<field name="padding">3</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import yuthon_office_supplies
|
||||
@@ -0,0 +1,29 @@
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class YuthonOfficeSupplies(models.Model):
|
||||
_name = 'yuthon.office.supplies'
|
||||
_description = '办公用品申请'
|
||||
|
||||
name = fields.Char(string='标题', required=True)
|
||||
code = fields.Char(string="编号",
|
||||
default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_office_supplies_code'))
|
||||
is_issues = fields.Boolean(string='是否上会')
|
||||
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
||||
department_id = fields.Many2one('hr.department', string="部门", related='users_id.employee_id.department_id')
|
||||
reason_application = fields.Html(string="事由")
|
||||
date = fields.Date(string="申请日期", default=fields.Date.today())
|
||||
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
||||
yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司")
|
||||
yuthon_office_supplies_line_ids = fields.One2many('yuthon.office.supplies.line', 'supplies_id', string="关联办公用品申请明细")
|
||||
|
||||
class YuthonOfficeSuppliesLine(models.Model):
|
||||
_name = 'yuthon.office.supplies.line'
|
||||
_description = '办公用品申请明细'
|
||||
|
||||
supplies_id = fields.Many2one('yuthon.office.supplies', string="关联办公用品申请")
|
||||
name = fields.Many2one('product.product', string="办公用品")
|
||||
number = fields.Integer(string="数量")
|
||||
price = fields.Float(string="单价")
|
||||
amount = fields.Float(string="金额")
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_yuthon_office_supplies,yuthon_office_supplies,model_yuthon_office_supplies,base.group_user,1,1,1,1
|
||||
access_yuthon_office_supplies_line,yuthon_office_supplies_line,model_yuthon_office_supplies_line,base.group_user,1,1,1,1
|
||||
|
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_yuthon_office_supplies_tree" model="ir.ui.view">
|
||||
<field name="name">yuthon.office.supplies.tree</field>
|
||||
<field name="model">yuthon.office.supplies</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="办公用品申请">
|
||||
<field name="name"/>
|
||||
<field name="users_id"/>
|
||||
<field name="department_id"/>
|
||||
<field name="yuthon_company"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_yuthon_office_supplies_form" model="ir.ui.view">
|
||||
<field name="name">yuthon.office.supplies.form</field>
|
||||
<field name="model">yuthon.office.supplies</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="办公用品申请">
|
||||
<sheet>
|
||||
<group string="申请人信息" col="3">
|
||||
<group>
|
||||
<field name="users_id"/>
|
||||
<field name="code"/>
|
||||
<field name="is_issues" invisible="1"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="department_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="yuthon_company"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="审批事项">
|
||||
<field name="name"/>
|
||||
<field name="date"/>
|
||||
<field name="reason_application"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="办公用品申请明细">
|
||||
<field name="yuthon_office_supplies_line_ids">
|
||||
<tree editable="bottom">
|
||||
<field name="supplies_id" column_invisible="1"/>
|
||||
<field name="name"/>
|
||||
<field name="number"/>
|
||||
<field name="price"/>
|
||||
<field name="amount"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="关联议题" invisible="not is_issues">
|
||||
<field name="related_issues_id"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_yuthon_office_supplies_action" model="ir.actions.act_window">
|
||||
<field name="name">办公用品申请</field>
|
||||
<field name="res_model">yuthon.office.supplies</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -21,6 +21,7 @@
|
||||
'yuthon_performance',
|
||||
'website',
|
||||
'yuthon_hr_employee',
|
||||
'yuthon_sps_approval',
|
||||
'sale',
|
||||
'payment',
|
||||
'purchase',
|
||||
|
||||
@@ -154,7 +154,11 @@
|
||||
parent="hr_menu_recruitment_process"
|
||||
action="yuthon_hr_employee_approval.yuthon_message_login_action"
|
||||
sequence="9"/>
|
||||
|
||||
<menuitem id="yuthon_sps_approval_root_board"
|
||||
name="办公用品申请"
|
||||
parent="hr_menu_recruitment_process"
|
||||
action="yuthon_sps_approval.view_yuthon_office_supplies_action"
|
||||
sequence="12"/>
|
||||
<menuitem id="hr_recruitment_setting_menu_board"
|
||||
name="配置"
|
||||
parent="hr_recruitment_menu_root_board"
|
||||
|
||||
Reference in New Issue
Block a user