forked from OpenG2P/openg2p-program
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9400114
commit 223ffc6
Showing
4 changed files
with
180 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Part of OpenG2P. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import models | ||
from . import tests |
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_entitlement, test_payment_manager |
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,86 @@ | ||
from datetime import timedelta | ||
|
||
from odoo import fields | ||
from odoo.tests import tagged | ||
from odoo.tests.common import TransactionCase | ||
|
||
from odoo.addons.g2p_programs.models import constants | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestG2PEntitlement(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.program = self.env["g2p.program"].create({"name": "Test Program"}) | ||
self.partner = self.env["res.partner"].create({"name": "Test Partner"}) | ||
self.cycle = self.env["g2p.cycle"].create( | ||
{ | ||
"name": "Test Cycle", | ||
"program_id": self.program.id, | ||
"start_date": fields.Datetime.now(), | ||
"end_date": fields.Datetime.now() + timedelta(days=7), | ||
} | ||
) | ||
self.entitlement = self.env["g2p.entitlement"].create( | ||
{ | ||
"program_id": self.program.id, | ||
"partner_id": self.partner.id, | ||
"cycle_id": self.cycle.id, | ||
"state": "draft", | ||
"initial_amount": 100.00, | ||
} | ||
) | ||
cash_pay_mgr_obj = "g2p.program.payment.manager.cash" | ||
pay_file_config = self.env["g2p.payment.file.config"].create( | ||
{"name": "Payment file config"} | ||
) | ||
self.cash_mgr = self.env[cash_pay_mgr_obj].create( | ||
{ | ||
"name": "Cash Manager", | ||
"program_id": self.program.id, | ||
"payment_file_config_ids": [(4, pay_file_config.id)], | ||
} | ||
) | ||
|
||
def test_compute_show_payment_buttons_valid(self): | ||
self.program.get_manager(constants.MANAGER_PAYMENT).unlink() | ||
pay_manager = self.env["g2p.program.payment.manager"].create( | ||
{ | ||
"program_id": self.program.id, | ||
"manager_ref_id": self.cash_mgr, | ||
} | ||
) | ||
self.program.update({"payment_managers": [(4, pay_manager.id)]}) | ||
self.entitlement.state = "approved" | ||
self.entitlement._compute_show_payment_buttons() | ||
self.assertTrue(self.entitlement.show_payment_prepare) | ||
|
||
def test_prepare_and_send_payment_cash_not_approved(self): | ||
self.entitlement.state = "draft" | ||
action = self.entitlement.prepare_and_send_payment_cash() | ||
self.assertEqual(action["params"]["type"], "danger") | ||
self.assertEqual(action["params"]["title"], "Payment") | ||
self.assertEqual(action["params"]["message"], "Entitlement is not approved!") | ||
|
||
def test_prepare_and_send_payment_cash_already_paid(self): | ||
self.entitlement.payment_status = "paid" | ||
self.entitlement.state = "approved" | ||
action = self.entitlement.prepare_and_send_payment_cash() | ||
self.assertEqual(action["params"]["type"], "danger") | ||
self.assertEqual(action["params"]["title"], "Payment") | ||
self.assertEqual(action["params"]["message"], "Invalid operation!") | ||
|
||
def test_prepare_and_send_payment_cash_valid(self): | ||
self.program.get_manager(constants.MANAGER_PAYMENT).unlink() | ||
pay_manager = self.env["g2p.program.payment.manager"].create( | ||
{ | ||
"program_id": self.program.id, | ||
"manager_ref_id": self.cash_mgr, | ||
} | ||
) | ||
self.program.update({"payment_managers": [(4, pay_manager.id)]}) | ||
self.entitlement.state = "approved" | ||
action = self.entitlement.prepare_and_send_payment_cash() | ||
self.assertEqual(action["params"]["type"], "success") | ||
self.assertEqual(action["params"]["title"], "Payment") | ||
self.assertEqual(action["params"]["message"], "Payment was issued and sent.") |
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,92 @@ | ||
from datetime import timedelta | ||
|
||
from odoo import fields | ||
from odoo.tests import tagged | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
@tagged("payment", "cash") | ||
class TestG2PPaymentManagerCash(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.program = self.env["g2p.program"].create({"name": "Test Program"}) | ||
self.partner = self.env["res.partner"].create({"name": "Test Partner"}) | ||
self.cycle = self.env["g2p.cycle"].create( | ||
{ | ||
"name": "Test Cycle", | ||
"program_id": self.program.id, | ||
"start_date": fields.Datetime.now(), | ||
"end_date": fields.Datetime.now() + timedelta(days=7), | ||
} | ||
) | ||
self.entitlement = self.env["g2p.entitlement"].create( | ||
{ | ||
"program_id": self.program.id, | ||
"partner_id": self.partner.id, | ||
"cycle_id": self.cycle.id, | ||
"state": "draft", | ||
"initial_amount": 100.00, | ||
} | ||
) | ||
self.payment_manager = self.env["g2p.program.payment.manager.cash"].create( | ||
{ | ||
"name": "Cash Payment Manager", | ||
"program_id": self.program.id, | ||
} | ||
) | ||
|
||
self.payment = self.env["g2p.payment"].create( | ||
{ | ||
"name": "Test Payment", | ||
"amount_issued": 100.0, | ||
"cycle_id": self.cycle.id, | ||
"state": "issued", | ||
"entitlement_id": self.entitlement.id, | ||
} | ||
) | ||
|
||
self.payment_batch = self.env["g2p.payment.batch"].create( | ||
{ | ||
"program_id": self.program.id, | ||
"cycle_id": self.cycle.id, | ||
"payment_ids": [(4, self.payment.id)], | ||
} | ||
) | ||
|
||
def test_selection_manager_ref_id(self): | ||
selection = self.env["g2p.program.payment.manager"]._selection_manager_ref_id() | ||
self.assertIn( | ||
("g2p.program.payment.manager.cash", "Cash Payment Manager"), selection | ||
) | ||
|
||
def test_crypto_key_set_creation(self): | ||
crypto_key_set = self.env["g2p.crypto.key.set"].create( | ||
{ | ||
"name": "Test Crypto Key Set", | ||
"cash_payment_manager_id": self.payment_manager.id, | ||
} | ||
) | ||
self.assertEqual(crypto_key_set.cash_payment_manager_id, self.payment_manager) | ||
|
||
def test_send_payments(self): | ||
result = self.payment_manager._send_payments([self.payment_batch]) | ||
self.assertEqual(self.payment.state, "reconciled") | ||
self.assertEqual(self.payment.status, "paid") | ||
self.assertEqual(self.payment.amount_paid, 100.0) | ||
|
||
self.assertEqual(result["type"], "ir.actions.client") | ||
self.assertEqual(result["tag"], "display_notification") | ||
self.assertTrue(result["params"]["sticky"]) | ||
self.assertEqual(result["params"]["type"], "success") | ||
self.assertEqual( | ||
result["params"]["next"]["type"], "ir.actions.act_window_close" | ||
) | ||
|
||
def test_send_payments_no_batches(self): | ||
result = self.payment_manager._send_payments([]) | ||
|
||
self.assertEqual(result["type"], "ir.actions.client") | ||
self.assertEqual(result["tag"], "display_notification") | ||
self.assertTrue(result["params"]["sticky"]) | ||
self.assertEqual(result["params"]["type"], "warning") | ||
self.assertEqual(result["params"]["message"], "No payment batches to process.") |