mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
fix: chickin include stock allocation, fix calculation hpp
This commit is contained in:
@@ -48,6 +48,8 @@ func (s *fifoStockV2Service) Gather(ctx context.Context, req GatherRequest) ([]G
|
||||
}
|
||||
|
||||
func (s *fifoStockV2Service) gatherRows(ctx context.Context, tx *gorm.DB, req GatherRequest) ([]GatherRow, error) {
|
||||
req.AllocationPurpose = normalizeAllocationPurpose(req.AllocationPurpose)
|
||||
|
||||
rules, err := s.loadRouteRules(ctx, tx, req.FlagGroupCode, req.Lane)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -155,7 +157,7 @@ func (s *fifoStockV2Service) buildGatherSubquery(rule routeRule, trait traitRule
|
||||
whereExtraArgs := make([]any, 0, 1)
|
||||
|
||||
if req.Lane == LaneStockable {
|
||||
if rule.UsedQuantityCol != nil && strings.TrimSpace(*rule.UsedQuantityCol) != "" {
|
||||
if !req.IgnoreSourceUsed && rule.UsedQuantityCol != nil && strings.TrimSpace(*rule.UsedQuantityCol) != "" {
|
||||
usedCol, _ := mustSafeIdentifier(*rule.UsedQuantityCol)
|
||||
usedExpr = fmt.Sprintf("COALESCE(src.%s,0)::numeric", usedCol)
|
||||
} else {
|
||||
@@ -167,13 +169,13 @@ func (s *fifoStockV2Service) buildGatherSubquery(rule routeRule, trait traitRule
|
||||
// We split the args because the WHERE placeholder order appears
|
||||
// after product/flag filter placeholders in the final SQL.
|
||||
usedExpr = fmt.Sprintf(
|
||||
"(SELECT COALESCE(SUM(sa.qty),0)::numeric FROM stock_allocations sa WHERE sa.stockable_type = ? AND sa.stockable_id = src.%s AND sa.status = '%s')",
|
||||
"(SELECT COALESCE(SUM(sa.qty),0)::numeric FROM stock_allocations sa WHERE sa.stockable_type = ? AND sa.stockable_id = src.%s AND sa.status = '%s' AND sa.allocation_purpose = ?)",
|
||||
sourceIDCol,
|
||||
activeAllocationStatus(),
|
||||
)
|
||||
extraArgs = append(extraArgs, rule.LegacyTypeKey)
|
||||
extraArgs = append(extraArgs, rule.LegacyTypeKey)
|
||||
whereExtraArgs = append(whereExtraArgs, rule.LegacyTypeKey)
|
||||
extraArgs = append(extraArgs, rule.LegacyTypeKey, req.AllocationPurpose)
|
||||
extraArgs = append(extraArgs, rule.LegacyTypeKey, req.AllocationPurpose)
|
||||
whereExtraArgs = append(whereExtraArgs, rule.LegacyTypeKey, req.AllocationPurpose)
|
||||
}
|
||||
availableExpr = fmt.Sprintf("(%s - %s)", baseQtyExpr, usedExpr)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user