From 9ff1d2df7209f265487358e942f13830cce82374 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Tue, 13 Jul 2021 09:51:13 +0000 Subject: [PATCH] [FIX] account: Block archival of journals with auto post entries At the moment, it is possible to archive a journal for which some entries are still waiting to be auto-posted in the future. Add a constrains to avoid make sure that it is no longer possible, since it shouldn't. Task id #2585454 closes odoo/odoo#74690 X-original-commit: 850eb5100d6405d3a7293e06910a1c5355fdb8d8 Signed-off-by: Laurent Smet Signed-off-by: Nicolas Viseur --- addons/account/i18n/account.pot | 12 ++++++++++++ addons/account/models/account_journal.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index dfd2f1bff9a..2f2905b025a 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -14143,6 +14143,18 @@ msgid "" "is the Odoo reference." msgstr "" +#. module: account +#: code:addons/account/models/account_journal.py:0 +#, python-format +msgid "" +"You can not archive a journal containing draft journal entries.\n" +"\n" +"To proceed:\n" +"1/ click on the top-right button 'Journal Entries' from this journal form\n" +"2/ then filter on 'Draft' entries\n" +"3/ select them all and post or delete them through the action menu" +msgstr "" + #. module: account #: code:addons/account/models/account_payment_term.py:0 #, python-format diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index ce39f31adea..e9cd3b727a5 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -429,6 +429,21 @@ class AccountJournal(models.Model): raise ValidationError(_("Some payment methods supposed to be unique already exists somewhere else.\n" "(%s)", ', '.join([method.display_name for method in methods]))) + @api.constrains('active') + def _check_auto_post_draft_entries(self): + for journal in self: + pending_moves = self.env['account.move'].search([ + ('journal_id', '=', journal.id), + ('state', '=', 'draft') + ], limit=1) + + if pending_moves: + raise ValidationError(_("You can not archive a journal containing draft journal entries.\n\n" + "To proceed:\n" + "1/ click on the top-right button 'Journal Entries' from this journal form\n" + "2/ then filter on 'Draft' entries\n" + "3/ select them all and post or delete them through the action menu")) + @api.onchange('type') def _onchange_type(self): self.refund_sequence = self.type in ('sale', 'purchase')