2
0

[FIX] account_move_name_sequence: Exclude no_gap sequences from _is_end_of_seq_chain

This commit is contained in:
Francisco Javier Luna Vazquez 2022-05-25 17:58:09 -05:00 committed by Rodrigo
parent a800db0440
commit 198724234a
2 changed files with 34 additions and 0 deletions

View File

@ -52,3 +52,12 @@ class AccountMove(models.Model):
# We must by-pass this constraint of sequence.mixin # We must by-pass this constraint of sequence.mixin
def _constrains_date_sequence(self): def _constrains_date_sequence(self):
return True 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()

View File

@ -1,10 +1,13 @@
# Copyright 2021 Akretion France (http://www.akretion.com/) # Copyright 2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com> # @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Moisés López <moylop260@vauxoo.com>
# @author: Francisco Luna <fluna@vauxoo.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime from datetime import datetime
from odoo import fields from odoo import fields
from odoo.exceptions import UserError
from odoo.tests import tagged from odoo.tests import tagged
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
@ -111,3 +114,25 @@ class TestAccountMoveNameSequence(TransactionCase):
in_refund_invoice.button_draft() in_refund_invoice.button_draft()
in_refund_invoice.action_post() in_refund_invoice.action_post()
self.assertEqual(in_refund_invoice.name, move_name) 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()