-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de16767
commit 2c6df2a
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_account_invoice_select_for_payment |
94 changes: 94 additions & 0 deletions
94
account_invoice_select_for_payment/tests/test_account_invoice_select_for_payment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from odoo.tests import TransactionCase | ||
|
||
|
||
class TestAccountMoveAndPayment(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
||
# Create common product and account for testing | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "Test Product", "list_price": 100} | ||
) | ||
cls.account = cls.env["account.account"].search( | ||
[("code", "=", "400000")], limit=1 | ||
) | ||
|
||
# Create invoices for testing | ||
cls.invoice_1 = cls._create_invoice( | ||
partner_id=cls.env.ref("base.res_partner_1").id, selected_for_payment=False | ||
) | ||
cls.invoice_2 = cls._create_invoice( | ||
partner_id=cls.env.ref("base.res_partner_2").id, selected_for_payment=True | ||
) | ||
|
||
@classmethod | ||
def _create_invoice(cls, partner_id, selected_for_payment): | ||
invoice = cls.env["account.move"].create( | ||
{ | ||
"move_type": "out_invoice", | ||
"partner_id": partner_id, | ||
"selected_for_payment": selected_for_payment, | ||
} | ||
) | ||
invoice.write( | ||
{ | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": cls.product.id, | ||
"quantity": 1, | ||
"price_unit": 100, | ||
"account_id": cls.account.id, | ||
}, | ||
) | ||
] | ||
} | ||
) | ||
invoice.action_post() | ||
return invoice | ||
|
||
def test_action_toggle_select_for_payment(self): | ||
"""Test toggling the 'selected_for_payment' status.""" | ||
# Toggle selected_for_payment status for both invoices | ||
self.invoice_1.action_toggle_select_for_payment() | ||
self.invoice_2.action_toggle_select_for_payment() | ||
|
||
# Assert the expected results | ||
self.assertTrue( | ||
self.invoice_1.selected_for_payment, | ||
"Invoice 1 should be selected for payment.", | ||
) | ||
self.assertFalse( | ||
self.invoice_2.selected_for_payment, | ||
"Invoice 2 should not be selected for payment.", | ||
) | ||
|
||
def test_action_register_payment(self): | ||
"""Test the 'action_register_payment' method with multiple invoices.""" | ||
# Ensure initial selected_for_payment states | ||
self.assertFalse(self.invoice_1.selected_for_payment) | ||
self.assertTrue(self.invoice_2.selected_for_payment) | ||
|
||
# Register payment for both invoices | ||
context = dict( | ||
self.env.context, active_ids=[self.invoice_1.id, self.invoice_2.id] | ||
) | ||
self.invoice_1.with_context(**context).action_register_payment() | ||
|
||
# Validate that selected_for_payment is reset after payment | ||
self.env.invalidate_all() | ||
self.assertFalse(self.invoice_1.selected_for_payment) | ||
self.assertFalse(self.invoice_2.selected_for_payment) | ||
|
||
def test_register_payment_with_no_active_ids(self): | ||
"""Test the 'action_register_payment' method when no active_ids are provided.""" | ||
# Call register payment with no active_ids | ||
self.invoice_1.action_register_payment() | ||
|
||
# Ensure that no changes occurred to selected_for_payment | ||
self.env.invalidate_all() | ||
self.assertFalse(self.invoice_1.selected_for_payment) | ||
self.assertTrue(self.invoice_2.selected_for_payment) |