消息推送

This commit is contained in:
liaodanlong
2024-09-23 11:55:28 +08:00
parent a6701a842e
commit e7e64720c6
8 changed files with 110 additions and 57 deletions

View File

@@ -11,7 +11,7 @@
""", """,
'category': 'sf', 'category': 'sf',
'website': 'https://www.sf.jikimo.com', 'website': 'https://www.sf.jikimo.com',
'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify'], 'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify','stock'],
'data': [ 'data': [
'data/bussiness_node.xml' 'data/bussiness_node.xml'
], ],

View File

@@ -10,5 +10,17 @@
<field name="name">确认接单</field> <field name="name">确认接单</field>
<field name="model">sale.order</field> <field name="model">sale.order</field>
</record> </record>
<record id="transfer_inventory" model="jikimo.message.bussiness.node">
<field name="name">调拨入库</field>
<field name="model">stock.picking</field>
</record>
<record id="tool_assembly" model="jikimo.message.bussiness.node">
<field name="name">功能刀具组装</field>
<field name="model">sf.functional.tool.assembly</field>
</record>
<record id="tool_dismantle" model="jikimo.message.bussiness.node">
<field name="name">功能刀具寿命到期</field>
<field name="model">sf.functional.tool.dismantle</field>
</record>
</data> </data>
</odoo> </odoo>

View File

@@ -6,3 +6,4 @@ from . import sf_message_cam_program
from . import sf_message_functional_tool_assembly from . import sf_message_functional_tool_assembly
from . import sf_message_purchase from . import sf_message_purchase
from . import sf_message_workorder from . import sf_message_workorder
from . import sf_message_functional_tool_dismantle

View File

@@ -3,4 +3,16 @@ from odoo import models, fields, api, _
class SFMessagefunctionalToolAssembly(models.Model): class SFMessagefunctionalToolAssembly(models.Model):
_name = 'sf.functional.tool.assembly' _name = 'sf.functional.tool.assembly'
_description = "刀具组装单"
_inherit = ['sf.functional.tool.assembly', 'jikimo.message.dispatch'] _inherit = ['sf.functional.tool.assembly', 'jikimo.message.dispatch']
@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('功能刀具组装')
return result

View File

@@ -0,0 +1,18 @@
from odoo import models, api
class SFMessagefunctionalToolDismantle(models.Model):
_name = 'sf.functional.tool.dismantle'
_description = "刀具拆解单"
_inherit = ['sf.functional.tool.dismantle', 'jikimo.message.dispatch']
@api.model
def create(self, vals):
result = super(SFMessagefunctionalToolDismantle, self).create(vals)
is_dismantle = False
for obj in result:
if obj.dismantle_cause in ['寿命到期报废', '崩刀报废']and obj.state=='待拆解':
is_dismantle = True
if is_dismantle:
self.add_queue('功能刀具寿命到期')
return result

View File

@@ -3,4 +3,11 @@ from odoo import models, fields, api, _
class SFMessageStockPicking(models.Model): class SFMessageStockPicking(models.Model):
_name = 'stock.picking' _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

View File

@@ -9,4 +9,7 @@ class SfMessageTemplate(models.Model):
def _get_message_model(self): def _get_message_model(self):
res = super(SfMessageTemplate, self)._get_message_model() res = super(SfMessageTemplate, self)._get_message_model()
res.append("sale.order") res.append("sale.order")
res.append("stock.picking")
res.append('sf.functional.tool.assembly')
res.append('sf.functional.tool.dismantle')
return res return res

View File

@@ -31,67 +31,67 @@ class Sf_Mrs_Connect(http.Controller):
request.env.ref("base.user_admin")).search(domain) request.env.ref("base.user_admin")).search(domain)
if productions: if productions:
# 拉取所有加工面的程序文件 # 拉取所有加工面的程序文件
for r in ret['processing_panel'].split(','): # for r in ret['processing_panel'].split(','):
program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) # program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
if os.path.exists(program_path_tmp_r): # if os.path.exists(program_path_tmp_r):
files_r = os.listdir(program_path_tmp_r) # files_r = os.listdir(program_path_tmp_r)
if files_r: # if files_r:
for file_name in files_r: # for file_name in files_r:
file_path = os.path.join(program_path_tmp_r, file_name) # file_path = os.path.join(program_path_tmp_r, file_name)
os.remove(file_path) # os.remove(file_path)
download_state = request.env['sf.cnc.processing'].with_user( # download_state = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).download_file_tmp( # request.env.ref("base.user_admin")).download_file_tmp(
ret['folder_name'], r) # ret['folder_name'], r)
if download_state is False: # if download_state is False:
res['status'] = -2 # res['status'] = -2
res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) # res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
return json.JSONEncoder().encode(res) # return json.JSONEncoder().encode(res)
for production in productions: for production in productions:
if not production.workorder_ids: if not production.workorder_ids:
production.product_id.model_processing_panel = ret['processing_panel'] production.product_id.model_processing_panel = ret['processing_panel']
production._create_workorder(ret) production._create_workorder(ret)
productions.process_range_time() productions.process_range_time()
else: # else:
for panel in ret['processing_panel'].split(','): # for panel in ret['processing_panel'].split(','):
# 查询状态为进行中且工序类型为CNC加工的工单 # # 查询状态为进行中且工序类型为CNC加工的工单
cnc_workorder_has = production.workorder_ids.filtered( # cnc_workorder_has = production.workorder_ids.filtered(
lambda ach: ach.routing_type == 'CNC加工' and ach.state not in ['progress', 'done', # lambda ach: ach.routing_type == 'CNC加工' and ach.state not in ['progress', 'done',
'rework', # 'rework',
'cancel'] and ach.processing_panel == panel) # 'cancel'] and ach.processing_panel == panel)
if cnc_workorder_has: # if cnc_workorder_has:
if cnc_workorder_has.cnc_ids: # if cnc_workorder_has.cnc_ids:
cnc_workorder_has.cmm_ids.sudo().unlink() # cnc_workorder_has.cmm_ids.sudo().unlink()
cnc_workorder_has.cnc_ids.sudo().unlink() # cnc_workorder_has.cnc_ids.sudo().unlink()
request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( # request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
production) # production)
cnc_workorder_has.write( # cnc_workorder_has.write(
{'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret), # {'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret),
'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)}) # 'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)})
for panel in ret['processing_panel'].split(','): # for panel in ret['processing_panel'].split(','):
# 查询状态为进行中且工序类型为CNC加工的工单 # # 查询状态为进行中且工序类型为CNC加工的工单
cnc_workorder = productions.workorder_ids.filtered( # cnc_workorder = productions.workorder_ids.filtered(
lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework' # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework'
'cancel'] and ac.processing_panel == panel) # 'cancel'] and ac.processing_panel == panel)
if cnc_workorder: # if cnc_workorder:
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
# panel) # # panel)
program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) # program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel)
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
files_panel = os.listdir(program_path_tmp_panel) # files_panel = os.listdir(program_path_tmp_panel)
if files_panel: # if files_panel:
for file in files_panel: # for file in files_panel:
file_extension = os.path.splitext(file)[1] # file_extension = os.path.splitext(file)[1]
logging.info('file_extension:%s' % file_extension) # logging.info('file_extension:%s' % file_extension)
if file_extension.lower() == '.pdf': # if file_extension.lower() == '.pdf':
panel_file_path = os.path.join(program_path_tmp_panel, file) # panel_file_path = os.path.join(program_path_tmp_panel, file)
logging.info('panel_file_path:%s' % panel_file_path) # logging.info('panel_file_path:%s' % panel_file_path)
cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) # cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
pre_workorder = productions.workorder_ids.filtered( # pre_workorder = productions.workorder_ids.filtered(
lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework' # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework'
'cancel'] and ap.processing_panel == panel) # 'cancel'] and ap.processing_panel == panel)
if pre_workorder: # if pre_workorder:
pre_workorder.write( # pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
productions.write({'programming_state': '已编程', 'work_state': '已编程'}) productions.write({'programming_state': '已编程', 'work_state': '已编程'})
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
else: else: