1、优化扫描录入刀具物料方法,

This commit is contained in:
yuxianghui
2024-04-09 17:27:37 +08:00
parent 85649daef6
commit f19a1a282a

View File

@@ -238,7 +238,9 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
@api.depends('integral_freight_barcode') @api.depends('integral_freight_barcode')
def _compute_integral_product_id(self): def _compute_integral_product_id(self):
pass location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.integral_freight_barcode)])
if location:
self.integral_product_id = location.product_id.id
# ===============刀片型号==================== # ===============刀片型号====================
blade_freight_barcode = fields.Char('刀片货位') blade_freight_barcode = fields.Char('刀片货位')
@@ -255,7 +257,9 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
@api.depends('blade_freight_barcode') @api.depends('blade_freight_barcode')
def _compute_blade_product_id(self): def _compute_blade_product_id(self):
pass location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.blade_freight_barcode)])
if location:
self.blade_product_id = location.product_id.id
# ====================刀杆型号================== # ====================刀杆型号==================
bar_freight_barcode = fields.Char('刀杆货位') bar_freight_barcode = fields.Char('刀杆货位')
@@ -272,7 +276,9 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
@api.depends('bar_freight_barcode') @api.depends('bar_freight_barcode')
def _compute_bar_product_id(self): def _compute_bar_product_id(self):
pass location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.bar_freight_barcode)])
if location:
self.bar_product_id = location.product_id.id
# ===============刀盘型号=================== # ===============刀盘型号===================
pad_freight_barcode = fields.Char('刀盘货位') pad_freight_barcode = fields.Char('刀盘货位')
@@ -289,7 +295,9 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
@api.depends('pad_freight_barcode') @api.depends('pad_freight_barcode')
def _compute_pad_product_id(self): def _compute_pad_product_id(self):
pass location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.pad_freight_barcode)])
if location:
self.pad_product_id = location.product_id.id
# ================刀柄型号=============== # ================刀柄型号===============
handle_code_id = fields.Many2one('stock.lot', '刀柄序列号', required=True, handle_code_id = fields.Many2one('stock.lot', '刀柄序列号', required=True,
@@ -317,69 +325,44 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
@api.depends('chuck_freight_barcode') @api.depends('chuck_freight_barcode')
def _compute_chuck_product_id(self): def _compute_chuck_product_id(self):
pass location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.chuck_freight_barcode)])
if location:
self.chuck_product_id = location.product_id.id
# ======================================== # ========================================
def on_barcode_scanned(self, barcode): def on_barcode_scanned(self, barcode):
""" """
智能工厂组装单处扫码绑定刀具物料') 智能工厂组装单处扫码绑定刀具物料
""" """
for record in self: for record in self:
if 'DJWL' in barcode: lot_ids = self.env['stock.lot'].sudo().search([('rfid', '=', barcode)])
lot_ids = record.env['stock.lot'].sudo().search([('name', '=', barcode)]) if lot_ids:
if not lot_ids:
raise ValidationError('扫描的条形码数据不存在,请重新扫描!')
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 = lot_id.id
elif tool_material_name == '刀片':
record.blade_code_id = lot_id.id
elif tool_material_name == '刀杆':
record.bar_code_id = lot_id.id
elif tool_material_name == '刀盘':
record.pad_code_id = lot_id.id
elif tool_material_name == '刀柄':
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 = lot_id.id
else:
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
else:
lot_ids = self.env['stock.lot'].sudo().search([('rfid', '=', barcode)])
if not lot_ids:
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
for lot_id in lot_ids: for lot_id in lot_ids:
if lot_id.quant_ids[-1].location_id.name in '刀具房': if lot_id.quant_ids[-1].location_id.name in '刀具房':
record.handle_code_id = lot_id.id 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 == '刀具组装位置': elif lot_id.quant_ids[-1].location_id.name == '刀具组装位置':
raise ValidationError('该刀柄已使用,请重新扫描!!!') raise ValidationError('该刀柄已使用,请重新扫描!!!')
else: else:
raise ValidationError('该刀柄未入库,请重新扫描!!!') raise ValidationError('该刀柄未入库,请重新扫描!!!')
else:
def get_chuck_code_id(self, lot_id): location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', barcode)])
# 适用夹头型号 if location:
cutting_tool_chuck_id = lot_id.product_id.cutting_tool_chuck_id material_name = location.product_id.cutting_tool_material_id.name
# 适用夹头尺寸 if material_name == '整体式刀具':
fit_chuck_size = lot_id.product_id.cutting_tool_fit_chuck_size record.integral_freight_barcode = barcode
# 适用夹头产品 elif material_name == '刀片':
chuck_product_id = self.env['product.product'].sudo().search( record.blade_freight_barcode = barcode
[('cutting_tool_model_id', '=', cutting_tool_chuck_id.id), elif material_name == '刀杆':
('cutting_tool_er_size_model', '=', fit_chuck_size)]) record.bar_freight_barcode = barcode
# 适用夹头产品序列号 elif material_name == '刀盘':
chuck_product_lot_ids = self.env['stock.lot'].sudo().search( record.pad_freight_barcode = barcode
[('product_id', '=', chuck_product_id.id), ('tool_material_status', '=', '可用')]) elif material_name == '夹头':
for chuck_product_lot_id in chuck_product_lot_ids: record.chuck_freight_barcode = barcode
if chuck_product_lot_id.quant_ids[-1].location_id.name in '刀具房': else:
return chuck_product_lot_id raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
return False else:
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
@api.depends('handle_code_id') @api.depends('handle_code_id')
def _compute_rfid(self): def _compute_rfid(self):
@@ -605,12 +588,12 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'name': self.after_assembly_functional_tool_name, 'name': self.after_assembly_functional_tool_name,
'rfid': self.rfid, 'rfid': self.rfid,
'tool_groups_id': self.tool_groups_id.id, 'tool_groups_id': self.tool_groups_id.id,
'integral_code_id': self.integral_code_id.id, 'integral_product_id': self.integral_product_id.id,
'blade_code_id': self.blade_code_id.id, 'blade_product_id': self.blade_product_id.id,
'bar_code_id': self.bar_code_id.id, 'bar_product_id': self.bar_product_id.id,
'pad_code_id': self.pad_code_id.id, 'pad_product_id': self.pad_product_id.id,
'handle_code_id': self.handle_code_id.id, 'handle_code_id': self.handle_code_id.id,
'chuck_code_id': self.chuck_code_id.id, 'chuck_product_id': self.chuck_product_id.id,
'after_assembly_functional_tool_name': self.after_assembly_functional_tool_name, 'after_assembly_functional_tool_name': self.after_assembly_functional_tool_name,
'after_assembly_functional_tool_type_id': self.after_assembly_functional_tool_type_id.id, 'after_assembly_functional_tool_type_id': self.after_assembly_functional_tool_type_id.id,
@@ -645,12 +628,12 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'tool_groups_id': self.tool_groups_id.id, 'tool_groups_id': self.tool_groups_id.id,
'functional_tool_name_id': functional_tool_assembly_id.id, 'functional_tool_name_id': functional_tool_assembly_id.id,
'sf_cutting_tool_type_id': self.after_assembly_functional_tool_type_id.id, 'sf_cutting_tool_type_id': self.after_assembly_functional_tool_type_id.id,
'cutting_tool_integral_model_id': self.integral_code_id.product_id.id, 'cutting_tool_integral_model_id': self.integral_product_id.id,
'cutting_tool_blade_model_id': self.blade_code_id.product_id.id, 'cutting_tool_blade_model_id': self.blade_product_id.id,
'cutting_tool_cutterbar_model_id': self.bar_code_id.product_id.id, 'cutting_tool_cutterbar_model_id': self.bar_product_id.id,
'cutting_tool_cutterpad_model_id': self.pad_code_id.product_id.id, 'cutting_tool_cutterpad_model_id': self.pad_product_id.id,
'cutting_tool_cutterhandle_model_id': self.handle_code_id.product_id.id, 'cutting_tool_cutterhandle_model_id': self.handle_product_id.id,
'cutting_tool_cutterhead_model_id': self.chuck_code_id.product_id.id, 'cutting_tool_cutterhead_model_id': self.chuck_product_id.id,
'functional_tool_diameter': self.after_assembly_functional_tool_diameter, 'functional_tool_diameter': self.after_assembly_functional_tool_diameter,
'knife_tip_r_angle': self.after_assembly_knife_tip_r_angle, 'knife_tip_r_angle': self.after_assembly_knife_tip_r_angle,