From 2b9587aad692b7efc818fc0e66eaf7a3d5956572 Mon Sep 17 00:00:00 2001 From: "Ali Alfie (alal)" Date: Fri, 28 Apr 2023 10:59:18 +0000 Subject: [PATCH] [FIX] account delay draft opening entry Before: in the accounting dashboard setup, an opening move was created in step 1 (accounting periods) and step 4 (chart of accounts) Now: the opening move is only created in step 4 only when a first opening debit/credit is entered manually by our user. Task-ID #3177315 closes odoo/odoo#122818 X-original-commit: c3793357d823273cb4297b0eb31308ad73a9dff8 Signed-off-by: Nicolas Viseur (vin) --- addons/account/models/account_account.py | 6 ++++++ addons/account/models/company.py | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 3037e5c4daf..c2ba19ed75a 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -2,6 +2,7 @@ from odoo import api, fields, models, _, tools from odoo.osv import expression from odoo.exceptions import UserError, ValidationError +from odoo.tools.float_utils import float_is_zero from bisect import bisect_left from collections import defaultdict import re @@ -451,6 +452,11 @@ class AccountAccount(models.Model): either 'debit' or 'credit', depending on which one of these two fields got assigned. """ + # only set the opening debit/credit if the amount is not zero, + # otherwise return early + if float_is_zero(amount, precision_digits=2): + return + self.company_id.create_op_move_if_non_existant() opening_move = self.company_id.account_opening_move_id diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 39ae357f5ba..1da178c3ee9 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -420,7 +420,6 @@ class ResCompany(models.Model): def setting_init_fiscal_year_action(self): """ Called by the 'Fiscal Year Opening' button of the setup bar.""" company = self.env.company - company.create_op_move_if_non_existant() new_wizard = self.env['account.financial.year.op'].create({'company_id': company.id}) view_id = self.env.ref('account.setup_financial_year_opening_form').id @@ -444,9 +443,6 @@ class ResCompany(models.Model): if company.opening_move_posted(): return 'account.action_account_form' - # Otherwise, we create the opening move - company.create_op_move_if_non_existant() - # Then, we open will open a custom tree view allowing to edit opening balances of the account view_id = self.env.ref('account.init_accounts_tree').id # Hide the current year earnings account as it is automatically computed