diff --git a/yuthon_hr_attendance/models/overtime_approval.py b/yuthon_hr_attendance/models/overtime_approval.py index 2784dd255..1daec1103 100644 --- a/yuthon_hr_attendance/models/overtime_approval.py +++ b/yuthon_hr_attendance/models/overtime_approval.py @@ -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 +# } +# } diff --git a/yuthon_hr_attendance/views/overtime_approval.xml b/yuthon_hr_attendance/views/overtime_approval.xml index 66f3c5158..55d0cd8e0 100644 --- a/yuthon_hr_attendance/views/overtime_approval.xml +++ b/yuthon_hr_attendance/views/overtime_approval.xml @@ -17,6 +17,9 @@ overtime.approval
+
+
- +
diff --git a/yuthon_sps_approval/__init__.py b/yuthon_sps_approval/__init__.py new file mode 100644 index 000000000..9a7e03ede --- /dev/null +++ b/yuthon_sps_approval/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/yuthon_sps_approval/__manifest__.py b/yuthon_sps_approval/__manifest__.py new file mode 100644 index 000000000..73aebb5e4 --- /dev/null +++ b/yuthon_sps_approval/__manifest__.py @@ -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', + ] + +} + diff --git a/yuthon_sps_approval/data/sps_approval_code_data.xml b/yuthon_sps_approval/data/sps_approval_code_data.xml new file mode 100644 index 000000000..9f8a1ad04 --- /dev/null +++ b/yuthon_sps_approval/data/sps_approval_code_data.xml @@ -0,0 +1,10 @@ + + + + 办公用品申请编号 + yuthon_office_supplies_code + BG%(y)s%(month)s%(day)s + 3 + + + \ No newline at end of file diff --git a/yuthon_sps_approval/models/__init__.py b/yuthon_sps_approval/models/__init__.py new file mode 100644 index 000000000..a3c656160 --- /dev/null +++ b/yuthon_sps_approval/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import yuthon_office_supplies diff --git a/yuthon_sps_approval/models/yuthon_office_supplies.py b/yuthon_sps_approval/models/yuthon_office_supplies.py new file mode 100644 index 000000000..72a34b968 --- /dev/null +++ b/yuthon_sps_approval/models/yuthon_office_supplies.py @@ -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="金额") + diff --git a/yuthon_sps_approval/security/ir.model.access.csv b/yuthon_sps_approval/security/ir.model.access.csv new file mode 100644 index 000000000..6bea8473d --- /dev/null +++ b/yuthon_sps_approval/security/ir.model.access.csv @@ -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 \ No newline at end of file diff --git a/yuthon_sps_approval/views/yuthon_office_supplies_views.xml b/yuthon_sps_approval/views/yuthon_office_supplies_views.xml new file mode 100644 index 000000000..7ce3aabaa --- /dev/null +++ b/yuthon_sps_approval/views/yuthon_office_supplies_views.xml @@ -0,0 +1,65 @@ + + + + yuthon.office.supplies.tree + yuthon.office.supplies + + + + + + + + + + + + yuthon.office.supplies.form + yuthon.office.supplies + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 办公用品申请 + yuthon.office.supplies + tree,form + + \ No newline at end of file diff --git a/yuthon_work_brand/__manifest__.py b/yuthon_work_brand/__manifest__.py index f01457d7f..e7bd05e62 100644 --- a/yuthon_work_brand/__manifest__.py +++ b/yuthon_work_brand/__manifest__.py @@ -21,6 +21,7 @@ 'yuthon_performance', 'website', 'yuthon_hr_employee', + 'yuthon_sps_approval', 'sale', 'payment', 'purchase', diff --git a/yuthon_work_brand/views/hr_menus.xml b/yuthon_work_brand/views/hr_menus.xml index cf83460ff..3e72cc111 100644 --- a/yuthon_work_brand/views/hr_menus.xml +++ b/yuthon_work_brand/views/hr_menus.xml @@ -154,7 +154,11 @@ parent="hr_menu_recruitment_process" action="yuthon_hr_employee_approval.yuthon_message_login_action" sequence="9"/> - +