Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

-- Seed Dummy/GOOD/OURS warehouses under fallback vendor (id = 40) for every billing region
-- in ProfitMandiConstants.WAREHOUSE_MAP that doesn't already have one.
--
-- Phantom order allocations (placement when stock is insufficient or missing) route to the
-- Dummy warehouse for the partner's billing region. This guarantees every region has a
-- deterministic phantom target; going forward WarehouseServiceImpl.ensureDummyForBillingRegion
-- auto-creates Dummies when a new billing region's first warehouse is created.
--
-- Idempotent: uses NOT EXISTS to skip regions that already have a Dummy (the 5 pre-existing
-- regions with coverage: 7, 7441, 7573, 9203, 9213).
--
-- Applied on: hadb1 (remote) and local 127.0.0.1 as part of this refactor.

INSERT INTO inventory.warehouse
    (displayName, vendor_id, billingWarehouseId, shippingWarehouseId,
     inventoryType, warehouseType, status, billingType,
     state_id, addedOn, lastCheckedOn)
SELECT
    CONCAT(bw.displayName, '/Dummy/G'),
    40,
    bw.id,
    bw.id,
    'GOOD',
    'OURS',
    3,
    0,
    bw.state_id,
    NOW(),
    NOW()
FROM inventory.warehouse bw
WHERE bw.id IN (7720, 8947, 8468, 7678, 9349, 8889, 9470, 9513, 9514,
                10010, 10516, 10519, 10520, 10521)
  AND NOT EXISTS (
    SELECT 1 FROM inventory.warehouse w
    WHERE w.vendor_id = 40 AND w.billingWarehouseId = bw.id
      AND w.inventoryType = 'GOOD' AND w.warehouseType = 'OURS'
  );

-- Verify coverage:
-- SELECT billingWarehouseId, id, displayName
-- FROM inventory.warehouse
-- WHERE vendor_id = 40 AND inventoryType='GOOD' AND warehouseType='OURS'
-- ORDER BY billingWarehouseId;