From baee5a975f3e808c9489820d8ab5df14defeecba Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Tue, 4 Apr 2023 11:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=BB=99js=E7=9A=84action?= =?UTF-8?q?=E5=B7=B2=E9=85=8D=E7=BD=AE=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/models/ftp_client.py | 53 ++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py index defb33dc..53ff1e9e 100644 --- a/sf_machine_connect/models/ftp_client.py +++ b/sf_machine_connect/models/ftp_client.py @@ -7,7 +7,7 @@ import hashlib import time import requests from datetime import datetime - +from odoo.http import request from odoo import fields, models, api, _ from odoo.exceptions import ValidationError from odoo.exceptions import UserError @@ -482,6 +482,57 @@ class WorkCenterBarcode(models.Model): url = 'https://bfm.cs.jikimo.com/api/get/state' requests.post(url, json=json, data=None) + def action_test(self, barcode=12345): + + workorder_obj = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)]) + action = { + 'name': '工单', + # 'name': name, + 'type': 'ir.actions.act_window', + # 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mrp.workorder', + 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id, + 'res_id': 1023, + 'target': 'current', + 'context': {'id': workorder_obj.id}, + # 'flags': {'initial_mode': 'edit'}, + } + return action + # result = request.env['ir.actions.act_window'].sudo().create(action).read()[0] + # action = {'action': action} + # return result + + @api.model + def get_product_id_by_barcode(self, barcode, **kwargs): + print(kwargs) + print(barcode) + print('111111111111111111111') + workorder_obj = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)]) + workorder_cnc = self.env['mrp.workorder'].sudo().search(['&', ('production_id', '=', workorder_obj.production_id.id), ('name', '=', 'CNC加工')]) + print('222222222222222222222222') + if workorder_obj: + print(workorder_obj) + print(workorder_obj.id) + action = { + 'name': '工单', + 'type': 'ir.actions.act_window', + # 'view_type': 'form', + 'views': [[False, 'form']], + 'view_mode': 'form', + 'res_model': 'mrp.workorder', + 'view_id': request.env.ref('mrp.mrp_production_workorder_form_view_inherit').id, + 'res_id': workorder_cnc.id, + 'target': 'current', + 'context': {'id': workorder_obj.id}, + # 'flags': {'initial_mode': 'edit'}, + } + action = {'result': action, 'error': '返回错误'} + action1 = json.dumps(action) + return action1 + else: + return False + class CuttingTimeToolType(models.Model): _inherit = 'sf.cutting_tool.type'