添加功能
This commit is contained in:
@@ -24,27 +24,27 @@ class YuthonHrDepartment(models.Model):
|
||||
department_code = fields.Char(string="部门序号")
|
||||
company_id = fields.Many2one('res.company', string="公司", index=True, default=lambda self: self.env.company)
|
||||
pinyin_name = fields.Char(string="拼音名称", compute='_compute_pinyin', index=True, store=True)
|
||||
is_company = fields.Boolean(string="本公司", default=True, compute='_compute_is_company', search='_search_part_of_company')
|
||||
|
||||
@api.depends_context('uid', 'company')
|
||||
@api.depends('company_id')
|
||||
def _compute_is_company(self):
|
||||
active_company_ids = self.env.companies
|
||||
for employee in self:
|
||||
employee.is_company = employee.company_id in active_company_ids
|
||||
|
||||
def _search_part_of_company(self, operator, value):
|
||||
if operator not in ('=', '!=') or not isinstance(value, bool):
|
||||
raise UserError(('Operation not supported'))
|
||||
company_ids = self.env.companies.ids # 获取公司ID列表
|
||||
# 处理反向操作符
|
||||
if not value:
|
||||
operator = '!=' if operator == '=' else '='
|
||||
# 使用company_id in company_ids的结构
|
||||
if operator == '=':
|
||||
return [('company_id', 'in', company_ids)]
|
||||
else: # operator == '!='
|
||||
return [('company_id', 'not in', company_ids)]
|
||||
# is_company = fields.Boolean(string="本公司", default=True, compute='_compute_is_company', search='_search_part_of_company')
|
||||
#
|
||||
# @api.depends_context('uid', 'company')
|
||||
# @api.depends('company_id')
|
||||
# def _compute_is_company(self):
|
||||
# active_company_ids = self.env.companies
|
||||
# for employee in self:
|
||||
# employee.is_company = employee.company_id in active_company_ids
|
||||
#
|
||||
# def _search_part_of_company(self, operator, value):
|
||||
# if operator not in ('=', '!=') or not isinstance(value, bool):
|
||||
# raise UserError(('Operation not supported'))
|
||||
# company_ids = self.env.companies.ids # 获取公司ID列表
|
||||
# # 处理反向操作符
|
||||
# if not value:
|
||||
# operator = '!=' if operator == '=' else '='
|
||||
# # 使用company_id in company_ids的结构
|
||||
# if operator == '=':
|
||||
# return [('company_id', 'in', company_ids)]
|
||||
# else: # operator == '!='
|
||||
# return [('company_id', 'not in', company_ids)]
|
||||
|
||||
@api.constrains('create_date', 'end_date')
|
||||
def _check_start_end_time(self):
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<xpath expr="//field[@name='name']" position="after">
|
||||
<field name="department_code"/>
|
||||
<field name="department_phone"/>
|
||||
<field name="is_company" optional="hide"/>
|
||||
<!-- <field name="is_company" optional="hide"/>-->
|
||||
<field name="pinyin_name" column_invisible="1"/>
|
||||
<field name="department_fax" column_invisible="1"/>
|
||||
<field name="department_location"/>
|
||||
|
||||
@@ -38,11 +38,11 @@ class PropertySplitApproval(models.Model):
|
||||
def property_split_button(self):
|
||||
if self.split_quantity < 2:
|
||||
raise UserError('拆分数量必须是大于2')
|
||||
if self.id.origin and self.property_id:
|
||||
if self.id and self.property_id:
|
||||
lines_to_create = []
|
||||
for i in range(self.split_quantity):
|
||||
lines_to_create.append({
|
||||
'property_split_approval_id': self.id.origin,
|
||||
'property_split_approval_id': self.id,
|
||||
'split_property': f"{self.property_id.name}-{i + 1}"
|
||||
})
|
||||
self.property_split_approval_line_ids.unlink()
|
||||
|
||||
@@ -12,7 +12,7 @@ class YuthonMessageApproval(models.Model):
|
||||
code = fields.Char(string="编号",
|
||||
default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_leaving_approval_code'))
|
||||
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
|
||||
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="发布部门", domain=[])
|
||||
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="发布部门")
|
||||
phone = fields.Char(related='users_id.employee_id.mobile_phone', string="联系方式")
|
||||
documents_ids = fields.Many2many('ir.attachment', string="附件")
|
||||
publish_ids = fields.Many2many('yuthon.publish.type', string="发布平台")
|
||||
|
||||
@@ -84,22 +84,6 @@ class YuthonWillTask(models.Model):
|
||||
start_date = fields.Date(string='开始日期', default=fields.Datetime.today())
|
||||
task_state = fields.Selection([('will', '待办'), ('done', '已办'), ('cancel', '取消')], default='will', string='状态', store=True)
|
||||
|
||||
@api.constrains('start_time', 'end_time')
|
||||
def _check_start_end_time(self):
|
||||
for record in self:
|
||||
if record.start_time and record.end_time and record.start_time > record.end_time:
|
||||
raise models.ValidationError("开始时间不能大于结束时间!")
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
defaults = super().default_get(fields_list)
|
||||
current_time = datetime.now()
|
||||
if current_time.time() < time(12, 0, 0):
|
||||
defaults["end_time"] = current_time.replace(hour=12, minute=0, second=0) - timedelta(hours=8)
|
||||
else:
|
||||
defaults["end_time"] = current_time.replace(hour=18, minute=0, second=0) - timedelta(hours=8)
|
||||
return defaults
|
||||
|
||||
@api.onchange('employee_ids', 'user_id')
|
||||
def _onchange_employee_ids(self):
|
||||
user_ids = []
|
||||
@@ -119,26 +103,37 @@ class YuthonWillTask(models.Model):
|
||||
return self.search_count([('state', '=', 'will'), ('users_ids', 'in', self.env.user.id)])
|
||||
|
||||
def will_task_time(self):
|
||||
for i in self.search([('task_state', '=', 'will')]):
|
||||
if datetime.now() - timedelta(hours=8) > i.end_time:
|
||||
i.write({'task_state': 'done'})
|
||||
# 任务状态判断
|
||||
for task in self.search([('task_state', '=', 'will')]):
|
||||
# 计算开始时间(将日期和时间选择转换为datetime对象)
|
||||
hour_from = float(task.request_hour_from)
|
||||
start_hour = int(hour_from)
|
||||
start_minute = int((hour_from - start_hour) * 60)
|
||||
start_datetime = datetime.combine(
|
||||
fields.Date.from_string(task.start_date),
|
||||
time(start_hour, start_minute)
|
||||
) + timedelta(hours=8)
|
||||
if task.request_hour_to:
|
||||
hour_to = float(task.request_hour_to)
|
||||
end_hour = int(hour_to)
|
||||
end_minute = int((hour_to - end_hour) * 60)
|
||||
end_datetime = start_datetime.replace(hour=end_hour, minute=end_minute)
|
||||
else:
|
||||
end_datetime = start_datetime + timedelta(hours=1)
|
||||
now = datetime.now() + timedelta(hours=8)
|
||||
start_time = task.start_time + timedelta(hours=8)
|
||||
if now > end_datetime:
|
||||
task.write({'task_state': 'done'})
|
||||
continue
|
||||
_logger.info("定时任务执行中")
|
||||
_logger.info("判断前now:{}---start:{}".format(now, start_time))
|
||||
if now <= start_time:
|
||||
_logger.info("判断后now:{}---start:{}".format(now, start_time))
|
||||
_logger.info(f"判断前 now:{now} --- start:{start_datetime}")
|
||||
if now <= start_datetime:
|
||||
if task.task_time_ids:
|
||||
for task_time in task.task_time_ids:
|
||||
duration = self._compute_duration(task_time)
|
||||
day_now = (now + duration).day
|
||||
day_start = start_time.day
|
||||
hour_now = (now + duration).hour
|
||||
hour_start = start_time.hour
|
||||
min_now = (now + duration).minute
|
||||
min_start = start_time.minute
|
||||
if day_now == day_start and hour_now == hour_start and min_now == min_start:
|
||||
trigger_time = now + duration
|
||||
if (trigger_time.day == start_datetime.day and
|
||||
trigger_time.hour == start_datetime.hour and
|
||||
trigger_time.minute == start_datetime.minute):
|
||||
task.add_comment()
|
||||
|
||||
def _compute_duration(self, task_time):
|
||||
|
||||
Reference in New Issue
Block a user