diff --git a/yuthon_hr_attendance/models/yuthon_customer_planning.py b/yuthon_hr_attendance/models/yuthon_customer_planning.py index 914633b25..c006ca9f7 100644 --- a/yuthon_hr_attendance/models/yuthon_customer_planning.py +++ b/yuthon_hr_attendance/models/yuthon_customer_planning.py @@ -16,7 +16,7 @@ class YuthonCustomerPlanning(models.Model): select_time = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'), ('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'), ('9', '九月'), ('10', '十月'), ('11', '十一月'), - ('12', '十二月')], string='选择月份') + ('12', '十二月')], string='选择月份', default=lambda self: self._get_default_month()) def auto_customer_plan(self, next_date=False): selected_month = int(self.select_time) @@ -27,6 +27,13 @@ class YuthonCustomerPlanning(models.Model): next_month = (selected_month % 12) + 1 next_year = year + (1 if next_month == 1 else 0) # 如果是12月,年份加1 end_date = datetime(next_year, next_month, 1) + existing_slots = self.env['planning.slot'].search([ + ('role_id.name', '=', '客服中心'), + ('start_datetime', '>=', start_date), + ('start_datetime', '<=', end_date), + ]) + if len(existing_slots) > 0: + raise UserError(f"该月已经有排程,请选择其他时间。") else: next_month = (selected_month % 12) + 1 next_year = year + (1 if next_month == 1 else 0) @@ -34,12 +41,19 @@ class YuthonCustomerPlanning(models.Model): next_next_month = (next_month % 12) + 1 next_next_year = next_year + (1 if next_next_month == 1 else 0) end_date = datetime(next_next_year, next_next_month, 1) + existing_slots = self.env['planning.slot'].search([ + ('role_id.name', '=', '客服中心'), + ('start_datetime', '>=', start_date), + ('start_datetime', '<=', end_date), + ]) + if len(existing_slots) > 0: + raise UserError(f"该月已经有排程,请选择其他时间。") role_a = self.env['planning.role'].search([('name', '=', '客服中心')], limit=1) role_template_a = self.env['planning.slot.template'].search([('planning_name', '=', '白班'), ('role_id', '=', role_a.id)]) role_template_b = self.env['planning.slot.template'].search([('planning_name', '=', '值班'), ('role_id', '=', role_a.id)]) current_date = start_date - while current_date <= end_date: + while current_date < end_date: day_of_week = current_date.weekday() if day_of_week < 6: if day_of_week < 5: @@ -70,6 +84,9 @@ class YuthonCustomerPlanning(models.Model): 'end_datetime': end_time, 'allocated_hours': 8, }) + def _get_default_month(self): + current_month = datetime.now().month + return str(current_month) # 返回字符串类型的月份 class CustomerPlanLine(models.Model): _name = 'customer.plan.line' diff --git a/yuthon_hr_attendance/views/yuthon_customer_planning_views.xml b/yuthon_hr_attendance/views/yuthon_customer_planning_views.xml index 7cd37c7c6..7d82f2f12 100644 --- a/yuthon_hr_attendance/views/yuthon_customer_planning_views.xml +++ b/yuthon_hr_attendance/views/yuthon_customer_planning_views.xml @@ -46,7 +46,7 @@ + domain="[('department_id.name', '=', '客户部')]"/>