[16.0][FIX] account_fiscal_year_closing: exclude cancelled moves when closing by partner - #385
Open
sefirosweb wants to merge 1 commit into
Conversation
…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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
AccountFiscalyearClosingMappingreads the journal items of the year through twodifferent methods, and only one of them filters out cancelled moves:
move_id.state != 'cancel'account_lines_getbalanceaccount_partners_getunreconciledIn Odoo a cancelled move keeps its
account.move.linerecords — reports ignore them byfiltering 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_getthe same domain leafaccount_lines_getalready uses, soboth closing types read the same journal items.
Test
test_account_closingalready builds a closing configuration withclosing_type_default = "unreconciled"mapping the receivable and payable accounts, andalready 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:
AssertionError: True is not false : There are unbalanced move/s in the closing moves!0 failed, 0 error(s) of 2 testsOther branches
The same asymmetry is present in
14.0and18.0, so the fix applies there too and I amhappy to forward-port it if this is accepted. In
12.0neither method filters the state,so that branch is at least self-consistent.