From e2d741937e9eff81683aefa5b19e559833c250fc Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 10 Sep 2024 17:52:40 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=9E=E7=8E=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=88=80=E5=85=B7=E7=82=B9=E5=87=BB=E5=BC=80=E5=A7=8B=E7=BB=84?= =?UTF-8?q?=E8=A3=85=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E6=B8=85=E5=8D=95BOM?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=B9=B6=E6=A0=B9=E6=8D=AE=E8=A7=84?= =?UTF-8?q?=E5=88=99=E5=8C=B9=E9=85=8D=E5=88=80=E5=85=B7=E7=89=A9=E6=96=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BF=9B=E8=A1=8C=E4=BF=A1=E6=81=AF=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=EF=BC=9B2=E3=80=81=E5=AF=B9=E7=BB=84?= =?UTF-8?q?=E8=A3=85=E5=8D=95form=E7=95=8C=E9=9D=A2=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E5=B9=B6=E9=9A=90=E8=97=8F=E5=A4=B9?= =?UTF-8?q?=E5=A4=B4=E7=89=A9=E6=96=99=E7=9A=84=E6=89=80=E4=BB=A5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/base.py | 118 +++++++++++++++- sf_tool_management/views/tool_base_views.xml | 136 +++++++++---------- 2 files changed, 179 insertions(+), 75 deletions(-) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 4c61bfe4..4d7821ac 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -493,11 +493,13 @@ class FunctionalToolAssembly(models.Model): for item in self: item.integral_freight_lot_id = False - @api.depends('integral_freight_lot_id') + @api.depends('integral_freight_lot_id', 'integral_freight_barcode_id') def _compute_integral_lot_id(self): for item in self: if item.integral_freight_lot_id: item.integral_lot_id = item.integral_freight_lot_id.lot_id.id + elif not item.integral_freight_barcode_id: + item.integral_lot_id = False @api.depends('integral_lot_id') def _compute_integral_product_id(self): @@ -527,11 +529,13 @@ class FunctionalToolAssembly(models.Model): for item in self: item.blade_freight_lot_id = False - @api.depends('blade_freight_lot_id') + @api.depends('blade_freight_lot_id', 'blade_freight_barcode_id') def _compute_blade_lot_id(self): for item in self: if item.blade_freight_lot_id: item.blade_lot_id = item.blade_freight_lot_id.lot_id.id + elif not item.blade_freight_barcode_id: + item.blade_lot_id = False @api.depends('blade_lot_id') def _compute_blade_product_id(self): @@ -561,11 +565,13 @@ class FunctionalToolAssembly(models.Model): for item in self: item.bar_freight_lot_id = False - @api.depends('bar_freight_lot_id') + @api.depends('bar_freight_lot_id', 'bar_freight_barcode_id') def _compute_bar_lot_id(self): for item in self: if item.bar_freight_lot_id: item.bar_lot_id = item.bar_freight_lot_id.lot_id.id + elif not item.bar_freight_barcode_id: + item.bar_lot_id = False @api.depends('bar_lot_id') def _compute_bar_product_id(self): @@ -595,11 +601,13 @@ class FunctionalToolAssembly(models.Model): for item in self: item.pad_freight_lot_id = False - @api.depends('pad_freight_lot_id') + @api.depends('pad_freight_lot_id', 'pad_freight_barcode_id') def _compute_pad_lot_id(self): for item in self: if item.pad_freight_lot_id: item.pad_lot_id = item.pad_freight_lot_id.lot_id.id + elif not item.pad_freight_barcode_id: + item.pad_lot_id = False @api.depends('pad_lot_id') def _compute_pad_product_id(self): @@ -655,11 +663,13 @@ class FunctionalToolAssembly(models.Model): for item in self: item.chuck_freight_lot_id = False - @api.depends('chuck_freight_lot_id') + @api.depends('chuck_freight_lot_id', 'chuck_freight_barcode_id') def _compute_chuck_lot_id(self): for item in self: if item.chuck_freight_lot_id: item.chuck_lot_id = item.chuck_freight_lot_id.lot_id.id + elif not item.chuck_freight_barcode_id: + item.chuck_lot_id = False @api.depends('chuck_lot_id') def _compute_chuck_product_id(self): @@ -819,7 +829,103 @@ class FunctionalToolAssembly(models.Model): self.after_assembly_coarse_middle_thin = '3' self.after_assembly_new_former = '0' - # todo 调用功能刀具名称对应的清单的BOM获取对应刀具物料信息 + # 调用功能刀具名称对应的清单的BOM获取对应刀具物料信息 + bom = self._get_inventory_bom(self.tool_inventory_id) + # 根据BOM自动配置物料的值 + self._set_tool_material(bom) + logging.info('功能刀具开始组装初始化值成功!') + + def _set_tool_material(self, bom): + """根据BOM对刀具物料进行初始配置""" + options = bom.get('options') + # 配置刀柄信息 + for handle_id in bom.get('handle_ids'): + if handle_id: + self.handle_product_id = handle_id.id + break + + # 刀柄之外的物料配置 + if options == '刀柄+整体式刀具': + # 配置整体式刀具 + integra_lot_id = self._get_old_tool_material_lot(bom.get('integral_ids')) + integra_location_lot_id = self._get_shelf_location_lot(integra_lot_id) + self.integral_freight_barcode_id = integra_location_lot_id.shelf_location_id.id + self.integral_freight_lot_id = integra_location_lot_id.id + else: + # 配置刀片 + blade_lot_id = self._get_old_tool_material_lot(bom.get('blade_ids')) + blade_location_lot_id = self._get_shelf_location_lot(blade_lot_id) + self.blade_freight_barcode_id = blade_location_lot_id.shelf_location_id.id + self.blade_freight_lot_id = blade_location_lot_id.id + + if options == '刀柄+刀杆+刀片': + # 配置刀杆 + bar_lot_id = self._get_old_tool_material_lot(bom.get('bar_ids')) + bar_location_lot_id = self._get_shelf_location_lot(bar_lot_id) + self.bar_freight_barcode_id = bar_location_lot_id.shelf_location_id.id + self.bar_freight_lot_id = bar_location_lot_id.id + elif options == '刀柄+刀盘+刀片': + # 配置刀盘 + pad_lot_id = self._get_old_tool_material_lot(bom.get('pad_ids')) + pad_location_lot_id = self._get_shelf_location_lot(pad_lot_id) + self.pad_freight_barcode_id = pad_location_lot_id.shelf_location_id.id + self.pad_freight_lot_id = pad_location_lot_id.id + + def _get_old_tool_material_lot(self, material_ids): + """ 根据先进先出原则选择物料批次 """ + location_id = self.env['stock.location'].search([('name', '=', '刀具房')]) + stock_quant = self.env['stock.quant'].sudo().search( + [('location_id', '=', location_id.id), ('product_id', 'in', material_ids.ids), ('quantity', '>', '0')], + order='lot_id', limit=1) + if stock_quant: + return stock_quant.lot_id + else: + raise ValidationError(f'【{material_ids[0].cutting_tool_material_id.name}】物料库存不足,请先进行盘点或采购') + + def _get_shelf_location_lot(self, lot_id): + """根据所给的刀具物料批次号,返回一个刀具物料货位、批次信息""" + location_lots = self.env['sf.shelf.location.lot'].sudo().search([('lot_id', '=', lot_id.id)]) + if not location_lots: + raise ValidationError(f'没有查询到批次为【{lot_id.name}】物料的货位信息!') + else: + return location_lots[0] + + def _get_inventory_bom(self, inventory_id): + """获取BOM的刀具物料产品信息""" + product_ids = inventory_id.jikimo_bom_ids.product_ids # BOM配置的物料产品 + options = inventory_id.jikimo_bom_ids.options # BOM产品组装类型 + + if not product_ids or not options: + raise ValidationError('功能刀具清单的BOM未进行配置,请先配置BOM再开始组装!') + handle_ids = product_ids.filtered(lambda a: a.cutting_tool_material_id.name == '刀柄') + integral_ids = product_ids.filtered(lambda a: a.cutting_tool_material_id.name == '整体式刀具') + blade_ids = product_ids.filtered(lambda a: a.cutting_tool_material_id.name == '刀片') + bar_ids = product_ids.filtered(lambda a: a.cutting_tool_material_id.name == '刀杆') + pad_ids = product_ids.filtered(lambda a: a.cutting_tool_material_id.name == '刀盘') + + if not handle_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀柄]信息,请先配置BOM再开始组装!') + + if options == '刀柄+整体式刀具': + if not integral_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀柄]信息,请先配置BOM再开始组装!') + return {'options': options, 'handle_ids': handle_ids, 'integral_ids': integral_ids} + elif options == '刀柄+刀杆+刀片': + if not blade_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀片]信息,请先配置BOM再开始组装!') + if not bar_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀杆]信息,请先配置BOM再开始组装!') + return {'options': options, 'handle_ids': handle_ids, 'blade_ids': blade_ids, 'bar_ids': bar_ids} + elif options == '刀柄+刀盘+刀片': + if not blade_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀片]信息,请先配置BOM再开始组装!') + if not pad_ids: + raise ValidationError('功能刀具清单的BOM未配置[刀盘]信息,请先配置BOM再开始组装!') + return {'options': options, 'handle_ids': handle_ids, 'blade_ids': blade_ids, 'pad_ids': pad_ids} + else: + raise ValidationError(f'功能刀具清单BOM的组装方式错误:【{options}】') + + # def set_ def functional_tool_assembly(self): """ diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml index 46f557d7..bd4d949c 100644 --- a/sf_tool_management/views/tool_base_views.xml +++ b/sf_tool_management/views/tool_base_views.xml @@ -520,81 +520,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - + + + + + - - - - - - - - - - - - - - - - @@ -634,6 +574,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +