消息提醒

This commit is contained in:
guanhuan
2024-12-19 14:36:16 +08:00
parent 5eda4427df
commit 72bf8ad011
7 changed files with 84 additions and 77 deletions

View File

@@ -9,6 +9,7 @@ from odoo.addons.sf_base.commons.common import Common
_logger = logging.getLogger(__name__)
class MessageSfMrsConnect(Sf_Mrs_Connect):
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
@@ -38,9 +39,16 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
_logger.info('无效用刀异常消息推送接口:%s' % ret)
except Exception as e:
_logger.info('无效用刀异常消息推送接口:%s' % e)
try:
productions = request.env['mrp.production'].sudo().search([('id', '=', res.get('production_ids')[0])])
productions.add_queue('工单已下发通知')
except Exception as e:
_logger.info('工单已下发通知异常:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/api/maintenance_logs/notify', type='json', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
@http.route('/api/maintenance_logs/notify', type='json', auth='public', methods=['GET', 'POST'], csrf=False,
cors="*")
def maintenance_logs_notify(self, **kw):
res = {'code': 200, 'message': '设备故障日志信息推送成功'}
datas = request.httprequest.data
@@ -52,7 +60,8 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
try:
if not isinstance(log_id, list):
log_id = [log_id]
maintenance_logs = request.env['sf.maintenance.logs'].sudo().search([('id', 'in', [int(id) for id in log_id])])
maintenance_logs = request.env['sf.maintenance.logs'].sudo().search(
[('id', 'in', [int(id) for id in log_id])])
if maintenance_logs:
maintenance_logs.add_queue('设备故障')
except Exception as e:

View File

@@ -56,7 +56,7 @@
<!--工单-->
<record id="bussiness_mrp_workorder_remind" model="jikimo.message.bussiness.node">
<field name="name">工单已下发通知</field>
<field name="model">mrp.workorder</field>
<field name="model">mrp.production</field>
</record>
<!--发货调拨-->
<record id="production_completed_warehouse_reminder" model="jikimo.message.bussiness.node">

View File

@@ -78,8 +78,8 @@
<record id="template_mrp_workorder_remind" model="jikimo.message.template">
<field name="name">工单已下发通知</field>
<field name="model_id" ref="mrp_workorder.model_mrp_workorder"/>
<field name="model">mrp.workorder</field>
<field name="model_id" ref="mrp.model_mrp_production"/>
<field name="model">mrp.production</field>
<field name="bussiness_node_id" ref="bussiness_mrp_workorder_remind"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>

View File

@@ -14,15 +14,18 @@ class SFMessageMrpProduction(models.Model):
'workorder_ids.state', 'product_qty', 'qty_producing')
def _compute_state(self):
super(SFMessageMrpProduction, self)._compute_state()
for record in self:
if record.state in ['scrap', 'done']:
# 查询制造订单下的所有未完成的生产订单
mrp_production = record.env['mrp.production'].search(
[('origin', '=', record.origin), ('state', 'not in', ['scrap', 'done'])])
if not mrp_production:
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
if not mrp_production_queue:
record.add_queue('生产完工入库提醒')
try:
for record in self:
if record.state in ['scrap', 'done']:
# 查询制造订单下的所有未完成的生产订单
mrp_production = record.env['mrp.production'].search(
[('origin', '=', record.origin), ('state', 'not in', ['scrap', 'done'])])
if not mrp_production:
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
if not mrp_production_queue:
record.add_queue('生产完工入库提醒')
except Exception as e:
logging.info('add_queue生产完工入库提醒 error:%s' % e)
# 获取发送消息内容
def _get_message(self, message_queue_ids):
@@ -66,6 +69,17 @@ class SFMessageMrpProduction(models.Model):
url_with_id).replace(
'{{num}}', str(stock_picking_num))
contents.append(content)
if message_queue_id.message_template_id.name == '工单已下发通知':
content = message_queue_id.message_template_id.content
mrp_production = self.env['mrp.production'].sudo().search([('id', '=', int(message_queue_id.res_id))])
production_num = self.env['mrp.production'].sudo().search_count(
[('product_id', '=', mrp_production.product_id.id)])
if production_num >= 1:
url = self.get_request_url()
content = content.replace('{{product_id}}', mrp_production.product_id.name).replace(
'{{number}}', str(production_num)).replace(
'{{request_url}}', url)
contents.append(content)
if unique_products:
unique_products_contents = self.get_production_info(content, unique_products, 'confirmed',
'sf_plan.sf_production_plan_action1')
@@ -106,3 +120,17 @@ class SFMessageMrpProduction(models.Model):
# 拼接URL
full_url = url + "/web#" + query_string
return full_url
def get_request_url(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('sf_message.mrp_workorder_issued_action').id
menu_id = self.env['ir.model.data'].sudo().search([('name', '=', 'module_stock_dropshipping')]).id
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', '工件装夹中心')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
'view_type': 'list', 'active_id': active_id}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url

View File

@@ -12,36 +12,43 @@ class SFMessageStockPicking(models.Model):
@api.model_create_multi
def create(self, vals):
result = super(SFMessageStockPicking, self).create(vals)
for obj in result:
if obj.location_id.name == '进货' and obj.location_dest_id.name == '刀具房':
obj.add_queue('调拨入库')
try:
for obj in result:
if obj.location_id.name == '进货' and obj.location_dest_id.name == '刀具房':
obj.add_queue('调拨入库')
except Exception as e:
logging.info('add_queue调拨入库 error:%s' % e)
return result
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
def _compute_state(self):
super(SFMessageStockPicking, self)._compute_state()
for record in self:
if record.state == 'assigned' and record.picking_type_id.sequence_code == 'PC':
record.add_queue('坯料发料提醒')
try:
for record in self:
if record.state == 'assigned' and record.picking_type_id.sequence_code == 'PC':
record.add_queue('坯料发料提醒')
if record.picking_type_id.sequence_code == 'SFP' and record.state == 'done':
stock_picking_sfp = record.env['stock.picking'].search(
[('origin', '=', record.origin), ('state', '!=', 'done'),
('picking_type_id.sequence_code', '=', 'SFP')])
if not stock_picking_sfp:
stock_picking_send = self.env["jikimo.message.queue"].sudo().search([('res_id', '=', record.id)])
if not stock_picking_send:
record.add_queue('订单发货提醒')
if record.picking_type_id.sequence_code == 'OCOUT' and record.state == 'assigned':
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', record.origin)])
production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', mrp_production.product_id.id)])
manufacturing_order_names = production_list.mapped('name')
stock_picking_list = self.env['stock.picking'].sudo().search(
[('origin', 'in', manufacturing_order_names), ('picking_type_id.sequence_code', '=', 'OCOUT')])
all_ready_or_done = all(picking.state in ['assigned', 'done'] for picking in stock_picking_list)
if all_ready_or_done:
mrp_production.add_queue('工序外协发料通知')
if record.picking_type_id.sequence_code == 'SFP' and record.state == 'done':
stock_picking_sfp = record.env['stock.picking'].search(
[('origin', '=', record.origin), ('state', '!=', 'done'),
('picking_type_id.sequence_code', '=', 'SFP')])
if not stock_picking_sfp:
stock_picking_send = self.env["jikimo.message.queue"].sudo().search(
[('res_id', '=', record.id)])
if not stock_picking_send:
record.add_queue('订单发货提醒')
if record.picking_type_id.sequence_code == 'OCOUT' and record.state == 'assigned':
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', record.origin)])
production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', mrp_production.product_id.id)])
manufacturing_order_names = production_list.mapped('name')
stock_picking_list = self.env['stock.picking'].sudo().search(
[('origin', 'in', manufacturing_order_names), ('picking_type_id.sequence_code', '=', 'OCOUT')])
all_ready_or_done = all(picking.state in ['assigned', 'done'] for picking in stock_picking_list)
if all_ready_or_done:
mrp_production.add_queue('工序外协发料通知')
except Exception as e:
logging.info('add_queue_compute_state error:%s' % e)
def deal_stock_picking_sfp(self, message_queue_id): # 处理订单发货提醒
content = None

View File

@@ -16,4 +16,5 @@ class SfMessageTemplate(models.Model):
res.append('mrp.workorder')
res.append('sf.maintenance.logs')
res.append('quality.cnc.test')
res.append('mrp.production')
return res

View File

@@ -12,19 +12,8 @@ class SFMessageWork(models.Model):
_name = 'mrp.workorder'
_inherit = ['mrp.workorder', 'jikimo.message.dispatch']
@api.depends('production_availability', 'blocked_by_workorder_ids.state', 'production_id.tool_state')
def _compute_state(self):
super(SFMessageWork, self)._compute_state()
for workorder in self:
if workorder.state == 'ready' and workorder.routing_type == '装夹预调':
jikimo_message_queue = self.env['jikimo.message.queue'].sudo().search(
[('res_id', '=', workorder.id), ("message_status", "=", "pending")])
if not jikimo_message_queue:
workorder.add_queue('工单已下发通知')
def _get_message(self, message_queue_ids):
contents = []
product_id = []
bussiness_node = None
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@@ -37,20 +26,7 @@ class SFMessageWork(models.Model):
}
i = 0
for message_queue_id in message_queue_ids:
if message_queue_id.message_template_id.name == '工单已下发通知':
content = message_queue_id.message_template_id.content
mrp_workorder_line = self.env['mrp.workorder'].sudo().search([('id', '=', int(message_queue_id.res_id))])
mrp_workorder_list = self.env['mrp.workorder'].sudo().search(
[('product_id', '=', mrp_workorder_line.product_id.id), ('state', '=', 'ready'),
('routing_type', '=', '装夹预调')])
if len(mrp_workorder_list) > 0 and mrp_workorder_line.product_id.id not in product_id:
url = self.request_url()
content = content.replace('{{product_id}}', mrp_workorder_line.product_id.name).replace(
'{{number}}', str(len(mrp_workorder_list))).replace(
'{{request_url}}', url)
product_id.append(mrp_workorder_line.product_id.id)
contents.append(content)
elif message_queue_id.message_template_id.name in template_names['预警'] + template_names['已逾期']:
if message_queue_id.message_template_id.name in template_names['预警'] + template_names['已逾期']:
item = message_queue_id.message_template_id
bussiness_node = item.bussiness_node_id.name
for reminder_time in item.reminder_time_ids:
@@ -95,20 +71,6 @@ class SFMessageWork(models.Model):
contents.append(content)
return contents
def request_url(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('sf_message.mrp_workorder_issued_action').id
menu_id = self.env['ir.model.data'].sudo().search([('name', '=', 'module_stock_dropshipping')]).id
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', '工件装夹中心')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
'view_type': 'list', 'active_id': active_id}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url
def _overdue_or_warning_func(self):
workorders = self.env['mrp.workorder'].search(
[("state", "in", ["ready", "progress", "to be detected"]), ('schedule_state', '=', '已排')])