mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
Merge branch 'cmd/consolidate-and-repoint-stocks' into 'development'
cmd: skip consolidation for incomplete locations (locations without farm-level warehouse) See merge request mbugroup/lti-api!450
This commit is contained in:
@@ -33,6 +33,7 @@ type options struct {
|
||||
DBSSLMode string
|
||||
DeleteKandangWarehouses bool
|
||||
SkipBlockedRefsCheck bool
|
||||
SkipIncompleteLocations bool
|
||||
}
|
||||
|
||||
type consolidateRow struct {
|
||||
@@ -159,6 +160,7 @@ func parseFlags() (*options, error) {
|
||||
flag.StringVar(&opts.DBSSLMode, "db-sslmode", "", "Optional database sslmode override, for example: require")
|
||||
flag.BoolVar(&opts.DeleteKandangWarehouses, "delete-kandang-warehouses", true, "Soft delete kandang warehouse rows after all stocks have been moved")
|
||||
flag.BoolVar(&opts.SkipBlockedRefsCheck, "skip-blocked-refs-check", false, "Skip blocked references check (use with caution - only if you understand the stock_transfers references)")
|
||||
flag.BoolVar(&opts.SkipIncompleteLocations, "skip-incomplete-locations", false, "Skip locations that don't have farm-level warehouses and process the rest")
|
||||
flag.Parse()
|
||||
|
||||
opts.Output = strings.ToLower(strings.TrimSpace(opts.Output))
|
||||
@@ -188,6 +190,12 @@ func loadConsolidateRows(ctx context.Context, db *gorm.DB, opts *options) ([]con
|
||||
args = append(args, opts.KandangLocationName)
|
||||
}
|
||||
|
||||
// If skipping incomplete locations, filter out NULL farm warehouses
|
||||
whereClause := ""
|
||||
if opts.SkipIncompleteLocations {
|
||||
whereClause = "AND fw.id IS NOT NULL"
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
SELECT
|
||||
a.name AS area_name,
|
||||
@@ -251,8 +259,11 @@ WHERE w.deleted_at IS NULL
|
||||
AND sa.deleted_at IS NULL
|
||||
)
|
||||
%s
|
||||
%s
|
||||
ORDER BY a.name ASC, kl.name ASC, k.name ASC, wp.id ASC
|
||||
`, andClause(filters))
|
||||
`,
|
||||
andClause(filters),
|
||||
whereClause)
|
||||
|
||||
rows := make([]consolidateRow, 0)
|
||||
if err := db.WithContext(ctx).Raw(query, args...).Scan(&rows).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user