mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix: first push need support testing, and implemented fifo v2 to all modules
This commit is contained in:
@@ -487,7 +487,6 @@ func (s *fifoStockV2Service) Reflow(ctx context.Context, req ReflowRequest) (*Re
|
|||||||
if desiredQty <= 0 {
|
if desiredQty <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
allocateRes, allocateErr := s.allocateInternal(ctx, tx, AllocateRequest{
|
allocateRes, allocateErr := s.allocateInternal(ctx, tx, AllocateRequest{
|
||||||
FlagGroupCode: req.FlagGroupCode,
|
FlagGroupCode: req.FlagGroupCode,
|
||||||
ProductWarehouseID: req.ProductWarehouseID,
|
ProductWarehouseID: req.ProductWarehouseID,
|
||||||
|
|||||||
@@ -692,6 +692,9 @@ func (s *chickinService) ReplenishChickinStocks(ctx context.Context, tx *gorm.DB
|
|||||||
if tx == nil {
|
if tx == nil {
|
||||||
return errors.New("transaction is required")
|
return errors.New("transaction is required")
|
||||||
}
|
}
|
||||||
|
if s.FifoStockV2Svc == nil {
|
||||||
|
return errors.New("fifo v2 service is not available")
|
||||||
|
}
|
||||||
|
|
||||||
if err := tx.WithContext(ctx).
|
if err := tx.WithContext(ctx).
|
||||||
Model(&entity.ProjectFlockPopulation{}).
|
Model(&entity.ProjectFlockPopulation{}).
|
||||||
@@ -700,7 +703,11 @@ func (s *chickinService) ReplenishChickinStocks(ctx context.Context, tx *gorm.DB
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
asOf := chickin.ChickInDate
|
||||||
|
if asOf.IsZero() {
|
||||||
|
asOf = chickin.CreatedAt
|
||||||
|
}
|
||||||
|
return reflowChickinScope(ctx, s.FifoStockV2Svc, tx, targetPW.Id, &asOf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *chickinService) ReleaseChickinStocks(ctx context.Context, tx *gorm.DB, chickin *entity.ProjectChickin, actorID uint) error {
|
func (s *chickinService) ReleaseChickinStocks(ctx context.Context, tx *gorm.DB, chickin *entity.ProjectChickin, actorID uint) error {
|
||||||
@@ -779,8 +786,6 @@ func (s *chickinService) syncChickinTraceForProductWarehouse(ctx context.Context
|
|||||||
gatherRows, err := s.FifoStockV2Svc.Gather(ctx, commonSvc.FifoStockV2GatherRequest{
|
gatherRows, err := s.FifoStockV2Svc.Gather(ctx, commonSvc.FifoStockV2GatherRequest{
|
||||||
FlagGroupCode: flagGroupCode,
|
FlagGroupCode: flagGroupCode,
|
||||||
Lane: "STOCKABLE",
|
Lane: "STOCKABLE",
|
||||||
AllocationPurpose: entity.StockAllocationPurposeTraceChickin,
|
|
||||||
IgnoreSourceUsed: true,
|
|
||||||
ProductWarehouseID: productWarehouseID,
|
ProductWarehouseID: productWarehouseID,
|
||||||
Limit: 50000,
|
Limit: 50000,
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||||
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
chickinOutFunctionCode = "CHICKIN_OUT"
|
||||||
|
chickinUsableLane = "USABLE"
|
||||||
|
chickinSourceTable = "project_chickins"
|
||||||
|
)
|
||||||
|
|
||||||
|
func reflowChickinScope(
|
||||||
|
ctx context.Context,
|
||||||
|
fifoStockV2Svc commonSvc.FifoStockV2Service,
|
||||||
|
tx *gorm.DB,
|
||||||
|
productWarehouseID uint,
|
||||||
|
asOf *time.Time,
|
||||||
|
) error {
|
||||||
|
if fifoStockV2Svc == nil {
|
||||||
|
return fmt.Errorf("FIFO v2 service is not available")
|
||||||
|
}
|
||||||
|
if tx == nil {
|
||||||
|
return fmt.Errorf("transaction is required")
|
||||||
|
}
|
||||||
|
if productWarehouseID == 0 {
|
||||||
|
return fmt.Errorf("product warehouse id is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
flagGroupCode, err := resolveChickinFlagGroupByProductWarehouse(ctx, tx, productWarehouseID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(flagGroupCode) == "" {
|
||||||
|
return fmt.Errorf("flag group code is not found for product warehouse %d", productWarehouseID)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fifoStockV2Svc.Reflow(ctx, commonSvc.FifoStockV2ReflowRequest{
|
||||||
|
FlagGroupCode: flagGroupCode,
|
||||||
|
ProductWarehouseID: productWarehouseID,
|
||||||
|
AsOf: asOf,
|
||||||
|
Tx: tx,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveChickinFlagGroupByProductWarehouse(ctx context.Context, tx *gorm.DB, productWarehouseID uint) (string, error) {
|
||||||
|
type row struct {
|
||||||
|
FlagGroupCode string `gorm:"column:flag_group_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected row
|
||||||
|
err := tx.WithContext(ctx).
|
||||||
|
Table("fifo_stock_v2_route_rules rr").
|
||||||
|
Select("rr.flag_group_code").
|
||||||
|
Joins("JOIN fifo_stock_v2_flag_groups fg ON fg.code = rr.flag_group_code AND fg.is_active = TRUE").
|
||||||
|
Where("rr.is_active = TRUE").
|
||||||
|
Where("rr.lane = ?", chickinUsableLane).
|
||||||
|
Where("rr.function_code = ?", chickinOutFunctionCode).
|
||||||
|
Where("rr.source_table = ?", chickinSourceTable).
|
||||||
|
Where(`
|
||||||
|
EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM product_warehouses pw
|
||||||
|
JOIN flags f ON f.flagable_id = pw.product_id
|
||||||
|
JOIN fifo_stock_v2_flag_members fm ON fm.flag_name = f.name AND fm.is_active = TRUE
|
||||||
|
WHERE pw.id = ?
|
||||||
|
AND f.flagable_type = ?
|
||||||
|
AND fm.flag_group_code = rr.flag_group_code
|
||||||
|
)
|
||||||
|
`, productWarehouseID, entity.FlagableTypeProduct).
|
||||||
|
Order("rr.id ASC").
|
||||||
|
Limit(1).
|
||||||
|
Take(&selected).Error
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimSpace(selected.FlagGroupCode), nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user