From 1b760f351efb7f5a7a9596d50a7b0b83c0ea0937 Mon Sep 17 00:00:00 2001 From: yueli Date: Fri, 4 Sep 2026 09:40:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=87=BA=E5=BA=93/=E5=80=9F=E5=BA=93?= =?UTF-8?q?=E6=89=AB=E7=A0=81=E6=9F=A5=E5=BA=93=E5=AD=98=E4=B8=8E=20BOM=20?= =?UTF-8?q?=E5=AD=90=E4=BB=B6=E7=89=A9=E6=96=99=E9=80=89=E6=8B=A9=E5=8A=A0?= =?UTF-8?q?=E8=A1=8C=E7=BA=A7=E5=85=AC=E5=8F=B8=E9=9A=94=E7=A6=BB=EF=BC=88?= =?UTF-8?q?=E8=B6=85=E7=AE=A1/=E8=B7=A8=E5=9F=9F=E4=B8=8D=E5=8F=97?= =?UTF-8?q?=E9=99=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/app/api/v1/bom.py | 6 ++++ .../app/services/outbound_service.py | 29 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/inventory-backend/app/api/v1/bom.py b/inventory-backend/app/api/v1/bom.py index 6b29d7f..b92462a 100644 --- a/inventory-backend/app/api/v1/bom.py +++ b/inventory-backend/app/api/v1/bom.py @@ -357,6 +357,12 @@ def get_material_base_list(): # 构建查询条件 query = MaterialBase.query.filter_by(is_enabled=True) + # ★ 行级公司隔离:普通用户只能选本公司的物料作为 BOM 子件(超管/跨域不受限) + from app.utils.decorators import get_current_company_filter + company_limit = get_current_company_filter() + if company_limit is not None: + query = query.filter(MaterialBase.company_name == company_limit) + # 添加关键字模糊搜索 if keyword: query = query.filter( diff --git a/inventory-backend/app/services/outbound_service.py b/inventory-backend/app/services/outbound_service.py index a3842f6..56a06b6 100644 --- a/inventory-backend/app/services/outbound_service.py +++ b/inventory-backend/app/services/outbound_service.py @@ -58,25 +58,42 @@ class OutboundService: return float(item.pre_tax_unit_price) if item.pre_tax_unit_price else 0 return 0 - prod = StockProduct.query.filter( + # ★ 行级公司隔离:扫码出库/借库只能命中本公司的库存(超管/跨域不受限) + from app.utils.decorators import get_current_company_filter + from app.models.base import MaterialBase + company_limit = get_current_company_filter() + + prod_q = StockProduct.query.filter( or_(StockProduct.barcode == clean_code, StockProduct.sku == clean_code) - ).first() + ) + if company_limit is not None: + prod_q = prod_q.join(MaterialBase, StockProduct.base_id == MaterialBase.id) \ + .filter(MaterialBase.company_name == company_limit) + prod = prod_q.first() if prod: res = OutboundService._format_scan_result(prod, 'stock_product') res['price'] = get_price(prod, 'stock_product') return res - semi = StockSemi.query.filter( + semi_q = StockSemi.query.filter( or_(StockSemi.barcode == clean_code, StockSemi.sku == clean_code) - ).first() + ) + if company_limit is not None: + semi_q = semi_q.join(MaterialBase, StockSemi.base_id == MaterialBase.id) \ + .filter(MaterialBase.company_name == company_limit) + semi = semi_q.first() if semi: res = OutboundService._format_scan_result(semi, 'stock_semi') res['price'] = 0 return res - buy = StockBuy.query.filter( + buy_q = StockBuy.query.filter( or_(StockBuy.barcode == clean_code, StockBuy.sku == clean_code) - ).first() + ) + if company_limit is not None: + buy_q = buy_q.join(MaterialBase, StockBuy.base_id == MaterialBase.id) \ + .filter(MaterialBase.company_name == company_limit) + buy = buy_q.first() if buy: res = OutboundService._format_scan_result(buy, 'stock_buy') res['price'] = get_price(buy, 'stock_buy')