mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'codex/sales-at-farm-level' into 'development'
codex/fix: qty 0 after PO to farm-level warehouse See merge request mbugroup/lti-api!385
This commit is contained in:
@@ -47,6 +47,17 @@ func reflowPurchaseScope(
|
||||
AsOf: asOf,
|
||||
Tx: tx,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fifoStockV2Svc.Recalculate(ctx, commonSvc.FifoStockV2RecalculateRequest{
|
||||
ProductWarehouseIDs: []uint{productWarehouseID},
|
||||
FlagGroupCodes: []string{flagGroupCode},
|
||||
AsOf: asOf,
|
||||
FixDrift: true,
|
||||
Tx: tx,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -34,6 +35,68 @@ func TestResolvePurchaseFlagGroupByProductWarehouseUsesProductFlagsWhenPresent(t
|
||||
}
|
||||
}
|
||||
|
||||
func TestReflowPurchaseScopeRunsRecalculateToFixWarehouseDrift(t *testing.T) {
|
||||
db := setupPurchaseFifoHelperTestDB(t)
|
||||
ctx := context.Background()
|
||||
fifo := &purchaseFifoStub{}
|
||||
|
||||
if err := reflowPurchaseScope(ctx, fifo, db, 1115, nil); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(fifo.reflowReqs) != 1 {
|
||||
t.Fatalf("expected 1 reflow request, got %d", len(fifo.reflowReqs))
|
||||
}
|
||||
reflowReq := fifo.reflowReqs[0]
|
||||
if reflowReq.ProductWarehouseID != 1115 {
|
||||
t.Fatalf("expected reflow product warehouse 1115, got %d", reflowReq.ProductWarehouseID)
|
||||
}
|
||||
if reflowReq.FlagGroupCode != "PAKAN" {
|
||||
t.Fatalf("expected reflow flag group PAKAN, got %s", reflowReq.FlagGroupCode)
|
||||
}
|
||||
|
||||
if len(fifo.recalculateReqs) != 1 {
|
||||
t.Fatalf("expected 1 recalculate request, got %d", len(fifo.recalculateReqs))
|
||||
}
|
||||
recalculateReq := fifo.recalculateReqs[0]
|
||||
if len(recalculateReq.ProductWarehouseIDs) != 1 || recalculateReq.ProductWarehouseIDs[0] != 1115 {
|
||||
t.Fatalf("expected recalculate for warehouse 1115, got %+v", recalculateReq.ProductWarehouseIDs)
|
||||
}
|
||||
if len(recalculateReq.FlagGroupCodes) != 1 || recalculateReq.FlagGroupCodes[0] != "PAKAN" {
|
||||
t.Fatalf("expected recalculate for PAKAN, got %+v", recalculateReq.FlagGroupCodes)
|
||||
}
|
||||
if !recalculateReq.FixDrift {
|
||||
t.Fatalf("expected recalculate FixDrift=true")
|
||||
}
|
||||
}
|
||||
|
||||
type purchaseFifoStub struct {
|
||||
reflowReqs []commonSvc.FifoStockV2ReflowRequest
|
||||
recalculateReqs []commonSvc.FifoStockV2RecalculateRequest
|
||||
}
|
||||
|
||||
func (s *purchaseFifoStub) Gather(context.Context, commonSvc.FifoStockV2GatherRequest) ([]commonSvc.FifoStockV2GatherRow, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *purchaseFifoStub) Allocate(context.Context, commonSvc.FifoStockV2AllocateRequest) (*commonSvc.FifoStockV2AllocateResult, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *purchaseFifoStub) Rollback(context.Context, commonSvc.FifoStockV2RollbackRequest) (*commonSvc.FifoStockV2RollbackResult, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *purchaseFifoStub) Reflow(_ context.Context, req commonSvc.FifoStockV2ReflowRequest) (*commonSvc.FifoStockV2ReflowResult, error) {
|
||||
s.reflowReqs = append(s.reflowReqs, req)
|
||||
return &commonSvc.FifoStockV2ReflowResult{}, nil
|
||||
}
|
||||
|
||||
func (s *purchaseFifoStub) Recalculate(_ context.Context, req commonSvc.FifoStockV2RecalculateRequest) (*commonSvc.FifoStockV2RecalculateResult, error) {
|
||||
s.recalculateReqs = append(s.recalculateReqs, req)
|
||||
return &commonSvc.FifoStockV2RecalculateResult{}, nil
|
||||
}
|
||||
|
||||
func setupPurchaseFifoHelperTestDB(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user