diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 72be50dd..3d9ec5ee 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -782,10 +782,11 @@ class FunctionalToolAssembly(models.Model): """根据BOM对刀具物料进行初始配置""" options = bom.get('options') # 配置刀柄信息 - for handle_id in bom.get('handle_ids'): + handle_ids = self._get_old_tool_material_lot(bom.get('handle_ids')) + for handle_id in handle_ids: if handle_id: if not self.handle_product_id: - self.handle_product_id = handle_id.id + self.handle_product_id = handle_id.product_id.id break # 刀柄之外的物料配置 @@ -820,19 +821,20 @@ class FunctionalToolAssembly(models.Model): 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) + order='lot_id') if stock_quant: - return stock_quant.lot_id + return [quant.lot_id for quant in stock_quant] 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] + raise ValidationError(f'【{lot_ids[0].product_id.cutting_tool_material_id.name}】物料在货位库存不足,请先进行盘点入库') + def _get_inventory_bom(self, inventory_id): """获取BOM的刀具物料产品信息"""