Files
gzth/yuthon_hr_attendance/wizard/customer_create_wizard.py
T
2026-04-23 11:41:31 +08:00

49 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
import calendar
from odoo import models, api, fields, _
from odoo.tools.float_utils import float_round
from odoo.exceptions import ValidationError, UserError
from datetime import date
from datetime import timedelta
from datetime import datetime, time
class CustomerCreateWizard(models.TransientModel):
_name = 'customer.create.wizard'
_description = '客服排班生成弹窗'
select_month = fields.Selection([('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
('9', '九月'), ('10', '十月'), ('11', '十一月'),
('12', '十二月')], string='月份',
default=lambda self: str(datetime.now().month))
select_year = fields.Selection(selection=[(str(i), str(i)) for i in range(2026, 2060)], string='年份',
default=lambda self: str(datetime.now().year))
def create_customer(self):
year = int(self.select_year)
month = int(self.select_month)
saturdays = []
current_date = datetime(year, month, 1)
if month == 12:
next_month = datetime(year + 1, 1, 1)
else:
next_month = datetime(year, month + 1, 1)
last_day = next_month - timedelta(days=1)
while current_date <= last_day:
if current_date.weekday() == 5:
saturdays.append(current_date.strftime('%Y-%m-%d'))
current_date += timedelta(days=1)
# 3. 批量创建值班计划
planning_vals_list = []
for date in saturdays:
planning_vals_list.append({
'date': date,
})
if planning_vals_list:
self.env['yuthon.customer.planning'].create(planning_vals_list)