Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m27s
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
# 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")
|