From f0b972e705ad5c8783d5b615b964f6934493bb11 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Mon, 1 Apr 2024 16:56:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E5=88=80=E6=9F=84?= =?UTF-8?q?=E7=89=A9=E6=96=99=E4=BA=A7=E5=93=81=E9=80=82=E7=94=A8=E5=A4=B9?= =?UTF-8?q?=E5=A4=B4=E5=9E=8B=E5=8F=B7=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BC=98=E5=8C=96=E5=88=80?= =?UTF-8?q?=E5=85=B7=E6=A0=87=E5=87=86=E5=BA=93=E5=9F=BA=E6=9C=AC=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3=EF=BC=9B2?= =?UTF-8?q?=E3=80=81=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=BB=84=E8=A3=85=E6=97=B6=EF=BC=8C=E5=8F=AA=E9=9C=80=E6=89=AB?= =?UTF-8?q?=E5=85=A5=E5=88=80=E6=9F=84=E7=9A=84Rfid=EF=BC=8C=E5=B0=86?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=B8=A6=E5=87=BA=E5=88=80=E6=9F=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=B9=B6=E6=A0=B9=E6=8D=AE=E5=88=80=E6=9F=84?= =?UTF-8?q?=E9=80=82=E7=94=A8=E5=A4=B9=E5=A4=B4=E5=9E=8B=E5=8F=B7=E5=92=8C?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=A4=B9=E5=A4=B4=E5=B0=BA=E5=AF=B8=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=B8=A6=E5=87=BA=E4=B8=80=E4=B8=AA=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E5=A4=B9=E5=A4=B4=E7=89=A9=E6=96=99=E4=BF=A1=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=B0=86=E5=88=80=E6=9F=84=E7=9A=84Rfid?= =?UTF-8?q?=E7=A0=81=E5=A1=AB=E5=85=A5=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=9A=84Rfid=E7=A0=81=E3=80=823=E3=80=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=80=E6=9F=84=E7=89=A9=E6=96=99=E9=87=87=E8=B4=AD=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=97=B6=E7=9A=84=E9=AA=8C=E8=AF=81=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=9D=A1=E4=BB=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/product_template.py | 7 +- sf_mrs_connect/models/sync_common.py | 91 ++++++++------------ sf_tool_management/views/tool_base_views.xml | 2 +- sf_tool_management/wizard/wizard.py | 82 +++++++++++------- sf_warehouse/models/model.py | 4 +- 5 files changed, 95 insertions(+), 91 deletions(-) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index be0c09ae..1489cddd 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -7,7 +7,6 @@ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError from odoo.modules import get_resource_path - from OCC.Extend.DataExchange import read_step_file from OCC.Extend.DataExchange import write_stl_file @@ -107,7 +106,10 @@ class ResProductMo(models.Model): @api.onchange('cutting_tool_model_id') def _onchange_cutting_tool_model_id(self): - self.specification_id = False + for item in self: + if item: + item.specification_id = False + item.cutting_tool_chuck_id = item.cutting_tool_model_id.chuck_id @api.onchange('cutting_tool_material_id') def _onchange_cutting_tool_material_id(self): @@ -310,7 +312,6 @@ class ResProductMo(models.Model): self.cutting_tool_is_safety_lock = self.specification_id.is_safe_lock self.cutting_tool_fit_nut_model = self.specification_id.nut self.cutting_tool_wrench = self.specification_id.spanner - self.cutting_tool_chuck_id = self.specification_id.chuck_id.id self.cutting_tool_jump_accuracy = self.specification_id.diameter_slip_accuracy self.cutting_tool_taper_shank_model = self.specification_id.taper_shank_model self.cutting_tool_cooling_type = self.specification_id.cooling_model diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index 49956f4b..3ee916e7 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -2421,7 +2421,7 @@ class CuttingToolBasicParameters(models.Model): 'active': integral_tool_item['active'], }) else: - self.write({ + self.search([('code', '=', integral_tool_item['code'])]).write({ 'name': integral_tool_item['name'], 'total_length': integral_tool_item['total_length'], 'blade_diameter': integral_tool_item['blade_diameter'], @@ -2482,7 +2482,7 @@ class CuttingToolBasicParameters(models.Model): 'active': blade_item['active'], }) else: - self.write({ + self.search([('code', '=', blade_item['code'])]).write({ 'name': blade_item['name'], 'length': blade_item['length'], 'thickness': blade_item['thickness'], @@ -2539,7 +2539,7 @@ class CuttingToolBasicParameters(models.Model): 'active': chuck_item['active'], }) else: - self.write({ + self.search([('code', '=', chuck_item['code'])]).write({ 'name': chuck_item['name'], 'er_size_model': chuck_item['size_model'], 'min_clamping_diameter': chuck_item['clamping_diameter_min'], @@ -2598,7 +2598,7 @@ class CuttingToolBasicParameters(models.Model): 'active': cutter_arbor_item['active'], }) else: - self.write({ + self.search([('code', '=', cutter_arbor_item['code'])]).write({ 'name': cutter_arbor_item['name'], 'height': cutter_arbor_item['height'], 'width': cutter_arbor_item['width'], @@ -2662,7 +2662,7 @@ class CuttingToolBasicParameters(models.Model): 'active': cutter_head_item['active'], }) else: - self.write({ + self.search([('code', '=', cutter_head_item['code'])]).write({ 'name': cutter_head_item['name'], 'install_blade_tip_num': cutter_head_item['number_blade_installed'], 'blade_diameter': cutter_head_item['blade_diameter'], @@ -2691,57 +2691,38 @@ class CuttingToolBasicParameters(models.Model): for knife_handle_item in basic_parameters_knife_handle_list: knife_handle = self.search( [('code', '=', knife_handle_item['code']), ('active', 'in', [True, False])]) + val = { + 'name': knife_handle_item['name'], + 'taper_shank_model': knife_handle_item['taper_shank_model'], + 'total_length': knife_handle_item['total_length'], + 'flange_shank_length': knife_handle_item['flange_length'], + 'flange_diameter': knife_handle_item['flange_diameter'], + 'shank_length': knife_handle_item['shank_length'], + 'shank_diameter': knife_handle_item['shank_diameter'], + 'min_clamping_diameter': knife_handle_item['clamping_diameter_min'], + 'max_clamping_diameter': knife_handle_item['clamping_diameter_max'], + 'clamping_mode': knife_handle_item['clamping_way'], + 'tool_changing_time': knife_handle_item['tool_changing_time'], + 'max_rotate_speed': knife_handle_item['rotate_speed_max'], + 'diameter_slip_accuracy': knife_handle_item['diameter_slip_accuracy'], + 'cooling_model': knife_handle_item['cooling_model'], + 'fit_chuck_size': knife_handle_item['fit_chuck_size'], + 'is_quick_cutting': knife_handle_item['is_quick_cutting'], + 'is_safe_lock': knife_handle_item['is_safe_lock'], + 'screw': knife_handle_item['fit_wrench_model'], + 'nut': knife_handle_item['fit_nut_model'], + 'dynamic_balance_class': knife_handle_item['dynamic_balance_class'], + 'active': knife_handle_item['active'], + } if not knife_handle: - self.create({ - 'name': knife_handle_item['name'], - 'code': knife_handle_item['code'], - 'cutting_tool_type': '刀柄', - 'taper_shank_model': knife_handle_item['taper_shank_model'], - 'standard_library_id': self.env['sf.cutting_tool.standard.library'].search( - [('code', '=', knife_handle_item['standard_library_code'].replace("JKM", result[ - 'factory_short_name']))]).id, - 'total_length': knife_handle_item['total_length'], - 'flange_shank_length': knife_handle_item['flange_length'], - 'flange_diameter': knife_handle_item['flange_diameter'], - 'shank_length': knife_handle_item['shank_length'], - 'shank_diameter': knife_handle_item['shank_diameter'], - 'min_clamping_diameter': knife_handle_item['clamping_diameter_min'], - 'max_clamping_diameter': knife_handle_item['clamping_diameter_max'], - 'clamping_mode': knife_handle_item['clamping_way'], - 'tool_changing_time': knife_handle_item['tool_changing_time'], - 'max_rotate_speed': knife_handle_item['rotate_speed_max'], - 'diameter_slip_accuracy': knife_handle_item['diameter_slip_accuracy'], - 'cooling_model': knife_handle_item['cooling_model'], - 'is_quick_cutting': knife_handle_item['is_quick_cutting'], - 'is_safe_lock': knife_handle_item['is_safe_lock'], - 'screw': knife_handle_item['fit_wrench_model'], - 'nut': knife_handle_item['fit_nut_model'], - 'dynamic_balance_class': knife_handle_item['dynamic_balance_class'], - 'active': knife_handle_item['active'], - }) + val['code'] = knife_handle_item['code'] + val['cutting_tool_type'] = '刀柄' + val['standard_library_id'] = self.env['sf.cutting_tool.standard.library'].search( + [('code', '=', knife_handle_item['standard_library_code'].replace("JKM", result[ + 'factory_short_name']))]).id + self.create(val) else: - self.write({ - 'name': knife_handle_item['name'], - 'taper_shank_model': knife_handle_item['taper_shank_model'], - 'total_length': knife_handle_item['total_length'], - 'flange_shank_length': knife_handle_item['flange_length'], - 'flange_diameter': knife_handle_item['flange_diameter'], - 'shank_length': knife_handle_item['shank_length'], - 'shank_diameter': knife_handle_item['shank_diameter'], - 'min_clamping_diameter': knife_handle_item['clamping_diameter_min'], - 'max_clamping_diameter': knife_handle_item['clamping_diameter_max'], - 'clamping_mode': knife_handle_item['clamping_way'], - 'tool_changing_time': knife_handle_item['tool_changing_time'], - 'max_rotate_speed': knife_handle_item['rotate_speed_max'], - 'diameter_slip_accuracy': knife_handle_item['diameter_slip_accuracy'], - 'cooling_model': knife_handle_item['cooling_model'], - 'is_quick_cutting': knife_handle_item['is_quick_cutting'], - 'is_safe_lock': knife_handle_item['is_safe_lock'], - 'screw': knife_handle_item['fit_wrench_model'], - 'nut': knife_handle_item['fit_nut_model'], - 'dynamic_balance_class': knife_handle_item['dynamic_balance_class'], - 'active': knife_handle_item['active'], - }) + self.search([('code', '=', knife_handle_item['code'])]).write(val) else: raise ValidationError("刀具物料基本参数认证未通过") @@ -3097,6 +3078,7 @@ class CuttingToolBasicParameters(models.Model): 'cooling_model': knife_handle_item['cooling_model'], 'is_quick_cutting': knife_handle_item['is_quick_cutting'], 'is_safe_lock': knife_handle_item['is_safe_lock'], + 'fit_chuck_size': knife_handle_item['fit_chuck_size'], 'screw': knife_handle_item['fit_wrench_model'], 'nut': knife_handle_item['fit_nut_model'], 'dynamic_balance_class': knife_handle_item['dynamic_balance_class'], @@ -3121,6 +3103,7 @@ class CuttingToolBasicParameters(models.Model): 'max_rotate_speed': knife_handle_item['rotate_speed_max'], 'diameter_slip_accuracy': knife_handle_item['diameter_slip_accuracy'], 'cooling_model': knife_handle_item['cooling_model'], + 'fit_chuck_size': knife_handle_item['fit_chuck_size'], 'is_quick_cutting': knife_handle_item['is_quick_cutting'], 'is_safe_lock': knife_handle_item['is_safe_lock'], 'screw': knife_handle_item['fit_wrench_model'], diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml index 4406a90f..b210ff29 100644 --- a/sf_tool_management/views/tool_base_views.xml +++ b/sf_tool_management/views/tool_base_views.xml @@ -1056,7 +1056,7 @@ - + diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py index dbece7b7..eac95d8c 100644 --- a/sf_tool_management/wizard/wizard.py +++ b/sf_tool_management/wizard/wizard.py @@ -295,35 +295,70 @@ class FunctionalToolAssemblyOrder(models.TransientModel): """ for record in self: if 'DJWL' in barcode: - records = record.env['stock.lot'].search([('name', '=', barcode)]) - if not records: + lot_ids = record.env['stock.lot'].sudo().search([('name', '=', barcode)]) + if not lot_ids: raise ValidationError('扫描的条形码数据不存在,请重新扫描!') - for record_stock_lot in records: - if record_stock_lot.quant_ids[-1].location_id.name == '刀具组装位置': - raise ValidationError('该刀具物料已使用,请重新选择!!!') - elif record_stock_lot.quant_ids[-1].location_id.name not in '刀具房': - raise ValidationError('该刀具物料未入库,请重新选择!!!') - tool_material_name = record_stock_lot.product_id.cutting_tool_material_id.name + for lot_id in lot_ids: + if lot_id.quant_ids[-1].location_id.name == '刀具组装位置': + raise ValidationError('该刀具物料已使用,请重新扫描!!!') + elif lot_id.quant_ids[-1].location_id.name not in '刀具房': + raise ValidationError('该刀具物料未入库,请重新扫描!!!') + tool_material_name = lot_id.product_id.cutting_tool_material_id.name if tool_material_name == '整体式刀具': - record.integral_code_id = record_stock_lot.id + record.integral_code_id = lot_id.id elif tool_material_name == '刀片': - record.blade_code_id = record_stock_lot.id + record.blade_code_id = lot_id.id elif tool_material_name == '刀杆': - record.bar_code_id = record_stock_lot.id + record.bar_code_id = lot_id.id elif tool_material_name == '刀盘': - record.pad_code_id = record_stock_lot.id + record.pad_code_id = lot_id.id elif tool_material_name == '刀柄': - record.handle_code_id = record_stock_lot.id + record.handle_code_id = lot_id.id + record.chuck_code_id = record.get_chuck_code_id(lot_id).id or False elif tool_material_name == '夹头': - record.chuck_code_id = record_stock_lot.id + record.chuck_code_id = lot_id.id else: raise ValidationError('扫描的刀具物料不存在,请重新扫描!') else: - record.rfid = barcode + lot_ids = self.env['stock.lot'].sudo().search([('rfid', '=', barcode)]) + if not lot_ids: + raise ValidationError('扫描的刀具物料不存在,请重新扫描!') + for lot_id in lot_ids: + if lot_id.quant_ids[-1].location_id.name in '刀具房': + record.handle_code_id = lot_id.id + record.chuck_code_id = record.get_chuck_code_id(lot_id).id or False + elif lot_id.quant_ids[-1].location_id.name == '刀具组装位置': + raise ValidationError('该刀柄已使用,请重新扫描!!!') + else: + raise ValidationError('该刀柄未入库,请重新扫描!!!') + + def get_chuck_code_id(self, lot_id): + # 适用夹头型号 + cutting_tool_chuck_id = lot_id.product_id.cutting_tool_chuck_id + # 适用夹头尺寸 + fit_chuck_size = lot_id.product_id.cutting_tool_fit_chuck_size + # 适用夹头产品 + chuck_product_id = self.env['product.product'].sudo().search( + [('cutting_tool_model_id', '=', cutting_tool_chuck_id.id), + ('cutting_tool_er_size_model', '=', fit_chuck_size)]) + # 适用夹头产品序列号 + chuck_product_lot_ids = self.env['stock.lot'].sudo().search( + [('product_id', '=', chuck_product_id.id), ('tool_material_status', '=', '可用')]) + for chuck_product_lot_id in chuck_product_lot_ids: + if chuck_product_lot_id.quant_ids[-1].location_id.name in '刀具房': + return chuck_product_lot_id + + @api.depends('handle_code_id') + def _compute_rfid(self): + for item in self: + if item: + item.rfid = item.handle_code_id.rfid + else: + item.rfid = None # 组装功能刀具参数信息 barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号') - rfid = fields.Char('Rfid', required=True) + rfid = fields.Char('Rfid', readonly=True, store=True, compute='_compute_rfid') tool_code = fields.Char(string='功能刀具编码', readonly=True, compute='_compute_tool_code') after_assembly_functional_tool_name = fields.Char(string='组装后功能刀具名称', compute='_compute_name') after_assembly_functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', @@ -442,21 +477,6 @@ class FunctionalToolAssemblyOrder(models.TransientModel): if obj.after_assembly_functional_tool_length == 0: raise ValidationError('组装参数信息【伸出长】不能为0!!!') - @api.constrains('rfid') - def _check_rfid(self): - self.get_rfid() - - @api.onchange('rfid') - def _onchange_rfid(self): - self.get_rfid() - - def get_rfid(self): - for obj in self: - if obj.rfid: - tool_entity = self.env['sf.functional.cutting.tool.entity'].sudo().search([('rfid', '=', obj.rfid)]) - if tool_entity: - raise ValidationError('【%s】的Rfid已被使用,请重新录入!!!' % obj.rfid) - def functional_tool_assembly(self): """ 功能刀具组装 diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 3667c62c..328f5d43 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -746,9 +746,9 @@ class SfStockPicking(models.Model): line.current_location_id.location_status = '空闲' for move in self.move_ids: - if move and move.product_id.cutting_tool_material_id.name in '刀柄': + if move and move.product_id.cutting_tool_material_id.name == '刀柄': for item in move.move_line_nosuggest_ids: - if item: + if item.location_dest_id.name == '进货': self.env['stock.lot'].search([('name', '=', item.lot_name)]).write({'rfid': item.rfid}) return res