Subversion Repositories SmartDukaan

Rev

Rev 37607 | Details | Compare with Previous | 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
 
37608 amit 22
-- Multi-table DELETE (the "DELETE alias FROM" form) needs a default schema even when every table is
23
-- fully qualified, so select one up front rather than relying on how the client was invoked.
24
USE inventory;
25
 
37607 amit 26
CREATE TABLE inventory._bak_vcp_internal_20260912 AS
27
SELECT p.* FROM inventory.vendor_catalog_pricing p
28
  JOIN warehouse.supplier s ON s.id = p.vendor_id AND s.internal = 1;
29
 
30
CREATE TABLE inventory._bak_vcpl_internal_20260912 AS
31
SELECT l.* FROM inventory.vendor_catalog_pricing_log l
32
  JOIN warehouse.supplier s ON s.id = l.vendor_id AND s.internal = 1;
33
 
34
CREATE TABLE inventory._bak_vip_internal_20260912 AS
35
SELECT v.* FROM inventory.vendoritempricing v
36
  JOIN warehouse.supplier s ON s.id = v.vendor_id AND s.internal = 1;
37
 
38
-- Expected as of 2026-09-12: 12,372 / 17,241 / 33,252 rows across 16 internal suppliers.
39
SELECT (SELECT COUNT(*) FROM inventory._bak_vcp_internal_20260912)  AS pricing_backed_up,
40
       (SELECT COUNT(*) FROM inventory._bak_vcpl_internal_20260912) AS log_backed_up,
41
       (SELECT COUNT(*) FROM inventory._bak_vip_internal_20260912)  AS itempricing_backed_up;
42
 
43
-- Delete against the frozen backups rather than re-reading supplier.internal, so the rows removed are
44
-- exactly the rows preserved.
45
DELETE p FROM inventory.vendor_catalog_pricing p
46
  JOIN inventory._bak_vcp_internal_20260912 b
47
    ON b.vendor_id = p.vendor_id AND b.catalog_id = p.catalog_id;
48
 
49
DELETE l FROM inventory.vendor_catalog_pricing_log l
50
  JOIN inventory._bak_vcpl_internal_20260912 b ON b.id = l.id;
51
 
52
DELETE v FROM inventory.vendoritempricing v
53
  JOIN inventory._bak_vip_internal_20260912 b
54
    ON b.vendor_id = v.vendor_id AND b.item_id = v.item_id;
55
 
56
-- Verify: all three must be 0.
57
SELECT (SELECT COUNT(*) FROM inventory.vendor_catalog_pricing p
58
          JOIN warehouse.supplier s ON s.id = p.vendor_id AND s.internal = 1) AS pricing_left,
59
       (SELECT COUNT(*) FROM inventory.vendor_catalog_pricing_log l
60
          JOIN warehouse.supplier s ON s.id = l.vendor_id AND s.internal = 1) AS log_left,
61
       (SELECT COUNT(*) FROM inventory.vendoritempricing v
62
          JOIN warehouse.supplier s ON s.id = v.vendor_id AND s.internal = 1) AS itempricing_left;
63
 
64
-- Rollback:
65
-- INSERT INTO inventory.vendor_catalog_pricing     SELECT * FROM inventory._bak_vcp_internal_20260912;
66
-- INSERT INTO inventory.vendor_catalog_pricing_log SELECT * FROM inventory._bak_vcpl_internal_20260912;
67
-- INSERT INTO inventory.vendoritempricing          SELECT * FROM inventory._bak_vip_internal_20260912;