From da5e322229c4110981f8a2d50d66072971e6f68c Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 11 Sep 2024 17:49:43 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=BB=84=E8=A3=85=E5=8D=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BA=94=E7=A7=8D=E7=89=A9=E6=96=99=E7=9A=84=E3=80=90?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E3=80=91=E6=8C=89=E9=92=AE=EF=BC=8C=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC=E8=87=B3=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E5=BC=B9=E7=AA=97=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E6=B8=85=E5=8D=95?= =?UTF-8?q?BOM=E7=9A=84=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=87=BA=E5=85=A8=E9=83=A8=E6=BB=A1=E8=B6=B3=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=88=80=E6=9F=84=E4=BA=A7=E5=93=81=E6=88=96=E8=80=85?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E5=88=80=E5=85=B7=E7=89=A9=E6=96=99=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=89=B9=E6=AC=A1=E3=80=81=E8=B4=A7=E4=BD=8D?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8tree=E8=A7=86=E5=9B=BE=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E9=80=89=E6=8B=A9=E3=80=822=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BA=A7=E5=93=81tree=E3=80=81search=E8=A7=86?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/base.py | 48 +++++++++++++++++++- sf_tool_management/models/stock.py | 6 +++ sf_tool_management/views/tool_base_views.xml | 21 +++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) 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 @@