[IMP] account_advanced_protection_features: correct function button_draft when called on multiple moves
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m27s

This commit is contained in:
2026-01-07 16:56:30 +01:00
parent c7254a7b84
commit a948a466cc
3 changed files with 59 additions and 5 deletions

View File

@@ -0,0 +1 @@
from . import test_account_move

View File

@@ -0,0 +1,52 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestAccountMoveButtonDraft(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.journal = cls.env["account.journal"].search(
[("type", "=", "sale")], limit=1
)
cls.account = cls.env["account.account"].search(
[("account_type", "=", "income")], limit=1
)
def _create_invoice(self):
return self.env["account.move"].create({
"move_type": "out_invoice",
"partner_id": self.partner.id,
"journal_id": self.journal.id,
"invoice_line_ids": [
(0, 0, {
"name": "Test line",
"quantity": 1,
"price_unit": 100.0,
"account_id": self.account.id,
}),
],
})
def test_button_draft_multiple_moves(self):
"""Test that button_draft works on multiple account.move records.
"""
# Create two invoices
invoice1 = self._create_invoice()
invoice2 = self._create_invoice()
# Post both invoices
invoice1.action_post()
invoice2.action_post()
# Combine them into a recordset
invoices = invoice1 | invoice2
# This should not raise "Expected singleton" error
invoices.button_draft()
# Verify both are back to draft
self.assertEqual(invoice1.state, "draft")
self.assertEqual(invoice2.state, "draft")