diff --git a/yuthon_duty_plan/__init__.py b/yuthon_duty_plan/__init__.py index 9b4296142..0650744f6 100644 --- a/yuthon_duty_plan/__init__.py +++ b/yuthon_duty_plan/__init__.py @@ -1,2 +1 @@ from . import models -from . import wizard diff --git a/yuthon_duty_plan/__manifest__.py b/yuthon_duty_plan/__manifest__.py index 3c9388857..d817fbf93 100644 --- a/yuthon_duty_plan/__manifest__.py +++ b/yuthon_duty_plan/__manifest__.py @@ -11,7 +11,7 @@ 'sequence': 240, 'website': 'https://www.pengyuthon.com', 'depends': ['hr_attendance', 'resource', 'base', 'hr', 'mail', - 'soong_workflow', 'yuthon_issue', 'planning', 'calendar'], + 'soong_workflow', 'yuthon_issue','calendar'], 'data': [ 'security/ir.model.access.csv', 'data/arrangement_time_data.xml', @@ -25,8 +25,6 @@ 'views/yuthon_abnormal_setting_views.xml', 'views/yuthon_adjustments_approval_views.xml', 'views/yuthon_shift_approval_views.xml', - 'wizard/yuthon_duty_arrangement_wizard_views.xml', - 'wizard/yuthon_duty_summary_wizard_views.xml', ], 'installable': True, 'application': True, diff --git a/yuthon_duty_plan/models/yuthon_duty_arrangement.py b/yuthon_duty_plan/models/yuthon_duty_arrangement.py index 9f67b4bab..fd9ae50f7 100644 --- a/yuthon_duty_plan/models/yuthon_duty_arrangement.py +++ b/yuthon_duty_plan/models/yuthon_duty_arrangement.py @@ -9,8 +9,8 @@ class YuthonDutyArrangement(models.Model): _order = 'start_time desc' _rec_name = 'employee_id' - employee_id = fields.Many2one('hr.employee', string='员工', - domain=lambda self: [('department_id.name', '=', '仓储组')]) + employee_id = fields.Many2one('hr.employee', string='员工') + duty_class_id = fields.Many2one('yuthon.duty.class.setting', string="班组名称") start_time = fields.Date(string="开始日期") end_time = fields.Date(string="结束日期") remarks = fields.Text(string='备注') @@ -101,3 +101,6 @@ class YuthonDutyArrangement(models.Model): title="值班安排", description='本月的值班表已确认,请查看', url=str, btntxt="详细信息") + + def button_all_duty(self): + pass diff --git a/yuthon_duty_plan/models/yuthon_duty_plan.py b/yuthon_duty_plan/models/yuthon_duty_plan.py index d6e1c970e..1f200fd28 100644 --- a/yuthon_duty_plan/models/yuthon_duty_plan.py +++ b/yuthon_duty_plan/models/yuthon_duty_plan.py @@ -12,30 +12,44 @@ class YuthonDutyPlan(models.Model): end_index_time = fields.Date(string='失效时间') is_enable = fields.Boolean(string="启用", default=True) plan_line_ids = fields.One2many('duty.plan.line', 'duty_plan_id', string='关联计划明细') + notice = fields.Text(string='计划说明') def auto_duty_plan(self): - employee_ids = self.env['hr.employee'].search([('department_id.name', 'in', ['仓储组', '综合组', '保管组', '机安组', - '1库', '2库', '3库', '联安粮库'])]) - self.plan_line_ids.unlink() - sequence = 1 - for employee in employee_ids: - self.env['duty.plan.line'].create({ - 'duty_plan_id': self.id, - 'sequence': sequence, - 'employee_id': employee.id - }) - sequence += 1 + today = datetime.today().date() + first_day_of_month = today.replace(day=1) + if today.month < 12: + last_day_of_month = (today.replace(month=today.month + 1, day=1) - timedelta(days=1)) + else: + last_day_of_month = (today.replace(year=today.year + 1, month=1, day=1) - timedelta(days=1)) + duty_lines = [] + current_date = first_day_of_month + while current_date <= last_day_of_month: + for line in self.plan_line_ids: + for employee in line.employee_ids: + duty_lines.append({ + 'employee_id': employee.id, + 'start_time': current_date, + 'end_time': current_date, + 'duty_class_id': line.duty_class_id.id, + }) + current_date += timedelta(days=1) + if current_date > last_day_of_month: + break + self.env['yuthon.duty.arrangement'].create(duty_lines) + tree_id = self.env.ref("yuthon_duty_plan.view_yuthon_duty_arrangement_tree").id + return { + "type": "ir.actions.act_window", + "name": "值班安排", + "res_model": "yuthon.duty.arrangement", + "views": [[tree_id, "tree"]], + } class DutyPlanLine(models.Model): _name = 'duty.plan.line' _description = '值班计划明细行' - _order = 'sequence asc' + sequence = fields.Char(string='序号', store=True) duty_plan_id = fields.Many2one('yuthon.duty.plan', string='关联计划名称') - sequence = fields.Integer(string='序号') - employee_id = fields.Many2one('hr.employee', string='员工', - domain=lambda self: [('department_id.name', 'in', ['仓储组', '综合组', - '保管组', '机安组', - '1库', '2库', '3库', - '联安粮库'])]) + employee_ids = fields.Many2many('hr.employee', string='值班人员') + duty_class_id = fields.Many2one('yuthon.duty.class.setting', string="班组名称") diff --git a/yuthon_duty_plan/models/yuthon_duty_setting.py b/yuthon_duty_plan/models/yuthon_duty_setting.py index 22664210d..e892891d9 100644 --- a/yuthon_duty_plan/models/yuthon_duty_setting.py +++ b/yuthon_duty_plan/models/yuthon_duty_setting.py @@ -6,3 +6,11 @@ class YuthonDutySetting(models.Model): _description = '值班说明配置' reason_application = fields.Html(string="说明") + + +class YuthonDutyClassSetting(models.Model): + _name = 'yuthon.duty.class.setting' + _description = '值班班组配置' + _rec_name = 'name' + + name = fields.Char(string="班组名称") diff --git a/yuthon_duty_plan/security/ir.model.access.csv b/yuthon_duty_plan/security/ir.model.access.csv index c698edd4b..612bdadaa 100644 --- a/yuthon_duty_plan/security/ir.model.access.csv +++ b/yuthon_duty_plan/security/ir.model.access.csv @@ -1,14 +1,10 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_yuthon_duty_arrangement,yuthon.duty.arrangement,model_yuthon_duty_arrangement,base.group_user,1,1,1,1 -access_yuthon_duty_arrangement_wizard,yuthon.duty.arrangement.wizard,model_yuthon_duty_arrangement_wizard,base.group_user,1,1,1,1 access_yuthon_duty_plan,yuthon.duty.plan,model_yuthon_duty_plan,base.group_user,1,1,1,1 access_duty_plan_line,duty.plan.line,model_duty_plan_line,base.group_user,1,1,1,1 access_yuthon_duty_setting,yuthon.duty.setting,model_yuthon_duty_setting,base.group_user,1,1,1,1 +access_yuthon_duty_class_setting,yuthon.duty.class.setting,model_yuthon_duty_class_setting,base.group_user,1,1,1,1 access_yuthon_duty_summary,yuthon.duty.summary,model_yuthon_duty_summary,base.group_user,1,1,1,1 -access_yuthon_duty_summary_wizard,yuthon.duty.summary.wizard,model_yuthon_duty_summary_wizard,base.group_user,1,1,1,1 - - -access_duty_approval_line,duty.approval.line,model_duty_approval_line,base.group_user,1,1,1,1 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 diff --git a/yuthon_duty_plan/views/yuthon_duty_arrangement_views.xml b/yuthon_duty_plan/views/yuthon_duty_arrangement_views.xml index 4ada78d4c..e84a9966e 100644 --- a/yuthon_duty_plan/views/yuthon_duty_arrangement_views.xml +++ b/yuthon_duty_plan/views/yuthon_duty_arrangement_views.xml @@ -5,7 +5,11 @@ yuthon.duty.arrangement +
+
+ @@ -13,8 +17,8 @@ -