From fbce395321a5c4166301100b414ea44c9a147254 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Mon, 11 Mar 2024 17:34:03 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E5=BA=8F=E5=88=97=E5=8F=B7=E3=80=81=E5=88=80?= =?UTF-8?q?=E5=85=B7=E7=89=A9=E6=96=99=E6=B3=A8=E5=86=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9B2=E3=80=81=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=88=80=E5=85=B7=E3=80=81=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7?= =?UTF-8?q?=E5=87=BA=E5=85=A5=E5=BA=93=E8=AE=B0=E5=BD=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9B3=E3=80=81=E4=BC=98=E5=8C=96=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/base.py | 1 - .../models/functional_tool_enroll.py | 84 +++++++++++-------- .../models/maintenance_equipment.py | 11 ++- .../models/tool_material_search.py | 10 +-- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 649c757e..da1433ea 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -136,7 +136,6 @@ class FunctionalCuttingToolEntity(models.Model): @api.depends('cutting_tool_integral_model_id', 'cutting_tool_blade_model_id') def _compute_maintenance_equipment_image(self): for record in self: - print('111') if record.cutting_tool_integral_model_id: print(record.cutting_tool_integral_model_id) record.sudo().suitable_machining_method_ids = record.cutting_tool_integral_model_id.suitable_machining_method_ids.ids diff --git a/sf_tool_management/models/functional_tool_enroll.py b/sf_tool_management/models/functional_tool_enroll.py index 2d2941f5..b14ce16b 100644 --- a/sf_tool_management/models/functional_tool_enroll.py +++ b/sf_tool_management/models/functional_tool_enroll.py @@ -25,29 +25,24 @@ class StockLot(models.Model): val = { 'name': item.name, 'tool_material_status': item.tool_material_status, - 'location': item.quant_ids[-1].location_id.name, - 'tool_material_search_code': item.tool_material_search_id.code, + 'location': [] if not item.quant_ids else item.quant_ids[-1].location_id.name, + 'tool_material_search_id': item.tool_material_search_id.id, } tool_material_stock_list.append(val) kw = json.dumps(tool_material_stock_list, ensure_ascii=False) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() - if r == 200: + if ret.get('code') == 200: return '刀具物料序列号注册成功' else: raise UserError("没有注册刀具物料序列号信息") - @api.onchange('quant_ids') - def _onchange_quant_ids(self): - for item in self: - if item.product_id.categ_id == '刀具': - item.enroll_tool_material_stock() - @api.model_create_multi def create(self, vals_list): records = super(StockLot, self).create(vals_list) for record in records: - if record.product_id.categ_id == '刀具': + if record.product_id.categ_id.name == '刀具': + record.tool_material_status = '可用' record.enroll_tool_material_stock() return records @@ -74,11 +69,11 @@ class ToolMaterial(models.Model): barcode_names.append(barcode_id.name) val = { 'name': item.name, - 'code': item.code, + 'id': item.id, 'cutting_tool_material_code': item.cutting_tool_material_id.code, 'cutting_tool_standard_library_code': item.cutting_tool_standard_library_id.code, 'specification_name': item.specification_id.name, - 'image': item.image, + 'image': '' if not item.image else base64.b64encode(item.image).decode('utf-8'), 'number': item.number, 'usable_num': item.usable_num, 'have_been_used_num': item.have_been_used_num, @@ -95,6 +90,14 @@ class ToolMaterial(models.Model): else: raise UserError("没有注册刀具物料信息") + @api.model_create_multi + def create(self, vals_list): + records = super(ToolMaterial, self).create(vals_list) + for record in records: + if record: + record.enroll_tool_material() + return records + class FunctionalCuttingToolEntity(models.Model): _inherit = 'sf.functional.cutting.tool.entity' @@ -113,6 +116,18 @@ class FunctionalCuttingToolEntity(models.Model): functional_tool_list = [] if objs_all: for item in objs_all: + suitable_machining_method_names = [] + cutting_direction_names = [] + suitable_coolant_names = [] + for suitable_machining_method_id in item.suitable_machining_method_ids: + if suitable_machining_method_id: + suitable_machining_method_names.append(suitable_machining_method_id.name) + for cutting_direction_id in item.cutting_direction_ids: + if cutting_direction_id: + cutting_direction_names.append(cutting_direction_id.name) + for suitable_coolant_id in item.suitable_coolant_ids: + if suitable_coolant_id: + suitable_coolant_names.append(suitable_coolant_id.name) val = { 'id': item.id, 'code': item.code, @@ -143,21 +158,24 @@ class FunctionalCuttingToolEntity(models.Model): 'cut_time': item.cut_time, 'cut_length': item.cut_length, 'cut_number': item.cut_number, - 'cutting_tool_integral_model_code': item.cutting_tool_integral_model_id.code, - 'cutting_tool_blade_model_code': item.cutting_tool_blade_model_id.code, - 'cutting_tool_cutterbar_model_code': item.cutting_tool_cutterbar_model_id.code, - 'cutting_tool_cutterpad_model_code': item.cutting_tool_cutterpad_model_id.code, - 'cutting_tool_cutterhandle_model_code': item.cutting_tool_cutterhandle_model_id.code, - 'cutting_tool_cutterhead_model_code': item.cutting_tool_cutterhead_model_id.code, + 'cutting_tool_integral_model_id': item.cutting_tool_integral_model_id.tool_material_id, + 'cutting_tool_blade_model_id': item.cutting_tool_blade_model_id.tool_material_id, + 'cutting_tool_cutterbar_model_id': item.cutting_tool_cutterbar_model_id.tool_material_id, + 'cutting_tool_cutterpad_model_id': item.cutting_tool_cutterpad_model_id.tool_material_id, + 'cutting_tool_cutterhandle_model_id': item.cutting_tool_cutterhandle_model_id.tool_material_id, + 'cutting_tool_cutterhead_model_id': item.cutting_tool_cutterhead_model_id.tool_material_id, + 'suitable_machining_method_names': suitable_machining_method_names, + 'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name, + 'handle_type_name': item.handle_type_id.name, + 'cutting_direction_names': cutting_direction_names, + 'suitable_coolant_names': suitable_coolant_names, 'active': item.active, } functional_tool_list.append(val) kw = json.dumps(functional_tool_list, ensure_ascii=False) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() - # self.code = ret['data'] - # self.state_zc = "已注册" - if r == 200: + if ret.get('code') == 200: return "功能刀具注册成功" else: raise UserError("没有注册功能刀具信息") @@ -192,6 +210,7 @@ class FunctionalToolWarning(models.Model): 'id': item.id, 'name': item.name, 'code': item.code, + 'rfid': item.rfid, 'tool_groups_name': item.tool_groups_id.name, 'production_line': item.production_line_id.name, 'machine_tool_id': item.maintenance_equipment_id.code, @@ -218,9 +237,7 @@ class FunctionalToolWarning(models.Model): kw = json.dumps(tool_warning_list, ensure_ascii=False) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() - # self.code = ret['data'] - # self.state_zc = "已注册" - if r == 200: + if ret.get('code') == 200: return "功能刀具预警注册成功" else: raise UserError("没有注册功能刀具预警信息") @@ -255,6 +272,7 @@ class StockMoveLine(models.Model): 'id': item.id, 'name': item.functional_tool_name_id.name, 'code': item.code, + 'rfid': item.rfid, 'tool_groups_name': item.tool_groups_id.name, 'reference': item.reference, 'barcode': item.lot_id.name, @@ -271,9 +289,7 @@ class StockMoveLine(models.Model): kw = json.dumps(tool_stock_list, ensure_ascii=False) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() - # self.code = ret['data'] - # self.state_zc = "已注册" - if r == 200: + if ret.get('code') == 200: return "功能刀具出入库记录注册成功" else: raise UserError("没有注册功能刀具出入库记录信息") @@ -310,8 +326,9 @@ class RealTimeDistributionFunctionalTools(models.Model): val = { 'id': item.id, 'name': item.name, + 'rfid': item.rfid, 'tool_groups_name': item.tool_groups_id.name, - 'sf_cutting_tool_type_code': item.sf_cutting_tool_type_id.code, + 'cutting_tool_type_code': item.sf_cutting_tool_type_id.code, 'diameter': item.diameter, 'knife_tip_r_angle': item.knife_tip_r_angle, 'tool_stock_num': item.tool_stock_num, @@ -332,9 +349,7 @@ class RealTimeDistributionFunctionalTools(models.Model): kw = json.dumps(tool_distribution_list, ensure_ascii=False) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() - # self.code = ret['data'] - # self.state_zc = "已注册" - if r == 200: + if ret.get('code') == 200: return "功能刀具出入库记录注册成功" else: raise UserError("没有注册功能刀具出入库记录信息") @@ -344,10 +359,5 @@ class RealTimeDistributionFunctionalTools(models.Model): records = super(RealTimeDistributionFunctionalTools, self).create(vals_list) for record in records: if record.functional_tool_name_id: - record.enroll_functional_tool_move() + record.enroll_functional_tool_real_time_distribution() return records - - def write(self, vals): - res = super().write(vals) - self.enroll_functional_tool_move() - return res diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py index 4fbf0b9e..0dca8868 100644 --- a/sf_tool_management/models/maintenance_equipment.py +++ b/sf_tool_management/models/maintenance_equipment.py @@ -109,6 +109,8 @@ class StockLot(models.Model): record.tool_material_status = '在用' else: record.tool_material_status = '可用' + # 注册刀具物料状态到cloud平台 + record.enroll_tool_material_stock() @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): @@ -137,9 +139,7 @@ class StockLot(models.Model): for record in records: if record.product_id.categ_id.name == '刀具': tool_material_search = self.env['sf.tool.material.search'].sudo().search( - [('cutting_tool_material_id', '=', record.product_id.cutting_tool_material_id.id), - ('cutting_tool_standard_library_id', '=', record.product_id.cutting_tool_model_id.id), - ('specification_id', '=', record.product_id.specification_id.id)]) + [('id', '=', record.product_id.tool_material_id)]) if tool_material_search: record.tool_material_search_id = tool_material_search return records @@ -148,12 +148,15 @@ class StockLot(models.Model): class ProductProduct(models.Model): _inherit = 'product.product' + tool_material_id = fields.Char('刀具物料搜索模型ID') + @api.model_create_multi def create(self, vals_list): records = super(ProductProduct, self).create(vals_list) for record in records: if record.categ_id.name == '刀具': - self.env['sf.tool.material.search'].sudo().create({ + tool_material = self.env['sf.tool.material.search'].sudo().create({ 'product_id': record.id }) + record.tool_material_id = tool_material.id return records diff --git a/sf_tool_management/models/tool_material_search.py b/sf_tool_management/models/tool_material_search.py index 1812c489..547bae32 100644 --- a/sf_tool_management/models/tool_material_search.py +++ b/sf_tool_management/models/tool_material_search.py @@ -311,7 +311,7 @@ class ToolMaterial(models.Model): product_id = fields.Many2one('product.product', string='刀具物料产品') name = fields.Char('名称', related='product_id.name') - code = fields.Char('编码', compute='_compute_code', store=True) + code = fields.Char('编码') cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料', related='product_id.cutting_tool_material_id', store=True, @@ -331,14 +331,6 @@ class ToolMaterial(models.Model): active = fields.Boolean(string='已归档', default=True) - @api.depends('product_id') - def _compute_code(self): - for record in self: - if record: - code = '%s_%s' % (record.cutting_tool_standard_library_id.code, record.specification_id.name) - obj = self.search([('code', 'like', code)], limit=1, order="id desc") - record.code = '%s_%03d' % (code, 1 if obj else int(obj.code[-3:]) + 1) - @api.depends('barcode_ids') def _compute_number(self): for record in self: