56 lines
2.8 KiB
Python
56 lines
2.8 KiB
Python
from odoo import models, fields, api, _
|
|
import logging, json
|
|
import requests
|
|
from odoo.addons.sf_base.commons.common import Common
|
|
from urllib.parse import urlencode
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
class SFMessageWork(models.Model):
|
|
_name = 'mrp.workorder'
|
|
_inherit = ['mrp.workorder', 'jikimo.message.dispatch']
|
|
|
|
@api.depends('production_availability', 'blocked_by_workorder_ids.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 = []
|
|
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'].search([('id', '=', int(message_queue_id.res_id))])
|
|
mrp_workorder_list = self.env['mrp.workorder'].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)
|
|
return contents
|
|
|
|
def request_url(self):
|
|
we_config_info = self.env['we.config'].sudo().search([], limit=1)
|
|
redirect_domain = self.env['we.app'].sudo().search([('id', '=', we_config_info.odoo_app_id.id)]).redirect_domain
|
|
full_url = 'https://%s/' % redirect_domain
|
|
action_id = self.env.ref('sf_manufacturing.mrp_workorder_action_tablet').id
|
|
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_stock_dropshipping')]).id
|
|
# 查询参数
|
|
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
|
|
'view_type': 'list', 'active_id': 1}
|
|
# 拼接查询参数
|
|
query_string = urlencode(params)
|
|
# 拼接URL
|
|
full_url = full_url + "web#" + query_string
|
|
return full_url
|