From 198724234a13a46dfa6acc86e995ad8cf5f4c7db Mon Sep 17 00:00:00 2001 From: Francisco Javier Luna Vazquez Date: Wed, 25 May 2022 17:58:09 -0500 Subject: [PATCH] [FIX] account_move_name_sequence: Exclude no_gap sequences from _is_end_of_seq_chain --- .../models/account_move.py | 9 +++++++ .../tests/test_account_move_name_seq.py | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/account_move_name_sequence/models/account_move.py b/account_move_name_sequence/models/account_move.py index ff1dbc75..6f63aab6 100644 --- a/account_move_name_sequence/models/account_move.py +++ b/account_move_name_sequence/models/account_move.py @@ -52,3 +52,12 @@ class AccountMove(models.Model): # We must by-pass this constraint of sequence.mixin def _constrains_date_sequence(self): return True + + def _is_end_of_seq_chain(self): + invoices_no_gap_sequences = self.filtered( + lambda inv: inv.journal_id.sequence_id.implementation == "no_gap" + ) + invoices_other_sequences = self - invoices_no_gap_sequences + if not invoices_other_sequences and invoices_no_gap_sequences: + return False + return super(AccountMove, invoices_other_sequences)._is_end_of_seq_chain() diff --git a/account_move_name_sequence/tests/test_account_move_name_seq.py b/account_move_name_sequence/tests/test_account_move_name_seq.py index c6acf33c..039cfc87 100644 --- a/account_move_name_sequence/tests/test_account_move_name_seq.py +++ b/account_move_name_sequence/tests/test_account_move_name_seq.py @@ -1,10 +1,13 @@ # Copyright 2021 Akretion France (http://www.akretion.com/) # @author: Alexis de Lattre +# @author: Moisés López +# @author: Francisco Luna # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from datetime import datetime from odoo import fields +from odoo.exceptions import UserError from odoo.tests import tagged from odoo.tests.common import TransactionCase @@ -111,3 +114,25 @@ class TestAccountMoveNameSequence(TransactionCase): in_refund_invoice.button_draft() in_refund_invoice.action_post() self.assertEqual(in_refund_invoice.name, move_name) + + def test_remove_invoice_error(self): + invoice = self.env["account.move"].create( + { + "date": self.date, + "journal_id": self.misc_journal.id, + "line_ids": [ + (0, 0, {"account_id": self.account1.id, "debit": 10}), + (0, 0, {"account_id": self.account2.id, "credit": 10}), + ], + } + ) + self.assertEqual(invoice.name, "/") + invoice.action_post() + error_msg = "You cannot delete an item linked to a posted entry." + with self.assertRaisesRegex(UserError, error_msg): + invoice.unlink() + invoice.button_draft() + invoice.button_cancel() + error_msg = "You cannot delete this entry, as it has already consumed a" + with self.assertRaisesRegex(UserError, error_msg): + invoice.unlink()