diff --git a/yuthon_contract/wizard/yuthon_contract_wizard.py b/yuthon_contract/wizard/yuthon_contract_wizard.py index f808fdc6d..88dcc80c1 100644 --- a/yuthon_contract/wizard/yuthon_contract_wizard.py +++ b/yuthon_contract/wizard/yuthon_contract_wizard.py @@ -28,11 +28,11 @@ class YuthonContractWizard(models.Model): def employee_contract_data(self,row): employee_id = self.env['hr.employee'].search([('name', '=', row[1].value)]) - structure_type_id = self.env['hr.payroll.structure.type'].search([('name', '=', row[4].value), ('yuthon_company', '=', 'thwg')]) - party_id = self.env['yuthon.party.setting'].search([('party', '=', row[5].value)]) - contract_type_id = self.env['hr.contract.type'].search([('name', '=', row[6].value)]) + structure_type_id = self.env['hr.payroll.structure.type'].search([('name', '=', row[2].value), ('yuthon_company', '=', 'thtz')]) + party_id = self.env['yuthon.party.setting'].search([('party', '=', row[0].value)]) + contract_type_id = self.env['hr.contract.type'].search([('name', '=', row[3].value)]) wage_id = self.env['hr.salary.rule'].search([('struct_id.name', '=', structure_type_id.name), - ('yuthon_company', '=', 'thwg'), + ('yuthon_company', '=', 'thtz'), ('name', '=', '基本工资')]) wage = wage_id.amount_fix self.env['hr.contract'].create({ @@ -43,3 +43,4 @@ class YuthonContractWizard(models.Model): 'wage':wage, 'state':'open' }) + diff --git a/yuthon_hr_attendance/__manifest__.py b/yuthon_hr_attendance/__manifest__.py index 3507c169c..d35317873 100644 --- a/yuthon_hr_attendance/__manifest__.py +++ b/yuthon_hr_attendance/__manifest__.py @@ -33,6 +33,7 @@ 'views/leave_approval.xml', 'views/overtime_page_views.xml', 'views/remove_holiday_approval.xml', + 'views/yuthon_special_approval_views.xml', 'views/card_approval.xml', 'views/duty_approval.xml', 'views/yuthon_duty_setting_views.xml', diff --git a/yuthon_hr_attendance/data/attendance_code_data.xml b/yuthon_hr_attendance/data/attendance_code_data.xml index 08cba4559..4cb782a93 100644 --- a/yuthon_hr_attendance/data/attendance_code_data.xml +++ b/yuthon_hr_attendance/data/attendance_code_data.xml @@ -55,4 +55,18 @@ BK%(y)s%(month)s%(day)s 3 + + + 值班调替班申请序号 + shift_approval + DT%(y)s%(month)s%(day)s + 3 + + + + 值班特殊加班申请序号 + special_approval + TS%(y)s%(month)s%(day)s + 3 + diff --git a/yuthon_hr_attendance/data/attendance_time_data.xml b/yuthon_hr_attendance/data/attendance_time_data.xml index 989f56831..35f2749ef 100644 --- a/yuthon_hr_attendance/data/attendance_time_data.xml +++ b/yuthon_hr_attendance/data/attendance_time_data.xml @@ -14,9 +14,7 @@ -1 - - 定时任务:粮库上班打卡提醒 @@ -65,26 +63,24 @@ 1 days - + -1 - - - - - - - - - - - - - - - + + 定时任务:工程部白班上班打卡提醒 + + code + model.card_remind() + + + 1 + days + + -1 + + 定时任务:工程部白班下班打卡提醒 @@ -124,9 +120,7 @@ -1 - - 定时任务:保安部中班上班打卡提醒 diff --git a/yuthon_hr_attendance/models/__init__.py b/yuthon_hr_attendance/models/__init__.py index 1fe56acb0..214d80596 100644 --- a/yuthon_hr_attendance/models/__init__.py +++ b/yuthon_hr_attendance/models/__init__.py @@ -20,6 +20,7 @@ from . import yuthon_adjustments_approval from . import yuthon_abnormal_approval from . import yuthon_abnormal_setting from . import yuthon_shift_approval +from . import yuthon_special_approval diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index c69cd3ad5..90e9b87c7 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -265,9 +265,7 @@ class HrAttendance(models.Model): resource = self.env['resource.resource'].browse(resource_id) _logger.info("定时任务执行中") if department_id_name == '工程部' and name in ('白班', '中值夜班'): - _logger.info("判断前now:{}---start:{}".format(datetime.now(), slot.start_datetime + timedelta(hours=8))) if datetime.now() <= slot.start_datetime + timedelta(hours=8): - _logger.info("判断后now:{}---start:{}".format(datetime.now(), slot.start_datetime + timedelta(hours=8))) self.card_in_comment(resource.employee_id) elif datetime.now() >= slot.end_datetime + timedelta(hours=8): self.card_out_comment(resource.employee_id) diff --git a/yuthon_hr_attendance/models/yuthon_shift_approval.py b/yuthon_hr_attendance/models/yuthon_shift_approval.py index 6be4d3092..d9d3f5021 100644 --- a/yuthon_hr_attendance/models/yuthon_shift_approval.py +++ b/yuthon_hr_attendance/models/yuthon_shift_approval.py @@ -2,6 +2,8 @@ from odoo import api, fields, models, tools, _ from datetime import datetime, time, timedelta from odoo.exceptions import UserError +from odoo.odoo.api import ondelete + class YuthonShiftApproval(models.Model): _name = 'yuthon.shift.approval' @@ -10,10 +12,12 @@ class YuthonShiftApproval(models.Model): yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司") users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id) - name = fields.Char(string="标题", compute='_compute_name', readonly=False) - code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('adjustments_approval')) + name = fields.Char(string="标题", default=lambda self: self.env.user.employee_id.resource_id.name) + code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('shift_approval')) resource_id = fields.Many2one('resource.resource', string="申请人", default=lambda self: self.env.user.employee_id.resource_id.id) transferees_id = fields.Many2one('resource.resource', string="调班对象", domain="[('id', 'in', resource_ids)]") + alternate_id = fields.Many2one('resource.resource', string="替班对象", domain="[('id', 'in', resource_ids)]") + alternate_shifts = fields.Selection([('transferees', '调班'), ('alternate', '替班')], string="调替班" , default='transferees') shift_id = fields.Many2one('planning.slot', string="班次") return_id = fields.Many2one('planning.slot', string="班次") department_id = fields.Many2one('hr.department', string="部门", related='resource_id.employee_id.department_id') @@ -45,9 +49,19 @@ class YuthonShiftApproval(models.Model): shift_id = self.shift_id return_id = self.return_id original_shift_template_id = shift_id.template_id.id - if not self.transferees_id: - shift_id.write({ - 'template_id': return_id.template_id.id, + start_time= shift_id.start_datetime + end_time = shift_id.end_datetime + role_id = shift_id.role_id + template_id = self.env['planning.slot.template'].search([('id', '=', shift_id.template_id.id)]) + if self.alternate_id: + shift_id.unlink() + self.env['planning.slot'].create({ + 'resource_id':self.alternate_id.id, + 'template_id':template_id.id, + 'start_datetime':start_time, + 'end_datetime':end_time, + 'role_id':role_id.id, + 'allocated_hours':8 }) else: shift_id.write({ @@ -57,29 +71,33 @@ class YuthonShiftApproval(models.Model): 'template_id':original_shift_template_id, }) - @api.depends('resource_id', 'transferees_id') - def _compute_name(self): + @api.onchange('resource_id', 'transferees_id', 'alternate_id') + def onchange_name(self): for rec in self: - if rec.resource_id: - rec.name = '调班:'+ rec.resource_id.name - elif rec.resource_id and rec.transferees_id: + if rec.resource_id and rec.transferees_id and rec.alternate_shifts =='transferees': rec.name = '调班:'+ rec.resource_id.name + '-' + rec.transferees_id.name + elif rec.resource_id and rec.alternate_id and rec.alternate_shifts =='alternate': + rec.name = '替班:'+ rec.resource_id.name + '-' + rec.alternate_id.name @api.onchange('department_id') def _onchange_resource_ids(self): resource_ids = [] - employee_ids = self.env['hr.employee'].search([('department_id', '=', self.department_id.id)]) - for employee in employee_ids: - resource_id = self.env['resource.resource'].search([('name', '=', employee.name)], limit=1) - if resource_id: - resource_ids.append(resource_id.id) + target_departments = ['工程部', '保安部', '联安粮库'] + # 检查当前部门或其父部门是否在目标部门列表中 + current_department = self.department_id + while current_department: + if current_department.name in target_departments: + # 获取所有子部门(包括子部门的子部门) + all_child_departments = self.env['hr.department'].search([('id', 'child_of', current_department.id)]) + # 查找所有属于这些子部门的员工 + employee_ids = self.env['hr.employee'].search([('department_id', 'in', all_child_departments.ids)]) + for employee in employee_ids: + resource_id = self.env['resource.resource'].search([('name', '=', employee.name)], limit=1) + if resource_id: + resource_ids.append(resource_id.id) + break - child_ids = self.env['hr.department'].search([('parent_id', '=', self.department_id.id)]) - for child in child_ids: - employee_ids = self.env['hr.employee'].search([('department_id', '=', child.id)]) - for employee in employee_ids: - resource_id = self.env['resource.resource'].search([('name', '=', employee.name)], limit=1) - if resource_id: - resource_ids.append(resource_id.id) + current_department = current_department.parent_id # 继续检查父部门 + + self.resource_ids = [(6, 0, resource_ids)] - self.resource_ids = [(6, 0, resource_ids)] \ No newline at end of file diff --git a/yuthon_hr_attendance/models/yuthon_special_approval.py b/yuthon_hr_attendance/models/yuthon_special_approval.py new file mode 100644 index 000000000..f4f692083 --- /dev/null +++ b/yuthon_hr_attendance/models/yuthon_special_approval.py @@ -0,0 +1,61 @@ +from odoo import api, fields, models, tools, _ +from datetime import datetime, time, timedelta +from odoo.exceptions import UserError + + +class YuthonSpecialApproval(models.Model): + _name = 'yuthon.special.approval' + _inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin'] + _description = '特殊加班' + + yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司") + users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id) + name = fields.Char(string="标题", readonly=False, default=lambda self: self.env.user.employee_id.resource_id.name) + reason_application = fields.Html(string="申请事由") + code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('special_approval')) + resource_id = fields.Many2one('resource.resource', string="申请人", + default=lambda self: self.env.user.employee_id.resource_id.id) + template_id = fields.Many2one('planning.slot.template', string="加班模板", domain="[('department_id', '=', departments_id)]") + start_date = fields.Date(string="开始日期") + documents_ids = fields.Many2many('ir.attachment', string="附件") + department_id = fields.Many2one('hr.department', string="部门", related='resource_id.employee_id.department_id') + departments_id = fields.Many2one('hr.department', string="部门") + active = fields.Boolean('Active', default=True, tracking=True) + is_issues = fields.Boolean(string='是否上会') + related_issues_id = fields.Many2one('issue.library', string="关联议题") + + @api.onchange('department_id') + def _onchange_resource_ids(self): + target_departments = ['工程部', '保安部', '联安粮库'] + current_department = self.department_id + while current_department: + if current_department.name in target_departments: + self.departments_id = current_department.id + break + current_department = current_department.parent_id + + def button_special_approval(self): + role_a = self.env['planning.role'].search([('name', '=', self.departments_id.name)], limit=1) + start_datetime = datetime.combine(self.start_date, datetime.min.time()) + start_hour = int(self.template_id.start_time) + end_hour = int(self.template_id.end_time) + start_time = start_datetime.replace(hour=start_hour) + timedelta(hours=16) - timedelta(days=1) + if self.template_id.end_time < self.template_id.start_time: + end_time = start_datetime.replace(hour=end_hour) + timedelta(days=1, hours=16) - timedelta(days=1) + else: + end_time = start_datetime.replace(hour=end_hour) + timedelta(hours=16) - timedelta(days=1) + self.env['planning.slot'].create({ + 'resource_id': self.resource_id.id, + 'template_id': self.template_id.id, + 'role_id': role_a.id, + 'start_datetime': start_time, + 'end_datetime': end_time, + 'allocated_hours': 8, + }) + + @api.onchange('resource_id', 'start_date', 'template_id') + def onchange_name(self): + for rec in self: + if rec.resource_id and rec.start_date and rec.template_id: + rec.name = rec.resource_id.name + str(rec.start_date) + rec.template_id.planning_name + diff --git a/yuthon_hr_attendance/security/ir.model.access.csv b/yuthon_hr_attendance/security/ir.model.access.csv index ea6202535..4cf2e72e3 100644 --- a/yuthon_hr_attendance/security/ir.model.access.csv +++ b/yuthon_hr_attendance/security/ir.model.access.csv @@ -29,4 +29,5 @@ access_yuthon_duty_class_setting,yuthon.duty.class.setting,model_yuthon_duty_cla access_yuthon_adjustments_approval,yuthon.adjustments.approval,model_yuthon_adjustments_approval,base.group_user,1,1,1,1 access_yuthon_abnormal_approval,yuthon.abnormal.approval,model_yuthon_abnormal_approval,base.group_user,1,1,1,1 access_yuthon_abnormal_setting,yuthon.abnormal.setting,model_yuthon_abnormal_setting,base.group_user,1,1,1,1 -access_yuthon_shift_approval,yuthon.shift.approval,model_yuthon_shift_approval,base.group_user,1,1,1, \ No newline at end of file +access_yuthon_shift_approval,yuthon.shift.approval,model_yuthon_shift_approval,base.group_user,1,1,1,1 +access_yuthon_special_approval,yuthon.special.approval,model_yuthon_special_approval,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml b/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml index d900e72e9..b2ecd7d58 100644 --- a/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml +++ b/yuthon_hr_attendance/views/yuthon_shift_approval_views.xml @@ -32,8 +32,10 @@ + - + + @@ -41,8 +43,9 @@ + - + diff --git a/yuthon_hr_attendance/views/yuthon_special_approval_views.xml b/yuthon_hr_attendance/views/yuthon_special_approval_views.xml new file mode 100644 index 000000000..872daa5fb --- /dev/null +++ b/yuthon_hr_attendance/views/yuthon_special_approval_views.xml @@ -0,0 +1,58 @@ + + + + special.approval.tree + yuthon.special.approval + + + + + + + + + + + special.approval.form + yuthon.special.approval + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + 特殊加班审批 + yuthon.special.approval + tree,form + +
+ + diff --git a/yuthon_salary/views/inherit_hr_payroll_structure_views.xml b/yuthon_salary/views/inherit_hr_payroll_structure_views.xml index cedd822bb..143449b90 100644 --- a/yuthon_salary/views/inherit_hr_payroll_structure_views.xml +++ b/yuthon_salary/views/inherit_hr_payroll_structure_views.xml @@ -35,6 +35,7 @@ + diff --git a/yuthon_work_brand/views/attendance_menu.xml b/yuthon_work_brand/views/attendance_menu.xml index 6f011be7b..2ee9d00b1 100644 --- a/yuthon_work_brand/views/attendance_menu.xml +++ b/yuthon_work_brand/views/attendance_menu.xml @@ -279,6 +279,11 @@ parent="menu_hr_attendance_approval_request_board" sequence="13" action="yuthon_hr_attendance.approval_request_card"/> +