Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/销售订单和工单逾期消息推送
# Conflicts: # sf_message/__manifest__.py # sf_message/data/bussiness_node.xml
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
<field name="name">工单已下发通知</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
</record>
|
||||
|
||||
<record id="bussiness_mrp_workorder_pre_overdue_warning" model="jikimo.message.bussiness.node">
|
||||
<field name="name">装夹预调工单逾期预警</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
@@ -85,5 +86,6 @@
|
||||
<field name="name">表面工艺工单已逾期</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -9,10 +9,7 @@ class SFMessagefunctionalToolAssembly(models.Model):
|
||||
@api.model_create_multi
|
||||
def create(self, vals):
|
||||
result = super(SFMessagefunctionalToolAssembly, self).create(vals)
|
||||
is_cam = False
|
||||
for obj in result:
|
||||
if obj.loading_task_source == '0' and obj.assemble_status == '0':
|
||||
is_cam = True
|
||||
if is_cam:
|
||||
self.add_queue('功能刀具组装')
|
||||
obj.add_queue('功能刀具组装')
|
||||
return result
|
||||
|
||||
@@ -8,11 +8,12 @@ class SFMessagefunctionalToolDismantle(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
# 判断是否为web页面创建请求
|
||||
is_web_request = self.env.context.get('is_web_request', False)
|
||||
result = super(SFMessagefunctionalToolDismantle, self).create(vals)
|
||||
is_dismantle = False
|
||||
if is_web_request:
|
||||
return result
|
||||
for obj in result:
|
||||
if obj.dismantle_cause in ['寿命到期报废', '崩刀报废']and obj.state=='待拆解':
|
||||
is_dismantle = True
|
||||
if is_dismantle:
|
||||
self.add_queue('功能刀具寿命到期')
|
||||
if obj.dismantle_cause in ['寿命到期报废', '崩刀报废'] and obj.state == '待拆解':
|
||||
obj.add_queue('功能刀具寿命到期')
|
||||
return result
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
import logging
|
||||
from odoo import models, fields, api, _
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
class SFMessagePurchase(models.Model):
|
||||
_name = 'purchase.order'
|
||||
_inherit = ['purchase.order', 'jikimo.message.dispatch']
|
||||
_inherit = ['purchase.order', 'jikimo.message.dispatch']
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
res = super(SFMessagePurchase, self).create(vals_list)
|
||||
if res:
|
||||
try:
|
||||
res.add_queue('坯料采购提醒')
|
||||
except Exception as e:
|
||||
logging.info('add_queue error:%s' % e)
|
||||
return res
|
||||
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
|
||||
url = self.request_url(int(message_queue_id.res_id))
|
||||
purchase_order_line = self.env['purchase.order'].search([('id', '=', int(message_queue_id.res_id))])
|
||||
content = content.replace('{{name}}', purchase_order_line.name).replace(
|
||||
'{{request_url}}', url)
|
||||
contents.append(content)
|
||||
return contents
|
||||
|
||||
def request_url(self, id):
|
||||
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('purchase.purchase_form_action').id
|
||||
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_website_payment')]).id
|
||||
# 查询参数
|
||||
params = {'id': id, 'menu_id': menu_id, 'action': action_id,
|
||||
'model': 'purchase.order',
|
||||
'view_type': 'form'}
|
||||
# 拼接查询参数
|
||||
query_string = urlencode(params)
|
||||
# 拼接URL
|
||||
full_url = full_url + "web#" + query_string
|
||||
return full_url
|
||||
|
||||
@@ -23,6 +23,18 @@ class SFMessageSale(models.Model):
|
||||
if res is True:
|
||||
try:
|
||||
self.add_queue('确认接单')
|
||||
picking_ids = self.mrp_production_ids
|
||||
purchase_order_id = []
|
||||
if picking_ids:
|
||||
for picking_id in picking_ids:
|
||||
purchase_order_ids = (
|
||||
picking_id.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id |
|
||||
picking_id.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id).ids
|
||||
purchase_order_id.extend(purchase_order_ids)
|
||||
if purchase_order_id:
|
||||
purchase_order_list = self.env['purchase.order'].search([('id', 'in', purchase_order_id)])
|
||||
for purchase_order_info in purchase_order_list:
|
||||
purchase_order_info.add_queue('坯料采购提醒')
|
||||
except Exception as e:
|
||||
logging.info('add_queue error:%s' % e)
|
||||
return res
|
||||
|
||||
@@ -1,13 +1,67 @@
|
||||
import re
|
||||
from odoo import models, fields, api, _
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
class SFMessageStockPicking(models.Model):
|
||||
_name = 'stock.picking'
|
||||
_description = "库存调拨"
|
||||
_inherit = ['stock.picking', 'jikimo.message.dispatch']
|
||||
_inherit = ['stock.picking', 'jikimo.message.dispatch']
|
||||
|
||||
def button_validate(self):
|
||||
res = super(SFMessageStockPicking, self).button_validate()
|
||||
if self.location_id.name == '进货' and self.location_dest_id.name == '刀具房':
|
||||
self.add_queue('调拨入库')
|
||||
return res
|
||||
@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('调拨入库')
|
||||
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.check_in == 'PC':
|
||||
record.add_queue('坯料发料提醒')
|
||||
|
||||
def _get_message(self, message_queue_ids):
|
||||
contents = []
|
||||
product_id = []
|
||||
for message_queue_id in message_queue_ids:
|
||||
i = 0
|
||||
if message_queue_id.message_template_id.name == '坯料发料提醒':
|
||||
content = message_queue_id.message_template_id.content
|
||||
stock_picking_line = self.env['stock.picking'].search([('id', '=', int(message_queue_id.res_id))])
|
||||
mrp_production_info = self.env['mrp.production'].search(
|
||||
[('name', '=', stock_picking_line.origin)])
|
||||
mrp_production_list = self.env['mrp.production'].search(
|
||||
[('product_id', '=', mrp_production_info.product_id.id)])
|
||||
for mrp_production_line in mrp_production_list:
|
||||
picking_ids = mrp_production_line.picking_ids
|
||||
for picking_id in picking_ids:
|
||||
if picking_id.state == 'assigned' and picking_id.check_in == 'PC':
|
||||
i += 1
|
||||
if i > 0 and mrp_production_info.product_id.id not in product_id:
|
||||
url = self.request_url()
|
||||
content = content.replace('{{product_id}}', mrp_production_info.product_id.name).replace(
|
||||
'{{number}}', str(i)).replace('{{request_url}}', url)
|
||||
product_id.append(mrp_production_info.product_id.id)
|
||||
contents.append(content)
|
||||
return contents
|
||||
else:
|
||||
res = super(SFMessageStockPicking, self)._get_message(message_queue_id)
|
||||
return res
|
||||
|
||||
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('stock.stock_picking_type_action').id
|
||||
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_theme_treehouse')]).id
|
||||
# 查询参数
|
||||
params = {'menu_id': menu_id, 'action': action_id, 'model': 'stock.picking',
|
||||
'view_type': 'kanban'}
|
||||
# 拼接查询参数
|
||||
query_string = urlencode(params)
|
||||
# 拼接URL
|
||||
full_url = full_url + "web#" + query_string
|
||||
return full_url
|
||||
|
||||
@@ -13,4 +13,5 @@ class SfMessageTemplate(models.Model):
|
||||
res.append('sf.functional.tool.assembly')
|
||||
res.append('sf.functional.tool.dismantle')
|
||||
res.append('purchase.order')
|
||||
res.append('mrp.workorder')
|
||||
return res
|
||||
|
||||
@@ -1,6 +1,77 @@
|
||||
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']
|
||||
_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
|
||||
|
||||
@api.depends('cnc_ids.tool_state')
|
||||
def _compute_tool_state(self):
|
||||
# 将self的id与tool_state进行保存
|
||||
tool_state_dict = {record.id: record.tool_state for record in self}
|
||||
res = super(SFMessageWork, self)._compute_tool_state()
|
||||
data = {'name': []}
|
||||
for record in self:
|
||||
if tool_state_dict[record.id] != '2' and record.tool_state == '2':
|
||||
data['name'].append(record.production_id.programming_no)
|
||||
|
||||
if data['name']:
|
||||
# 请求cloud接口,发送微信消息推送
|
||||
configsettings = self.env['res.config.settings'].get_values()
|
||||
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
|
||||
url = '/api/message/invalid_tool_state'
|
||||
config_url = configsettings['sf_url'] + url
|
||||
data['token'] = configsettings['token']
|
||||
ret = requests.post(config_url, json=data, headers=config_header)
|
||||
ret = ret.json()
|
||||
_logger.info('无效用刀异常消息推送接口:%s' % ret)
|
||||
return res
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user