diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 4d7821ac..518c4c0f 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -925,7 +925,53 @@ class FunctionalToolAssembly(models.Model): else: raise ValidationError(f'功能刀具清单BOM的组装方式错误:【{options}】') - # def set_ + def set_tool_lot(self): + # 获取BOM的刀具物料产品信息 + tool_data = self._get_inventory_bom(self.tool_inventory_id) + + # 获取刀具类型 + tool_type = self.env.context.get('tool_type') + + if tool_type == '刀柄': + tool_material_ids = tool_data.get('handle_ids') + elif tool_type == '整体式刀具': + tool_material_ids = self._get_all_material_location_lot(tool_data.get('integral_ids')) + elif tool_type == '刀片': + tool_material_ids = self._get_all_material_location_lot(tool_data.get('handle_ids')) + elif tool_type == '刀杆': + tool_material_ids = self._get_all_material_location_lot(tool_data.get('bar_ids')) + else: + tool_material_ids = self._get_all_material_location_lot(tool_data.get('pad_ids')) + + if tool_type == '刀柄': + return { + "type": "ir.actions.act_window", + "res_model": "product.product", + "views": [[self.env.ref('sf_tool_management.view_tool_product_tree').id, "tree"], + [self.env.ref('sf_tool_management.view_tool_product_search').id, "search"]], + "target": "new", + "domain": [('id', 'in', tool_material_ids.ids)] + } + elif tool_type in ['整体式刀具', '刀片', '刀杆', '刀盘']: + return { + "type": "ir.actions.act_window", + "res_model": "sf.shelf.location.lot", + "views": [[False, "tree"]], + "target": "new", + "domain": [('id', 'in', tool_material_ids.ids)], + "context": {'create': False} + } + + def _get_all_material_location_lot(self, material_ids): + """ 获取所有满足条件 """ + location_id = self.env['stock.location'].search([('name', '=', '刀具房')]) + stock_quant_ids = self.env['stock.quant'].sudo().search( + [('location_id', '=', location_id.id), ('product_id', 'in', material_ids.ids), ('quantity', '>', '0')]) + lot_ids = [] + for stock_quant_id in stock_quant_ids: + lot_ids.append(stock_quant_id.lot_id.id) + location_lots = self.env['sf.shelf.location.lot'].sudo().search([('lot_id', 'in', lot_ids)]) + return location_lots def functional_tool_assembly(self): """ diff --git a/sf_tool_management/models/stock.py b/sf_tool_management/models/stock.py index 22a7fa72..50218e65 100644 --- a/sf_tool_management/models/stock.py +++ b/sf_tool_management/models/stock.py @@ -247,3 +247,9 @@ class ProductProduct(models.Model): m = int(stock_lot_id.name[-3:]) + 1 num = "%03d" % m return '%s-%s' % (code, num) + + +class SfShelfLocationLot(models.Model): + _inherit = 'sf.shelf.location.lot' + + diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml index bd4d949c..0c492721 100644 --- a/sf_tool_management/views/tool_base_views.xml +++ b/sf_tool_management/views/tool_base_views.xml @@ -524,6 +524,7 @@