消息提醒
This commit is contained in:
@@ -9,6 +9,7 @@ from odoo.addons.sf_base.commons.common import Common
|
|||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MessageSfMrsConnect(Sf_Mrs_Connect):
|
class MessageSfMrsConnect(Sf_Mrs_Connect):
|
||||||
|
|
||||||
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
@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)
|
_logger.info('无效用刀异常消息推送接口:%s' % ret)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.info('无效用刀异常消息推送接口:%s' % 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)
|
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):
|
def maintenance_logs_notify(self, **kw):
|
||||||
res = {'code': 200, 'message': '设备故障日志信息推送成功'}
|
res = {'code': 200, 'message': '设备故障日志信息推送成功'}
|
||||||
datas = request.httprequest.data
|
datas = request.httprequest.data
|
||||||
@@ -52,7 +60,8 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
|
|||||||
try:
|
try:
|
||||||
if not isinstance(log_id, list):
|
if not isinstance(log_id, list):
|
||||||
log_id = [log_id]
|
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:
|
if maintenance_logs:
|
||||||
maintenance_logs.add_queue('设备故障')
|
maintenance_logs.add_queue('设备故障')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<!--工单-->
|
<!--工单-->
|
||||||
<record id="bussiness_mrp_workorder_remind" model="jikimo.message.bussiness.node">
|
<record id="bussiness_mrp_workorder_remind" model="jikimo.message.bussiness.node">
|
||||||
<field name="name">工单已下发通知</field>
|
<field name="name">工单已下发通知</field>
|
||||||
<field name="model">mrp.workorder</field>
|
<field name="model">mrp.production</field>
|
||||||
</record>
|
</record>
|
||||||
<!--发货调拨-->
|
<!--发货调拨-->
|
||||||
<record id="production_completed_warehouse_reminder" model="jikimo.message.bussiness.node">
|
<record id="production_completed_warehouse_reminder" model="jikimo.message.bussiness.node">
|
||||||
|
|||||||
@@ -78,8 +78,8 @@
|
|||||||
|
|
||||||
<record id="template_mrp_workorder_remind" model="jikimo.message.template">
|
<record id="template_mrp_workorder_remind" model="jikimo.message.template">
|
||||||
<field name="name">工单已下发通知</field>
|
<field name="name">工单已下发通知</field>
|
||||||
<field name="model_id" ref="mrp_workorder.model_mrp_workorder"/>
|
<field name="model_id" ref="mrp.model_mrp_production"/>
|
||||||
<field name="model">mrp.workorder</field>
|
<field name="model">mrp.production</field>
|
||||||
<field name="bussiness_node_id" ref="bussiness_mrp_workorder_remind"/>
|
<field name="bussiness_node_id" ref="bussiness_mrp_workorder_remind"/>
|
||||||
<field name="msgtype">markdown</field>
|
<field name="msgtype">markdown</field>
|
||||||
<field name="urgency">normal</field>
|
<field name="urgency">normal</field>
|
||||||
|
|||||||
@@ -14,15 +14,18 @@ class SFMessageMrpProduction(models.Model):
|
|||||||
'workorder_ids.state', 'product_qty', 'qty_producing')
|
'workorder_ids.state', 'product_qty', 'qty_producing')
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
super(SFMessageMrpProduction, self)._compute_state()
|
super(SFMessageMrpProduction, self)._compute_state()
|
||||||
for record in self:
|
try:
|
||||||
if record.state in ['scrap', 'done']:
|
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'])])
|
mrp_production = record.env['mrp.production'].search(
|
||||||
if not mrp_production:
|
[('origin', '=', record.origin), ('state', 'not in', ['scrap', 'done'])])
|
||||||
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
|
if not mrp_production:
|
||||||
if not mrp_production_queue:
|
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
|
||||||
record.add_queue('生产完工入库提醒')
|
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):
|
def _get_message(self, message_queue_ids):
|
||||||
@@ -66,6 +69,17 @@ class SFMessageMrpProduction(models.Model):
|
|||||||
url_with_id).replace(
|
url_with_id).replace(
|
||||||
'{{num}}', str(stock_picking_num))
|
'{{num}}', str(stock_picking_num))
|
||||||
contents.append(content)
|
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:
|
if unique_products:
|
||||||
unique_products_contents = self.get_production_info(content, unique_products, 'confirmed',
|
unique_products_contents = self.get_production_info(content, unique_products, 'confirmed',
|
||||||
'sf_plan.sf_production_plan_action1')
|
'sf_plan.sf_production_plan_action1')
|
||||||
@@ -106,3 +120,17 @@ class SFMessageMrpProduction(models.Model):
|
|||||||
# 拼接URL
|
# 拼接URL
|
||||||
full_url = url + "/web#" + query_string
|
full_url = url + "/web#" + query_string
|
||||||
return full_url
|
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
|
||||||
|
|||||||
@@ -12,36 +12,43 @@ class SFMessageStockPicking(models.Model):
|
|||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
result = super(SFMessageStockPicking, self).create(vals)
|
result = super(SFMessageStockPicking, self).create(vals)
|
||||||
for obj in result:
|
try:
|
||||||
if obj.location_id.name == '进货' and obj.location_dest_id.name == '刀具房':
|
for obj in result:
|
||||||
obj.add_queue('调拨入库')
|
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
|
return result
|
||||||
|
|
||||||
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
|
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
super(SFMessageStockPicking, self)._compute_state()
|
super(SFMessageStockPicking, self)._compute_state()
|
||||||
for record in self:
|
try:
|
||||||
if record.state == 'assigned' and record.picking_type_id.sequence_code == 'PC':
|
for record in self:
|
||||||
record.add_queue('坯料发料提醒')
|
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':
|
if record.picking_type_id.sequence_code == 'SFP' and record.state == 'done':
|
||||||
stock_picking_sfp = record.env['stock.picking'].search(
|
stock_picking_sfp = record.env['stock.picking'].search(
|
||||||
[('origin', '=', record.origin), ('state', '!=', 'done'),
|
[('origin', '=', record.origin), ('state', '!=', 'done'),
|
||||||
('picking_type_id.sequence_code', '=', 'SFP')])
|
('picking_type_id.sequence_code', '=', 'SFP')])
|
||||||
if not stock_picking_sfp:
|
if not stock_picking_sfp:
|
||||||
stock_picking_send = self.env["jikimo.message.queue"].sudo().search([('res_id', '=', record.id)])
|
stock_picking_send = self.env["jikimo.message.queue"].sudo().search(
|
||||||
if not stock_picking_send:
|
[('res_id', '=', record.id)])
|
||||||
record.add_queue('订单发货提醒')
|
if not stock_picking_send:
|
||||||
if record.picking_type_id.sequence_code == 'OCOUT' and record.state == 'assigned':
|
record.add_queue('订单发货提醒')
|
||||||
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', record.origin)])
|
if record.picking_type_id.sequence_code == 'OCOUT' and record.state == 'assigned':
|
||||||
production_list = self.env['mrp.production'].sudo().search(
|
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', record.origin)])
|
||||||
[('product_id', '=', mrp_production.product_id.id)])
|
production_list = self.env['mrp.production'].sudo().search(
|
||||||
manufacturing_order_names = production_list.mapped('name')
|
[('product_id', '=', mrp_production.product_id.id)])
|
||||||
stock_picking_list = self.env['stock.picking'].sudo().search(
|
manufacturing_order_names = production_list.mapped('name')
|
||||||
[('origin', 'in', manufacturing_order_names), ('picking_type_id.sequence_code', '=', 'OCOUT')])
|
stock_picking_list = self.env['stock.picking'].sudo().search(
|
||||||
all_ready_or_done = all(picking.state in ['assigned', 'done'] for picking in stock_picking_list)
|
[('origin', 'in', manufacturing_order_names), ('picking_type_id.sequence_code', '=', 'OCOUT')])
|
||||||
if all_ready_or_done:
|
all_ready_or_done = all(picking.state in ['assigned', 'done'] for picking in stock_picking_list)
|
||||||
mrp_production.add_queue('工序外协发料通知')
|
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): # 处理订单发货提醒
|
def deal_stock_picking_sfp(self, message_queue_id): # 处理订单发货提醒
|
||||||
content = None
|
content = None
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ class SfMessageTemplate(models.Model):
|
|||||||
res.append('mrp.workorder')
|
res.append('mrp.workorder')
|
||||||
res.append('sf.maintenance.logs')
|
res.append('sf.maintenance.logs')
|
||||||
res.append('quality.cnc.test')
|
res.append('quality.cnc.test')
|
||||||
|
res.append('mrp.production')
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -12,19 +12,8 @@ class SFMessageWork(models.Model):
|
|||||||
_name = 'mrp.workorder'
|
_name = 'mrp.workorder'
|
||||||
_inherit = ['mrp.workorder', 'jikimo.message.dispatch']
|
_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):
|
def _get_message(self, message_queue_ids):
|
||||||
contents = []
|
contents = []
|
||||||
product_id = []
|
|
||||||
bussiness_node = None
|
bussiness_node = None
|
||||||
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||||
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
@@ -37,20 +26,7 @@ class SFMessageWork(models.Model):
|
|||||||
}
|
}
|
||||||
i = 0
|
i = 0
|
||||||
for message_queue_id in message_queue_ids:
|
for message_queue_id in message_queue_ids:
|
||||||
if message_queue_id.message_template_id.name == '工单已下发通知':
|
if message_queue_id.message_template_id.name in template_names['预警'] + template_names['已逾期']:
|
||||||
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['已逾期']:
|
|
||||||
item = message_queue_id.message_template_id
|
item = message_queue_id.message_template_id
|
||||||
bussiness_node = item.bussiness_node_id.name
|
bussiness_node = item.bussiness_node_id.name
|
||||||
for reminder_time in item.reminder_time_ids:
|
for reminder_time in item.reminder_time_ids:
|
||||||
@@ -95,20 +71,6 @@ class SFMessageWork(models.Model):
|
|||||||
contents.append(content)
|
contents.append(content)
|
||||||
return contents
|
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):
|
def _overdue_or_warning_func(self):
|
||||||
workorders = self.env['mrp.workorder'].search(
|
workorders = self.env['mrp.workorder'].search(
|
||||||
[("state", "in", ["ready", "progress", "to be detected"]), ('schedule_state', '=', '已排')])
|
[("state", "in", ["ready", "progress", "to be detected"]), ('schedule_state', '=', '已排')])
|
||||||
|
|||||||
Reference in New Issue
Block a user