Accept Merge Request #2188: (hotfix/修复刀具预警没有预警记录和通知 -> develop)

Merge Request: 功能刀具寿命到期消息通知

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2188
This commit is contained in:
胡尧
2025-06-13 08:41:05 +08:00
committed by Coding
7 changed files with 85 additions and 85 deletions

View File

@@ -445,32 +445,7 @@ class Manufacturing_Connect(http.Controller):
shelfinfo = list(filter(lambda x: x.get('DeviceId') == DeciveId, shelfinfo = list(filter(lambda x: x.get('DeviceId') == DeciveId,
request.env['sf.shelf.location'].sudo().get_sf_shelf_location_info( request.env['sf.shelf.location'].sudo().get_sf_shelf_location_info(
DeciveId))) DeciveId)))
total_data = request.env['sf.shelf.location.datasync'].sudo().get_total_data() request.env['sf.shelf.location.datasync'].sudo().set_shelf_location(shelfinfo)
for item in shelfinfo:
logging.info('货架已获取信息:%s' % item)
shelf_barcode = request.env['sf.shelf.location.datasync'].sudo().find_our_code(
total_data, item['Postion'])
location_id = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', shelf_barcode)],
limit=1)
if location_id:
# 如果是线边刀库信息,则对功能刀具移动生成记录
if 'Tool' in item['Postion']:
tool = request.env['sf.functional.cutting.tool.entity'].sudo().search(
[('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')])
tool.sudo().tool_in_out_stock_location(location_id)
if tool:
location_id.product_sn_id = tool.barcode_id.id
# 修改功能刀具状态
if item.get('State') == '报警':
if tool.functional_tool_status != item.get('State'):
tool.write({
'functional_tool_status': item['State']
})
else:
location_id.product_sn_id = False
if item['RfidCode']:
logging.info('Rfid为【%s】的功能刀具在系统中不存在!' % item['RfidCode'])
else: else:
equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', DeciveId)]) equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', DeciveId)])
if equipment_id: if equipment_id:

View File

@@ -210,8 +210,8 @@
<field name="msgtype">markdown</field> <field name="msgtype">markdown</field>
<field name="urgency">normal</field> <field name="urgency">normal</field>
<field name="content">### 功能刀具寿命到期提醒: <field name="content">### 功能刀具寿命到期提醒:
单号:拆解单[{{code}}]({{tool_expired_remind_special_url}}) 单号:拆解单[{{code}}]({{request_url}})
事项:{{functional_tool_id.tool_name_id.name}}寿命已到期,需拆解</field> 事项:{{name}}寿命已到期,需拆解</field>
</record> </record>
<record id="template_tool_assembly_remind" model="jikimo.message.template"> <record id="template_tool_assembly_remind" model="jikimo.message.template">

View File

@@ -1,4 +1,5 @@
from odoo import models, api from odoo import models, api
from urllib.parse import urlencode
class SFMessagefunctionalToolDismantle(models.Model): class SFMessagefunctionalToolDismantle(models.Model):
@@ -18,12 +19,39 @@ class SFMessagefunctionalToolDismantle(models.Model):
obj.add_queue('功能刀具寿命到期') obj.add_queue('功能刀具寿命到期')
return result return result
def get_special_url(self,id,tmplate_name,special_name,model_id): 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
td_line = self.search([('id', '=', int(message_queue_id.res_id))])
url = self.request_url(int(message_queue_id.res_id))
content = content.replace('{{code}}', td_line.code).replace(
'{{request_url}}', url).replace('{{name}}', td_line.name)
contents.append(content)
return contents, message_queue_ids
def request_url(self, id):
url = self.env['ir.config_parameter'].get_param('web.base.url')
action_id = self.env.ref('sf_tool_management.sf_functional_tool_dismantle_view_act').id
menu_id = self.env.ref('sf_tool_management.menu_sf_functional_tool_dismantle').id
# 查询参数
params = {'id': id, 'menu_id': menu_id, 'action': action_id,
'model': 'sf.functional.tool.dismantle',
'view_type': 'form'}
# 拼接查询参数
tool_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + tool_string
return full_url
def get_special_url(self, id, tmplate_name, special_name, model_id):
menu_id = 0 menu_id = 0
action_id = 0 action_id = 0
if tmplate_name=='调拨入库' and special_name== 'tool_expired_remind_special_url': if tmplate_name == '调拨入库' and special_name == 'tool_expired_remind_special_url':
menu_id = self.env.ref('mrp.menu_mrp_root').id menu_id = self.env.ref('mrp.menu_mrp_root').id
action_id = self.env.ref('sf_tool_management.sf_functional_tool_dismantle_view_act').id action_id = self.env.ref('sf_tool_management.sf_functional_tool_dismantle_view_act').id
return super(SFMessagefunctionalToolDismantle, self).get_url(id, menu_id, action_id,model_id) return super(SFMessagefunctionalToolDismantle, self).get_url(id, menu_id, action_id, model_id)
else: else:
return super(SFMessagefunctionalToolDismantle, self).get_special_url(id, tmplate_name, special_name, model_id) return super(SFMessagefunctionalToolDismantle, self).get_special_url(id, tmplate_name, special_name,
model_id)

View File

@@ -43,14 +43,17 @@ class SFMessageQualityCheck(models.Model):
# ('message_template_id', '=', message_template.id)]) # ('message_template_id', '=', message_template.id)])
# return jikimo_message_queue # return jikimo_message_queue
def write(self, vals): def write(self, vals):
original_state = self.quality_state original_state = {}
for item in self:
original_state.update({f'{item.id}': item.quality_state})
res = super(SFMessageQualityCheck, self).write(vals) res = super(SFMessageQualityCheck, self).write(vals)
if res and vals.get('quality_state') == 'none' and original_state != 'none': for item in self:
if vals.get('quality_state') == 'none' and original_state.get(f'{item.id}') != 'none':
message_template_id = self.env['jikimo.message.template'].sudo().search([('name', '=', '待质检提醒')]) message_template_id = self.env['jikimo.message.template'].sudo().search([('name', '=', '待质检提醒')])
queue_id = self.env['jikimo.message.queue'].sudo().search( queue_id = self.env['jikimo.message.queue'].sudo().search(
[('message_template_id', '=', message_template_id[-1].id), ('res_id', '=', self.id)]) [('message_template_id', '=', message_template_id[-1].id), ('res_id', '=', item.id)])
if not queue_id and '制造' not in [pt.name for pt in self.point_id.picking_type_ids]: if not queue_id and '制造' not in [pt.name for pt in item.point_id.picking_type_ids]:
self.add_queue('待质检') item.add_queue('待质检')
return res return res
def _get_message(self, message_queue_ids): def _get_message(self, message_queue_ids):

View File

@@ -58,20 +58,6 @@ class FunctionalCuttingToolEntity(models.Model):
safe_inventory_id = fields.Many2one('sf.real.time.distribution.of.functional.tools', safe_inventory_id = fields.Many2one('sf.real.time.distribution.of.functional.tools',
string='功能刀具安全库存', readonly=True) string='功能刀具安全库存', readonly=True)
@api.onchange('functional_tool_status')
def _onchange_functional_tool_status(self):
for item in self:
if item:
if item.functional_tool_status == '报警':
self.create_tool_dismantle()
def set_functional_tool_status(self):
# self.write({
# 'functional_tool_status': '报警'
# })
self.functional_tool_status = '报警'
self.create_tool_dismantle()
def create_tool_dismantle(self): def create_tool_dismantle(self):
for item in self: for item in self:
# 创建报警刀具拆解单 # 创建报警刀具拆解单

View File

@@ -42,7 +42,6 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form create="0" edit="0" delete="0"> <form create="0" edit="0" delete="0">
<header> <header>
<button name="set_functional_tool_status" string="报警" type="object" invisible="1"/>
<!-- <button name="enroll_functional_tool_entity" string="功能刀具注册" type="object"--> <!-- <button name="enroll_functional_tool_entity" string="功能刀具注册" type="object"-->
<!-- class="btn-primary"/>--> <!-- class="btn-primary"/>-->
<field name="functional_tool_status" widget="statusbar" statusbar_visible="正常,报警,已拆除"/> <field name="functional_tool_status" widget="statusbar" statusbar_visible="正常,报警,已拆除"/>

View File

@@ -107,20 +107,33 @@ class MrsShelfLocationDataSync(models.Model):
equipment_id.register_equipment_tool() equipment_id.register_equipment_tool()
shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info() shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info()
total_data = self.get_total_data() self.set_shelf_location(shelfinfo)
except Exception as e:
logging.info("库区信息同步失败:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员")
def set_shelf_location(self, shelfinfo):
print('shelfinfo:', shelfinfo) print('shelfinfo:', shelfinfo)
total_data = self.get_total_data()
for item in shelfinfo: for item in shelfinfo:
logging.info('货架已获取信息:%s' % item) logging.info('货架已获取信息:%s' % item)
shelf_barcode = self.find_our_code(total_data, item['Postion']) shelf_barcode = self.env['sf.shelf.location.datasync'].sudo().find_our_code(
location_id = self.env['sf.shelf.location'].search([('barcode', '=', shelf_barcode)], limit=1) total_data, item['Postion'])
location_id = self.env['sf.shelf.location'].sudo().search(
[('barcode', '=', shelf_barcode)],
limit=1)
if location_id: if location_id:
# 如果是线边刀库信息,则对功能刀具移动生成记录 # 如果是线边刀库信息,则对功能刀具移动生成记录
if 'Tool' in item['Postion']: if 'Tool' in item['Postion']:
tool = self.env['sf.functional.cutting.tool.entity'].sudo().search( tool = self.env['sf.functional.cutting.tool.entity'].sudo().search(
[('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')]) [('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')])
tool.tool_in_out_stock_location(location_id) tool.sudo().tool_in_out_stock_location(location_id)
if tool: if tool:
location_id.product_sn_id = tool.barcode_id.id location_id.product_sn_id = tool.barcode_id.id
if item.get('State') == '报警' and tool.functional_tool_status != '报警':
# 创建报警刀具拆解单和刀具报警记录
tool.create_tool_dismantle()
# 修改功能刀具标准状态值和已使用寿命值、功能刀具状态 # 修改功能刀具标准状态值和已使用寿命值、功能刀具状态
if 'LifeStd' in item and 'LifeUse' in item: if 'LifeStd' in item and 'LifeUse' in item:
tool.sudo().write({ tool.sudo().write({
@@ -138,7 +151,3 @@ class MrsShelfLocationDataSync(models.Model):
location_id.product_sn_id = stock_lot_obj.id location_id.product_sn_id = stock_lot_obj.id
else: else:
location_id.product_sn_id = False location_id.product_sn_id = False
except Exception as e:
logging.info("库区信息同步失败:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员")