63 lines
3.5 KiB
Python
63 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, fields, api, _
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
class SFMessageProduct(models.Model):
|
|
_name = 'product.product'
|
|
_inherit = ['product.product', 'jikimo.message.dispatch']
|
|
|
|
def _get_message(self, message_queue_ids):
|
|
contents = []
|
|
for message_queue_id in message_queue_ids:
|
|
if message_queue_id.message_template_id.name == '工单已下发通知':
|
|
content = message_queue_id.message_template_id.content
|
|
product_product = self.env['product.product'].sudo().search([('id', '=', int(message_queue_id.res_id))])
|
|
mrp_production_list = self.env['mrp.production'].sudo().search(
|
|
[('product_id', '=', product_product.id)])
|
|
production_num = 0
|
|
routing_type = None
|
|
for mrp_production_info in mrp_production_list:
|
|
routing_type = '人工线下加工' if mrp_production_info.production_type == '人工线下加工' else '装夹预调'
|
|
mrp_production_ready = mrp_production_info.workorder_ids.filtered(
|
|
lambda w: w.routing_type == routing_type and w.state == 'ready')
|
|
if mrp_production_ready:
|
|
production_num += 1
|
|
if production_num >= 1:
|
|
url = self.get_request_url(routing_type)
|
|
content = content.replace('{{product_id}}', product_product.name).replace(
|
|
'{{number}}', str(production_num)).replace(
|
|
'{{request_url}}', url)
|
|
contents.append(content)
|
|
if message_queue_id.message_template_id.name == '待质检提醒':
|
|
content = message_queue_id.message_template_id.content
|
|
product_product = self.env['product.product'].sudo().search([('id', '=', int(message_queue_id.res_id))])
|
|
quality_check_num = self.env['quality.check'].sudo().search_count(
|
|
[('product_id', '=', product_product.id), ('quality_state', '=', 'none')])
|
|
if quality_check_num >= 1:
|
|
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
|
action_id = self.env.ref('quality_control.quality_check_action_report').id
|
|
url_with_id = f"{url}/web#view_type=list&action={action_id}"
|
|
content = content.replace('{{name}}', product_product.name).replace('{{url}}', url_with_id).replace(
|
|
'{{num}}', str(quality_check_num))
|
|
contents.append(content)
|
|
return contents, message_queue_ids
|
|
|
|
def get_request_url(self, routing_type):
|
|
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.ref('mrp.menu_mrp_root').id
|
|
if routing_type == '人工线下加工':
|
|
routing_name = '线下工作中心'
|
|
else:
|
|
routing_name = '工件装夹中心'
|
|
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', routing_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
|