修复消息提醒时区问题
This commit is contained in:
@@ -100,15 +100,22 @@ class SFMessageSale(models.Model):
|
||||
|
||||
# # 销售订单逾期预警和已逾期
|
||||
def _overdue_or_warning_func(self):
|
||||
today = datetime.today().date()
|
||||
deadline_check = today + timedelta(days=1)
|
||||
logging.info(f"today: {today}, deadline_check: {deadline_check}")
|
||||
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
current_time = self.env['sf.sync.common'].sudo().get_add_time(current_time_strf)
|
||||
today_str = datetime.strptime(current_time, '%Y-%m-%d %H:%M:%S')
|
||||
today = today_str.strftime("%Y-%m-%d")
|
||||
# 计算下一天的日期
|
||||
deadline_check_str = today_str + timedelta(days=1)
|
||||
deadline_check = deadline_check_str.strftime("%Y-%m-%d")
|
||||
logging.info(
|
||||
f"today: {today}, deadline_check: {deadline_check},current_time_strf: {current_time_strf}, current_time: {current_time}'")
|
||||
sale_order = self.sudo().search(
|
||||
[('state', 'in', ['sale']), ('deadline_of_delivery', '!=', False), ('delivery_status', '!=', 'full')])
|
||||
for item in sale_order:
|
||||
production = self.env['mrp.production'].search([('origin', '=', item.name)])
|
||||
production_not_done = production.filtered(lambda p: p.state not in ['done', 'scrap', 'cancel'])
|
||||
production_done_count = len(production.filtered(lambda p: p.state in ['done', 'scrap', 'cancel']))
|
||||
deadline_of_delivery = item.deadline_of_delivery.strftime("%Y-%m-%d")
|
||||
if (len(production_not_done) >= 1 and len(production_not_done) != item.mrp_production_count) or len(
|
||||
production_not_done) != production_done_count:
|
||||
# logging.info("-----不等于----")
|
||||
@@ -116,9 +123,9 @@ class SFMessageSale(models.Model):
|
||||
# logging.info(
|
||||
# f"production_not_done: {len(production_not_done)}, production_done_count: {production_done_count}")
|
||||
# logging.info(f"deadline_of_delivery: {item.deadline_of_delivery}")
|
||||
if deadline_check == item.deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||
if deadline_check == deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||
item.delivery_warning = 'warning'
|
||||
elif today >= item.deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||
elif today >= deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||
item.delivery_warning = 'overdue'
|
||||
elif production_done_count == item.mrp_production_count:
|
||||
# logging.info("-----等于----")
|
||||
@@ -127,9 +134,9 @@ class SFMessageSale(models.Model):
|
||||
# f"production_not_done: {len(production_not_done)}, production_done_count: {production_done_count}")
|
||||
# logging.info(f"deadline_of_delivery: {item.deadline_of_delivery}")
|
||||
if item.delivery_status in ['pending', 'partial']:
|
||||
if deadline_check == item.deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||
if deadline_check == deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||
item.delivery_warning = 'warning'
|
||||
elif today >= item.deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||
elif today >= deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||
item.delivery_warning = 'overdue'
|
||||
else:
|
||||
# logging.info("-----1111111----")
|
||||
@@ -158,6 +165,22 @@ class SFMessageSale(models.Model):
|
||||
if not sale_order_has:
|
||||
message_name = '销售订单逾期预警' if wo.delivery_warning == 'warning' else '销售订单已逾期'
|
||||
wo.add_queue(message_name)
|
||||
if wo.delivery_warning == 'overdue':
|
||||
# 把消息队列中销售订单预警的状态改为取消发送
|
||||
business_node_id_warning = business_node_ids['warning']
|
||||
if business_node_id_warning:
|
||||
message_template_warning = self.env["jikimo.message.template"].search([
|
||||
("model", "=", self._name),
|
||||
("bussiness_node_id", "=", business_node_id_warning)
|
||||
], limit=1)
|
||||
sale_order_warning = self.env['jikimo.message.queue'].search([
|
||||
('res_id', '=', wo.id),
|
||||
('message_status', '=', 'pending'),
|
||||
('message_template_id', '=', message_template_warning.id)
|
||||
])
|
||||
if sale_order_warning:
|
||||
logging.info('取消发送:%s' % sale_order_warning.name)
|
||||
sale_order_warning.write({'message_status': 'cancel'})
|
||||
|
||||
def _recover_sale_time_warning_func(self):
|
||||
sale_order_done = self.sudo().search([('state', 'in', ['sale']), ('delivery_status', '=', 'full')])
|
||||
|
||||
Reference in New Issue
Block a user