fix: BOM 匹配库存(bom_match_stock)加行级公司隔离(三表按 base 公司过滤,超管/跨域不受限)
This commit is contained in:
@ -215,6 +215,11 @@ def bom_match_stock():
|
||||
# 去重
|
||||
child_ids = list(set(int(x) for x in child_ids))
|
||||
|
||||
# ★ 行级公司隔离:普通用户只能匹配本公司的库存(超管/跨域不受限)
|
||||
from app.utils.decorators import get_current_company_filter
|
||||
from app.models.base import MaterialBase
|
||||
company_limit = get_current_company_filter()
|
||||
|
||||
from app.models.inbound.buy import StockBuy
|
||||
from app.models.inbound.semi import StockSemi
|
||||
from app.models.inbound.product import StockProduct
|
||||
@ -226,7 +231,10 @@ def bom_match_stock():
|
||||
buy_items = StockBuy.query.filter(
|
||||
StockBuy.base_id.in_(child_ids),
|
||||
StockBuy.stock_quantity > 0
|
||||
).options(joinedload(StockBuy.base)).all()
|
||||
)
|
||||
if company_limit is not None:
|
||||
buy_items = buy_items.filter(StockBuy.base.has(MaterialBase.company_name == company_limit))
|
||||
buy_items = buy_items.options(joinedload(StockBuy.base)).all()
|
||||
for s in buy_items:
|
||||
d = s.to_dict()
|
||||
d['type'] = 'material'
|
||||
@ -242,7 +250,10 @@ def bom_match_stock():
|
||||
semi_items = StockSemi.query.filter(
|
||||
StockSemi.base_id.in_(child_ids),
|
||||
StockSemi.stock_quantity > 0
|
||||
).options(joinedload(StockSemi.base)).all()
|
||||
)
|
||||
if company_limit is not None:
|
||||
semi_items = semi_items.filter(StockSemi.base.has(MaterialBase.company_name == company_limit))
|
||||
semi_items = semi_items.options(joinedload(StockSemi.base)).all()
|
||||
for s in semi_items:
|
||||
d = s.to_dict()
|
||||
d['type'] = 'semi'
|
||||
@ -260,7 +271,10 @@ def bom_match_stock():
|
||||
prod_items = StockProduct.query.filter(
|
||||
StockProduct.base_id.in_(child_ids),
|
||||
StockProduct.stock_quantity > 0
|
||||
).options(joinedload(StockProduct.base)).all()
|
||||
)
|
||||
if company_limit is not None:
|
||||
prod_items = prod_items.filter(StockProduct.base.has(MaterialBase.company_name == company_limit))
|
||||
prod_items = prod_items.options(joinedload(StockProduct.base)).all()
|
||||
for s in prod_items:
|
||||
d = s.to_dict()
|
||||
d['type'] = 'product'
|
||||
|
||||
Reference in New Issue
Block a user