BEGIN;

-- ============================================================
-- MERGE: Add partner_id from partner_mapping into the original model,
-- then archive the duplicate partner_mapping
-- ============================================================

-- Ability Members: merge 68 → 20
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 68) WHERE id = 20;
UPDATE account_reconcile_model SET active = false WHERE id = 68;

-- ADT Security: merge 73 → 25
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 73) WHERE id = 25;
UPDATE account_reconcile_model SET active = false WHERE id = 73;

-- ATM fee: merge 54 → 3
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 54) WHERE id = 3;
UPDATE account_reconcile_model SET active = false WHERE id = 54;

-- BC FEE: merge 53 → 2
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 53) WHERE id = 2;
UPDATE account_reconcile_model SET active = false WHERE id = 53;

-- Canada Computer: merge 67 → 19
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 67) WHERE id = 19;
UPDATE account_reconcile_model SET active = false WHERE id = 67;

-- Circle K: merge 59 → 14
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 59) WHERE id = 14;
UPDATE account_reconcile_model SET active = false WHERE id = 59;

-- De Lage: merge 74 → 26
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 74) WHERE id = 26;
UPDATE account_reconcile_model SET active = false WHERE id = 74;

-- Enbridge: merge 60 → 32
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 60) WHERE id = 32;
UPDATE account_reconcile_model SET active = false WHERE id = 60;

-- Home Depot: merge 58 → 12
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 58) WHERE id = 12;
UPDATE account_reconcile_model SET active = false WHERE id = 58;

-- IFS Insurance: merge 71 → 23
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 71) WHERE id = 23;
UPDATE account_reconcile_model SET active = false WHERE id = 71;

-- MB-CREDIT CARD: merge 63 → 38
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 63) WHERE id = 38;
UPDATE account_reconcile_model SET active = false WHERE id = 63;

-- Monthly fee: merge 57 → 6
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 57) WHERE id = 6;
UPDATE account_reconcile_model SET active = false WHERE id = 57;

-- NSF fee: merge 55 → 4
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 55) WHERE id = 4;
UPDATE account_reconcile_model SET active = false WHERE id = 55;

-- Odoo: merge 52 → 30, archive both 52 and 78
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 52) WHERE id = 30;
UPDATE account_reconcile_model SET active = false WHERE id = 52;
UPDATE account_reconcile_model SET active = false WHERE id = 78;

-- Online Banking transfer: merge 56 → 35
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 56) WHERE id = 35;
UPDATE account_reconcile_model SET active = false WHERE id = 56;

-- Pay Employee-Vendor: merge 75 → 27
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 75) WHERE id = 27;
UPDATE account_reconcile_model SET active = false WHERE id = 75;

-- Petro Canada: merge 64 → 15
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 64) WHERE id = 15;
UPDATE account_reconcile_model SET active = false WHERE id = 64;

-- P M Products / Pride: merge 72 → 24
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 72) WHERE id = 24;
UPDATE account_reconcile_model SET active = false WHERE id = 72;

-- Purchase Interest: merge 77 → 29
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 77) WHERE id = 29;
UPDATE account_reconcile_model SET active = false WHERE id = 77;

-- Shell: merge 66 → 13
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 66) WHERE id = 13;
UPDATE account_reconcile_model SET active = false WHERE id = 66;

-- Superpass: merge 65 → 17
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 65) WHERE id = 17;
UPDATE account_reconcile_model SET active = false WHERE id = 65;

-- Wawanesa: merge 76 → 28
UPDATE account_reconcile_model SET mapped_partner_id = (SELECT mapped_partner_id FROM account_reconcile_model WHERE id = 76) WHERE id = 28;
UPDATE account_reconcile_model SET active = false WHERE id = 76;

-- Scotia Visa Payment: 62 has no original counterpart with lines — KEEP as is
-- Permobil: 69 has no original counterpart with lines — KEEP as is

-- ============================================================
-- Also rename the originals that had poor names
-- ============================================================
UPDATE account_reconcile_model SET name = '{"en_US": "Home Depot - Tools & Supplies"}' WHERE id = 12;
UPDATE account_reconcile_model SET name = '{"en_US": "Pride Mobility - Vendor Bills"}' WHERE id = 24;
UPDATE account_reconcile_model SET name = '{"en_US": "Odoo S.A. - Subscription"}' WHERE id = 30;

COMMIT;
