Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37607 amit 1
-- Remove vendor catalog pricing held against INTERNAL suppliers (2026-09-12)
2
--
3
-- WHY
4
--   Internal suppliers are our own warehouses. They never negotiated a price with anyone - every row they
5
--   hold was copied there from some other vendor, which is exactly what made internal movement prices drift
6
--   further from reality on each hop. Since r37603-05 nothing reads them: an internal movement is priced
7
--   from the stock being moved, resolved back to the ORIGINAL EXTERNAL vendor, and receiving no longer
8
--   validates price for those movements at all. The rows are now worse than useless - a stale one would
9
--   silently win over the derived price if any lookup were ever reintroduced.
10
--
11
-- ORDERING - deploy the fofo WAR carrying the warehouse-grn-request-items.vm fix FIRST.
12
--   That template rendered $vendorCatalogPricingLogMap.get($catalogId).getTransferPrice() with no null
13
--   guard, so with these rows gone every internal-supplier GRN line would print the raw reference text in
14
--   the System Price column. Velocity fails quietly, so it would not error - it would just look broken.
15
--   The fix renders "-" instead, which is honest: there is no independent system price for an internal
16
--   movement. V2FofoGrnController returns the same map as JSON and is unaffected by an empty map.
17
--
18
-- REVERSIBLE: every deleted row is copied to a _bak_ table first. To restore, INSERT ... SELECT back.
19
--   Membership is frozen into the backups at run time, so a supplier whose internal flag changes later
20
--   cannot silently widen or narrow what was removed.
21
 
22
CREATE TABLE inventory._bak_vcp_internal_20260912 AS
23
SELECT p.* FROM inventory.vendor_catalog_pricing p
24
  JOIN warehouse.supplier s ON s.id = p.vendor_id AND s.internal = 1;
25
 
26
CREATE TABLE inventory._bak_vcpl_internal_20260912 AS
27
SELECT l.* FROM inventory.vendor_catalog_pricing_log l
28
  JOIN warehouse.supplier s ON s.id = l.vendor_id AND s.internal = 1;
29
 
30
CREATE TABLE inventory._bak_vip_internal_20260912 AS
31
SELECT v.* FROM inventory.vendoritempricing v
32
  JOIN warehouse.supplier s ON s.id = v.vendor_id AND s.internal = 1;
33
 
34
-- Expected as of 2026-09-12: 12,372 / 17,241 / 33,252 rows across 16 internal suppliers.
35
SELECT (SELECT COUNT(*) FROM inventory._bak_vcp_internal_20260912)  AS pricing_backed_up,
36
       (SELECT COUNT(*) FROM inventory._bak_vcpl_internal_20260912) AS log_backed_up,
37
       (SELECT COUNT(*) FROM inventory._bak_vip_internal_20260912)  AS itempricing_backed_up;
38
 
39
-- Delete against the frozen backups rather than re-reading supplier.internal, so the rows removed are
40
-- exactly the rows preserved.
41
DELETE p FROM inventory.vendor_catalog_pricing p
42
  JOIN inventory._bak_vcp_internal_20260912 b
43
    ON b.vendor_id = p.vendor_id AND b.catalog_id = p.catalog_id;
44
 
45
DELETE l FROM inventory.vendor_catalog_pricing_log l
46
  JOIN inventory._bak_vcpl_internal_20260912 b ON b.id = l.id;
47
 
48
DELETE v FROM inventory.vendoritempricing v
49
  JOIN inventory._bak_vip_internal_20260912 b
50
    ON b.vendor_id = v.vendor_id AND b.item_id = v.item_id;
51
 
52
-- Verify: all three must be 0.
53
SELECT (SELECT COUNT(*) FROM inventory.vendor_catalog_pricing p
54
          JOIN warehouse.supplier s ON s.id = p.vendor_id AND s.internal = 1) AS pricing_left,
55
       (SELECT COUNT(*) FROM inventory.vendor_catalog_pricing_log l
56
          JOIN warehouse.supplier s ON s.id = l.vendor_id AND s.internal = 1) AS log_left,
57
       (SELECT COUNT(*) FROM inventory.vendoritempricing v
58
          JOIN warehouse.supplier s ON s.id = v.vendor_id AND s.internal = 1) AS itempricing_left;
59
 
60
-- Rollback:
61
-- INSERT INTO inventory.vendor_catalog_pricing     SELECT * FROM inventory._bak_vcp_internal_20260912;
62
-- INSERT INTO inventory.vendor_catalog_pricing_log SELECT * FROM inventory._bak_vcpl_internal_20260912;
63
-- INSERT INTO inventory.vendoritempricing          SELECT * FROM inventory._bak_vip_internal_20260912;