fix(fusion_accounting_bank_rec): MV correctness for V19 schema + Odoo test harness
Three issues surfaced when running the MV smoke tests against westin-v19: 1. account_bank_statement_line has no `date` column in V19 — `date` is a related field flowing through move_id -> account_move.date. The MV now JOINs account_move and selects am.date. 2. is_reconciled is nullable; replace `= FALSE` with `IS NOT TRUE` so nulls (genuinely unreconciled lines that haven't had the compute run yet) are still included. 3. _refresh() now flushes the ORM cache (env.flush_all()) before the REFRESH so computed-stored fields like is_reconciled are written to the DB before the materialization snapshot reads them. Previously the reconcile-then-refresh path saw the pre-reconcile column value. 4. _trigger_mv_refresh() (suggestion create/write hook) now uses concurrently=False because Postgres forbids REFRESH MATERIALIZED VIEW CONCURRENTLY inside a transaction block, and Odoo's per-request cursor is always inside one. The cron path (Task 25) will open an autocommit cursor for CONCURRENTLY refreshes. 5. Tests dropped the env.cr.commit() pattern: Postgres always shows a transaction its own writes, so a non-CONCURRENTLY refresh in the same txn picks up freshly-inserted rows. Cleaner + works inside TransactionCase, which forbids cr.commit(). Verified: 4 new MV tests pass, 0 failures across 118 logical tests (178 with parametrized property-based runs) of fusion_accounting_bank_rec on westin-v19. Made-with: Cursor
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
-- Refreshed on cron (Task 25) and on suggestion writes.
|
||||
-- Indexed on (company_id, journal_id, date) for fast UI queries.
|
||||
|
||||
-- NOTE: account_bank_statement_line does not store `date` directly in V19;
|
||||
-- it is a related field through move_id -> account_move.date. We JOIN on
|
||||
-- account_move to get it.
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS fusion_unreconciled_bank_line_mv AS
|
||||
SELECT
|
||||
bsl.id AS id,
|
||||
bsl.company_id AS company_id,
|
||||
bsl.journal_id AS journal_id,
|
||||
bsl.date AS date,
|
||||
am.date AS date,
|
||||
bsl.amount AS amount,
|
||||
bsl.payment_ref AS payment_ref,
|
||||
bsl.currency_id AS currency_id,
|
||||
@@ -41,7 +44,8 @@ SELECT
|
||||
WHERE p.partner_id = bsl.partner_id AND p.company_id = bsl.company_id LIMIT 1), 0)
|
||||
AS partner_reconcile_count
|
||||
FROM account_bank_statement_line bsl
|
||||
WHERE bsl.is_reconciled = FALSE;
|
||||
JOIN account_move am ON am.id = bsl.move_id
|
||||
WHERE bsl.is_reconciled IS NOT TRUE;
|
||||
|
||||
-- Indexes for the common UI queries: filter by company + journal, sort by date desc.
|
||||
CREATE INDEX IF NOT EXISTS fusion_mv_unrec_company_journal_date_idx
|
||||
|
||||
Reference in New Issue
Block a user