Skip to content

[19.0][FIX] hr_expense_payment: derive payment links from reconciliation (rework for OCA#355 review) - #5

Closed
dnplkndll wants to merge 2 commits into
19.0-mig-hr_expense_paymentfrom
19.0-mig-hr_expense_payment-rework
Closed

[19.0][FIX] hr_expense_payment: derive payment links from reconciliation (rework for OCA#355 review)#5
dnplkndll wants to merge 2 commits into
19.0-mig-hr_expense_paymentfrom
19.0-mig-hr_expense_payment-rework

Conversation

@dnplkndll

@dnplkndll dnplkndll commented Jul 23, 2026

Copy link
Copy Markdown

Rework of the hr_expense_payment 19.0 MIG answering pilarvargas-tecnativa's review on OCA/hr-expense#355. Do not merge — after approval the commit gets folded into the [MIG] commit on 19.0-mig-hr_expense_payment and force-pushed there.

What the review flagged

  1. The module redefined account.payment.expense_ids, which 19.0 core already owns (related to move_id.expense_ids) — the independent M2M shadows the core field and can desync.
  2. No migration script for 18.0 payment_expense_sheet_rel data (post_init_hook only runs on install).
  3. The hook walked full_reconcile_id only — misses partially reconciled payments.

The rework

  • account.payment.reconciled_expense_ids (renamed) + hr.expense.payment_ids are now computed from the reconciliation via core's account.move._get_reconciled_payments() / _get_reconciled_amls() — the reconciled_bill_ids pattern. Non-stored + search.
  • Kills all three findings at once: core field untouched; nothing stored → no migration script needed (links derive from reconciliation on upgraded DBs too); partial reconciliations included by construction (matched_debit_ids/matched_credit_ids).
  • Wizard override, action_pay context threading, and hooks.py deleted — reconciliation already captures every registration path, including payments registered move-side or reconciled manually.
  • hr_expense_cancel (only consumer, reads expense.payment_ids before unreconciling) keeps working unchanged.

Prior art

  • Core: account.payment.reconciled_invoice_ids/reconciled_bill_ids; helpers _get_reconciled_amls/_get_reconciled_payments (partial-inclusive).
  • Merged OCA: l10n-brazil#3981 (l10n_br_account_due_list.payment_move_line_ids — non-stored M2M computed from partials); account-analytic#579 & l10n-brazil#4750 (drop module field duplicated by core); sale-workflow#3013 (sale_delivery_state core-collision refactor).

Test conditions covered (from the review + prior-art threads)

core expense_ids not overridden · back-link on Register Payment · partial payment · second payment for the remainder · grouped multi-expense payment · unreconcile dissolves the link (no stale rows) · both fields searchable · employee (non-accounting) read access — compute_sudo, red→green proven · company-paid stays core-only (payment.expense_ids), module fields empty.

Local run (stock odoo:19.0 + fresh DB, demo on): 8/8 tests pass. Removing compute_sudo makes the employee-access test fail with the exact AccessError (red→green verified).

hr.expense.sheet was removed in 19.0; retarget the payment register to hr.expense.
Address review on OCA#355 (pilarvargas-tecnativa):

- Do not redefine account.payment.expense_ids: 19.0 core already owns
  that field (related to move_id.expense_ids, i.e. company-paid
  expenses) and hangs logic off it (_compute_outstanding_account_id,
  the write() guard, action_open_expense). The module field is renamed
  to reconciled_expense_ids.
- Replace the stored Many2many + wizard context threading + post_init
  hook with fields computed from the reconciliation, using core's
  account.move._get_reconciled_payments()/_get_reconciled_amls()
  helpers (the reconciled_bill_ids pattern). The link can never go out
  of sync with the standard relationship, includes partially
  reconciled payments, and works however the payment was registered.
- compute_sudo on both fields: employees can read their expenses
  without accounting access, so the reconciliation walk needs sudo.
- No migration script needed anymore: nothing is stored, so 18.0
  payment_expense_sheet_rel data is superseded by the reconciliation
  itself on upgraded databases.
- Tests cover: core field not overridden, back-link on register
  payment, partial payment, grouped multi-expense payment,
  unreconcile dissolving the link, searchability of both computed
  fields, employee (non-accounting) read access, and company-paid
  expenses staying core-only.
@dnplkndll
dnplkndll force-pushed the 19.0-mig-hr_expense_payment-rework branch from 8f9add1 to 225c1c7 Compare July 23, 2026 23:02
@dnplkndll
dnplkndll force-pushed the 19.0-mig-hr_expense_payment branch from 093ce9c to 3fa1c43 Compare July 23, 2026 23:10
@dnplkndll dnplkndll closed this Jul 23, 2026
@dnplkndll
dnplkndll deleted the 19.0-mig-hr_expense_payment-rework branch July 23, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant