优化定时器代码
This commit is contained in:
@@ -9,8 +9,8 @@ from odoo.exceptions import ValidationError, UserError
|
|||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
from OCC.Extend.DataExchange import read_step_file
|
# from OCC.Extend.DataExchange import read_step_file
|
||||||
from OCC.Extend.DataExchange import write_stl_file
|
# from OCC.Extend.DataExchange import write_stl_file
|
||||||
|
|
||||||
|
|
||||||
class ResProductMo(models.Model):
|
class ResProductMo(models.Model):
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ class SFMessageMaintenanceLogs(models.Model):
|
|||||||
_name = 'sf.maintenance.logs'
|
_name = 'sf.maintenance.logs'
|
||||||
_inherit = ['sf.maintenance.logs', 'jikimo.message.dispatch']
|
_inherit = ['sf.maintenance.logs', 'jikimo.message.dispatch']
|
||||||
|
|
||||||
@api._model_create_multi
|
# @api._model_create_multi
|
||||||
def create(self, vals_list):
|
# def create(self, vals_list):
|
||||||
res = super(SFMessageMaintenanceLogs, self).create(vals_list)
|
# res = super(SFMessageMaintenanceLogs, self).create(vals_list)
|
||||||
for rec in res:
|
# for rec in res:
|
||||||
rec.add_queue()
|
# rec.add_queue()
|
||||||
return res
|
# return res
|
||||||
|
|
||||||
def _get_message(self, message_queue_ids):
|
def _get_message(self, message_queue_ids):
|
||||||
contents = super(SFMessageMaintenanceLogs, self)._get_message(message_queue_ids)
|
contents = super(SFMessageMaintenanceLogs, self)._get_message(message_queue_ids)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class SFMessageSale(models.Model):
|
|||||||
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
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)
|
current_time = self.env['sf.sync.common'].sudo().get_add_time(current_time_strf)
|
||||||
current_time_datetime = datetime.strptime(current_time, '%Y-%m-%d %H:%M:%S')
|
current_time_datetime = datetime.strptime(current_time, '%Y-%m-%d %H:%M:%S')
|
||||||
time_range = timedelta(minutes=2)
|
time_range = timedelta(minutes=30)
|
||||||
i = 0
|
i = 0
|
||||||
for item in message_queue_ids:
|
for item in message_queue_ids:
|
||||||
if item.message_template_id.bussiness_node_id.name == '待接单':
|
if item.message_template_id.bussiness_node_id.name == '待接单':
|
||||||
@@ -109,33 +109,36 @@ class SFMessageSale(models.Model):
|
|||||||
production_not_done = production.filtered(lambda p: p.state not in ['done', 'scrap', 'cancel'])
|
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']))
|
production_done_count = len(production.filtered(lambda p: p.state in ['done', 'scrap', 'cancel']))
|
||||||
if len(production_not_done) != item.mrp_production_count:
|
if len(production_not_done) != item.mrp_production_count:
|
||||||
if deadline_check == item.deadline_of_delivery:
|
if deadline_check == item.deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||||
item.delivery_warning = 'warning'
|
item.delivery_warning = 'warning'
|
||||||
elif today == item.deadline_of_delivery:
|
elif today == item.deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||||
item.delivery_warning = 'overdue'
|
item.delivery_warning = 'overdue'
|
||||||
elif production_done_count == item.mrp_production_count:
|
elif production_done_count == item.mrp_production_count:
|
||||||
if item.delivery_status in ['pending', 'partial']:
|
if item.delivery_status in ['pending', 'partial']:
|
||||||
if deadline_check == item.deadline_of_delivery:
|
if deadline_check == item.deadline_of_delivery and item.delivery_warning not in ['warning']:
|
||||||
item.delivery_warning = 'warning'
|
item.delivery_warning = 'warning'
|
||||||
elif today == item.deadline_of_delivery:
|
elif today == item.deadline_of_delivery and item.delivery_warning not in ['overdue']:
|
||||||
item.delivery_warning = 'overdue'
|
item.delivery_warning = 'overdue'
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
# 获取业务节点
|
||||||
|
business_node_ids = {
|
||||||
|
'warning': self.env.ref('sf_message.bussiness_sale_order_overdue_warning').id,
|
||||||
|
'overdue': self.env.ref('sf_message.bussiness_sale_order_overdue').id
|
||||||
|
}
|
||||||
overdue_orders = self.sudo().search([('delivery_warning', 'in', ['warning', 'overdue'])])
|
overdue_orders = self.sudo().search([('delivery_warning', 'in', ['warning', 'overdue'])])
|
||||||
for wo in overdue_orders:
|
for wo in overdue_orders:
|
||||||
message_template = self.env["jikimo.message.template"].search([
|
business_node_id = business_node_ids.get(wo.delivery_warning)
|
||||||
("model", "=", self._name),
|
if business_node_id:
|
||||||
("bussiness_node_id", "=", self.env.ref('sf_message.bussiness_sale_order_overdue_warning').id)
|
message_template = self.env["jikimo.message.template"].search([
|
||||||
])
|
("model", "=", self._name),
|
||||||
sale_order_has = self.env['jikimo.message.queue'].search([
|
("bussiness_node_id", "=", business_node_id)
|
||||||
('res_id', '=', wo.id),
|
], limit=1)
|
||||||
('message_status', '=', 'pending'),
|
sale_order_has = self.env['jikimo.message.queue'].search([
|
||||||
('message_template_id', '=', message_template.id)
|
('res_id', '=', wo.id),
|
||||||
])
|
('message_status', '=', 'pending'),
|
||||||
if not sale_order_has:
|
('message_template_id', '=', message_template.id)
|
||||||
if wo.delivery_warning == 'warning':
|
])
|
||||||
wo.add_queue('销售订单逾期预警')
|
if not sale_order_has:
|
||||||
elif wo.delivery_warning == 'overdue':
|
message_name = '销售订单逾期预警' if wo.delivery_warning == 'warning' else '销售订单已逾期'
|
||||||
wo.add_queue('销售订单已逾期')
|
wo.add_queue(message_name)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -115,12 +115,13 @@ class SFMessageWork(models.Model):
|
|||||||
item.date_planned_finished.strftime("%Y-%m-%d %H:%M:%S"))
|
item.date_planned_finished.strftime("%Y-%m-%d %H:%M:%S"))
|
||||||
date_planned_finished = datetime.strptime(date_planned_finished_str, '%Y-%m-%d %H:%M:%S')
|
date_planned_finished = datetime.strptime(date_planned_finished_str, '%Y-%m-%d %H:%M:%S')
|
||||||
twelve_hours_ago = current_time_datetime - timedelta(hours=12)
|
twelve_hours_ago = current_time_datetime - timedelta(hours=12)
|
||||||
if current_time_datetime >= date_planned_finished:
|
if current_time_datetime >= date_planned_finished and item.delivery_warning not in ['overdue']:
|
||||||
logging.info("------overdue-------")
|
logging.info("------overdue-------")
|
||||||
logging.info(f"Workorder: {item.production_id.name}, Current Time: {current_time_datetime}, "
|
logging.info(f"Workorder: {item.production_id.name}, Current Time: {current_time_datetime}, "
|
||||||
f"Planned Finish: {date_planned_finished}")
|
f"Planned Finish: {date_planned_finished}")
|
||||||
item.delivery_warning = 'overdue'
|
item.delivery_warning = 'overdue'
|
||||||
elif twelve_hours_ago <= current_time_datetime <= date_planned_finished:
|
elif twelve_hours_ago <= current_time_datetime <= date_planned_finished and item.delivery_warning not in [
|
||||||
|
'warning']:
|
||||||
logging.info("------warning-------")
|
logging.info("------warning-------")
|
||||||
logging.info(f"Workorder: {item.production_id.name}, Current Time: {current_time_datetime}, "
|
logging.info(f"Workorder: {item.production_id.name}, Current Time: {current_time_datetime}, "
|
||||||
f"Planned Finish: {date_planned_finished}")
|
f"Planned Finish: {date_planned_finished}")
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ from datetime import datetime
|
|||||||
import requests
|
import requests
|
||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
from OCC.Extend.DataExchange import read_step_file
|
# from OCC.Extend.DataExchange import read_step_file
|
||||||
from OCC.Extend.DataExchange import write_stl_file
|
# from OCC.Extend.DataExchange import write_stl_file
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
from odoo.exceptions import ValidationError, UserError
|
from odoo.exceptions import ValidationError, UserError
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import os
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from stl import mesh
|
from stl import mesh
|
||||||
# from OCC.Core.GProp import GProp_GProps
|
# from OCC.Core.GProp import GProp_GProps
|
||||||
from OCC.Extend.DataExchange import read_step_file
|
# from OCC.Extend.DataExchange import read_step_file
|
||||||
from OCC.Extend.DataExchange import write_stl_file
|
# from OCC.Extend.DataExchange import write_stl_file
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
<attribute name="attrs">{'readonly': [('state', 'in', ['cancel','sale'])]}</attribute>
|
<attribute name="attrs">{'readonly': [('state', 'in', ['cancel','sale'])]}</attribute>
|
||||||
</field>
|
</field>
|
||||||
<field name="payment_term_id" position="after">
|
<field name="payment_term_id" position="after">
|
||||||
<field name="deadline_of_delivery" readonly="1"/>
|
<field name="deadline_of_delivery" readonly="0"/>
|
||||||
<field name="payments_way" attrs="{'readonly': [('state', 'in', ('sale','cancel'))]}"/>
|
<field name="payments_way" attrs="{'readonly': [('state', 'in', ('sale','cancel'))]}"/>
|
||||||
<field name="pay_way" attrs="{'readonly': [('state', 'in', ('sale','cancel'))]}"/>
|
<field name="pay_way" attrs="{'readonly': [('state', 'in', ('sale','cancel'))]}"/>
|
||||||
<!-- <field name="schedule_status" readonly="1"/> -->
|
<!-- <field name="schedule_status" readonly="1"/> -->
|
||||||
|
|||||||
Reference in New Issue
Block a user