diff --git a/yuthon_hr_attendance/models/yuthon_special_approval.py b/yuthon_hr_attendance/models/yuthon_special_approval.py index f4f692083..d0db6bb6e 100644 --- a/yuthon_hr_attendance/models/yuthon_special_approval.py +++ b/yuthon_hr_attendance/models/yuthon_special_approval.py @@ -5,7 +5,7 @@ from odoo.exceptions import UserError class YuthonSpecialApproval(models.Model): _name = 'yuthon.special.approval' - _inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin'] + # _inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin'] _description = '特殊加班' yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司") @@ -13,49 +13,47 @@ class YuthonSpecialApproval(models.Model): 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="申请人", + 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="开始日期") + employee_ids = fields.Many2many('hr.employee', string="加班人员", domain="[('department_id.name', '=', '联安粮库')]") + slot_id = fields.Many2one('planning.slot', string="开始日期", domain="[('id', 'in', start_list_ids)]") + start_list_ids = fields.Many2many('planning.slot', 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, - }) + role_a = self.env['planning.role'].search([('name', '=', '联安粮库')], limit=1) + role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '粮库值班'), ('role_id', '=', role_a.id)]) + shift_id = self.slot_id + start_date = shift_id.start_datetime.date() + end_date = start_date + timedelta(days=1) + for employee_id in self.employee_ids: + slot_id = self.env['planning.slot'].search([ + ('resource_id', '=', employee_id.resource_id.id), + ('start_datetime', '>=', start_date), # 大于等于起始日期 + ('start_datetime', '<', end_date), # 小于结束日期 (即下一天), + ]) + if slot_id: + slot_id.write({'template_id': role_template_b}) - @api.onchange('resource_id', 'start_date', 'template_id') + @api.onchange('resource_id', 'slot_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 + if rec.resource_id and rec.slot_id: + rec.name = rec.resource_id.name +':'+ rec.slot_id.start_datetime.strftime("%m/%d") + + @api.onchange("resource_id") + def _onchange_resource_ids(self): + for rec in self: + start_list_ids = self.env['planning.slot'].search([('resource_id', '=', rec.resource_id.id), + ('template_id.planning_name', 'ilike', '%值班%'), + ('start_datetime', '>', datetime.now())]).ids + if start_list_ids: + rec.start_list_ids = [(6, 0, start_list_ids)] + + + diff --git a/yuthon_hr_attendance/views/inherit_resource_views.xml b/yuthon_hr_attendance/views/inherit_resource_views.xml new file mode 100644 index 000000000..0e38334eb --- /dev/null +++ b/yuthon_hr_attendance/views/inherit_resource_views.xml @@ -0,0 +1,19 @@ + + + resource.resource.tree.inherit + resource.resource + + + + + + + + + 批量更新员工 + + + code + action = model.action_resource_resource() + + diff --git a/yuthon_hr_attendance/views/yuthon_special_approval_views.xml b/yuthon_hr_attendance/views/yuthon_special_approval_views.xml index 872daa5fb..ec79e3e13 100644 --- a/yuthon_hr_attendance/views/yuthon_special_approval_views.xml +++ b/yuthon_hr_attendance/views/yuthon_special_approval_views.xml @@ -32,8 +32,8 @@ - - + + @@ -41,7 +41,7 @@ - +