Skip to content

[16.0][FIX] account_fiscal_year_closing: exclude cancelled moves when closing by partner - #385

Open
sefirosweb wants to merge 1 commit into
OCA:16.0from
sefirosweb:16.0-fix-account_fiscal_year_closing-cancelled-partners
Open

[16.0][FIX] account_fiscal_year_closing: exclude cancelled moves when closing by partner#385
sefirosweb wants to merge 1 commit into
OCA:16.0from
sefirosweb:16.0-fix-account_fiscal_year_closing-cancelled-partners

Conversation

@sefirosweb

Copy link
Copy Markdown

Problem

Running the fiscal year closing on a database that contains cancelled moves produces an
unbalanced closing entry, and the module refuses to create it: the "Unbalanced journal
entry found"
wizard comes up instead.

Root cause

AccountFiscalyearClosingMapping reads the journal items of the year through two
different methods, and only one of them filters out cancelled moves:

Method Used when the closing type is Filters move_id.state != 'cancel'
account_lines_get balance yes
account_partners_get unreconciled no

In Odoo a cancelled move keeps its account.move.line records — reports ignore them by
filtering on the state. So accounts closed by balance are computed without cancelled
moves while accounts closed by partner are computed with them.

The closing move posts, for every account, the opposite of its balance, so it only
balances if the sum of all the included balances is zero. Mixing two filtering criteria
breaks that, by exactly the net amount of the cancelled moves in the accounts closed by
partner.

This is not an edge case for companies using a single receivable account for all
customers and a single payable account for all suppliers, which is the usual setup in
Spain: those accounts have to be closed by partner to keep the detail per third party,
so the only affected branch is the one they need. On the database where this was found the
closing came out 86,613.45 € off, entirely explained by 16 journal items belonging to 15
cancelled invoices.

Fix

Add to account_partners_get the same domain leaf account_lines_get already uses, so
both closing types read the same journal items.

Test

test_account_closing already builds a closing configuration with
closing_type_default = "unreconciled" mapping the receivable and payable accounts, and
already ends by asserting that no unbalanced move is produced. Reproducing the bug only
needed a cancelled invoice, so that is all the test adds.

The expected profit and loss amounts are now computed from non-cancelled journal items as
well: they are compared against what the module writes, and the module regularises income
and expense accounts through account_lines_get, which excludes cancelled moves.

Verified on a clean database with demo data:

  • without the fix → AssertionError: True is not false : There are unbalanced move/s in the closing moves!
  • with the fix → 0 failed, 0 error(s) of 2 tests

Other branches

The same asymmetry is present in 14.0 and 18.0, so the fix applies there too and I am
happy to forward-port it if this is accepted. In 12.0 neither method filters the state,
so that branch is at least self-consistent.

…ng by partner

account_lines_get() filters out journal items whose move is cancelled, but
account_partners_get() does not. Accounts closed with the "unreconciled"
closing type (receivable and payable) are therefore computed on a different
basis than the ones closed by balance.

In Odoo a cancelled move keeps its account.move.line records, so whenever the
fiscal year contains cancelled moves affecting those accounts, the sum of the
balances written to the closing move is no longer zero and the module refuses
to create it, showing the "Unbalanced journal entry found" wizard.

This is not an edge case for companies using a single receivable account for
all customers and a single payable account for all suppliers, which is the
common setup in Spain: those accounts have to be closed by partner to keep the
detail per third party, so the only branch affected is the one they need.

Add the same ("move_id.state", "!=", "cancel") leaf that account_lines_get
already uses, so both closing types read the same journal items.

The existing test already builds a closing configuration with
closing_type_default = "unreconciled" and asserts that no unbalanced move is
produced, so reproducing the bug only needed a cancelled invoice. The expected
profit and loss amounts are now computed from non-cancelled journal items too,
which is what the module does when regularising income and expense accounts.

Without the fix the test fails with the module's own message:

    AssertionError: True is not false : There are unbalanced move/s in the
    closing moves!
@OCA-git-bot OCA-git-bot added mod:account_fiscal_year_closing Module account_fiscal_year_closing series:16.0 labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_fiscal_year_closing Module account_fiscal_year_closing series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants