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')