From e9719a2b5b25ea59498a95b05a81e98d9ac3c83d Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 2 Apr 2025 13:47:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E7=BB=84?= =?UTF-8?q?=E8=A3=85=E6=97=B6=E8=87=AA=E5=8A=A8=E6=A0=B9=E6=8D=AEBOM?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=80=89=E5=8F=96=E7=89=A9=E6=96=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BC=98=E5=8C=96=E4=B8=BA=EF=BC=9A=E4=B8=80=E7=9B=B4?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E7=9B=B4=E5=88=B0=E6=89=BE=E5=88=B0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=BB=A1=E8=B6=B3=E6=9D=A1=E4=BB=B6=E7=9A=84=E7=89=A9?= =?UTF-8?q?=E6=96=99=E8=B4=A7=E4=BD=8D=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=B0=B1=E7=BB=99=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/base.py | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 40100a93..d1a990f1 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -791,48 +791,50 @@ class FunctionalToolAssembly(models.Model): # 刀柄之外的物料配置 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) + integra_lot_ids = self._get_old_tool_material_lot(bom.get('integral_ids')) + integra_location_lot_id = self._get_shelf_location_lot(integra_lot_ids) self.integral_freight_barcode_id = integra_location_lot_id.shelf_location_id.id self.integral_lot_id = integra_location_lot_id.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) + blade_lot_ids = self._get_old_tool_material_lot(bom.get('blade_ids')) + blade_location_lot_id = self._get_shelf_location_lot(blade_lot_ids) self.blade_freight_barcode_id = blade_location_lot_id.shelf_location_id.id self.blade_lot_id = blade_location_lot_id.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) + bar_lot_ids = self._get_old_tool_material_lot(bom.get('bar_ids')) + bar_location_lot_id = self._get_shelf_location_lot(bar_lot_ids) self.bar_freight_barcode_id = bar_location_lot_id.shelf_location_id.id self.bar_lot_id = bar_location_lot_id.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) + pad_lot_ids = self._get_old_tool_material_lot(bom.get('pad_ids')) + pad_location_lot_id = self._get_shelf_location_lot(pad_lot_ids) self.pad_freight_barcode_id = pad_location_lot_id.shelf_location_id.id self.pad_lot_id = pad_location_lot_id.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( + stock_quant_ids = 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 + order='lot_id') + if stock_quant_ids: + return [stock_quant_id.lot_id for stock_quant_id in stock_quant_ids] else: raise ValidationError(f'【{material_ids[0].cutting_tool_material_id.name}】物料库存不足,请先进行盘点或采购') - def _get_shelf_location_lot(self, lot_id): + def _get_shelf_location_lot(self, lot_ids): """根据所给的刀具物料批次号,返回一个刀具物料货位、批次信息""" - 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] + for lot_id in lot_ids: + location_lots = self.env['sf.shelf.location.lot'].sudo().search([('lot_id', '=', lot_id.id)]) + if location_lots: + return location_lots[0] + if lot_ids: + raise ValidationError( + f'【{lot_ids[0].product_id.cutting_tool_material_id.name}】物料在货位上库存不足,请先进行盘点或采购!') def _get_inventory_bom(self, inventory_id): """获取BOM的刀具物料产品信息"""