mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/BE/US-278-purchase_adjustment_createOne' into 'development'
Fix/be/us 278 purchase adjustment createone See merge request mbugroup/lti-api!123
This commit is contained in:
+25
@@ -216,6 +216,31 @@ func (r *ProductWarehouseRepositoryImpl) CleanupEmpty(ctx context.Context, affec
|
||||
return nil
|
||||
}
|
||||
|
||||
var inUseIDs []uint
|
||||
if err := r.DB().WithContext(ctx).
|
||||
Model(&entity.PurchaseItem{}).
|
||||
Where("product_warehouse_id IN ?", emptyIDs).
|
||||
Distinct().
|
||||
Pluck("product_warehouse_id", &inUseIDs).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(inUseIDs) > 0 {
|
||||
inUse := make(map[uint]struct{}, len(inUseIDs))
|
||||
for _, id := range inUseIDs {
|
||||
inUse[id] = struct{}{}
|
||||
}
|
||||
filtered := make([]uint, 0, len(emptyIDs))
|
||||
for _, id := range emptyIDs {
|
||||
if _, exists := inUse[id]; !exists {
|
||||
filtered = append(filtered, id)
|
||||
}
|
||||
}
|
||||
emptyIDs = filtered
|
||||
}
|
||||
if len(emptyIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := r.DB().WithContext(ctx).
|
||||
Model(&entity.PurchaseItem{}).
|
||||
Where("product_warehouse_id IN ?", emptyIDs).
|
||||
|
||||
Reference in New Issue
Block a user