Skip to content

Commit

Permalink
[MIG] Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Apr 1, 2022
1 parent 8fad380 commit 455edc4
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def setUpClass(cls):
)

def _invoice_confirm_flow(self):
self.invoice_manual_test.action_invoice_open()
self.invoice_manual_test.post()

# I check that the invoice state is "Open"
self.assertEqual(self.invoice_manual_test.state, "open")
# I check that the invoice state is "posted"
self.assertEqual(self.invoice_manual_test.state, "posted")

def test_invoice_button(self):
""" Test Invoice Button to Add to a payment order"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Luis Felipe Mileo <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.fields import Date
from odoo.tests import SavepointCase, tagged
from odoo.tests.common import Form


@tagged("post_install", "-at_install")
Expand All @@ -14,31 +16,48 @@ def setUpClass(cls):
cls.invoice_customer_without_paymeny_mode = cls.env.ref(
"l10n_br_account_payment_order." "demo_invoice_no_payment_mode"
)
cls.journal_cash = cls.env["account.journal"].search(
[("type", "=", "cash")], limit=1
)
cls.payment_method_manual_in = cls.env.ref(
"account.account_payment_method_manual_in"
)

def test_cancel_invoice_no_payment_mode_pay(self):
""" Test Pay Invoice without payment mode in cash"""
self.invoice_customer_without_paymeny_mode.action_invoice_open()

# I check that the invoice state is "Open"
self.assertEqual(self.invoice_customer_without_paymeny_mode.state, "open")
# I check that the invoice state is "posted"
self.assertEqual(self.invoice_customer_without_paymeny_mode.state, "posted")

open_amount = self.invoice_customer_without_paymeny_mode.residual
open_amount = self.invoice_customer_without_paymeny_mode.amount_residual
# I totally pay the Invoice
self.invoice_customer_without_paymeny_mode.pay_and_reconcile(
self.env["account.journal"].search([("type", "=", "cash")], limit=1),
open_amount,
payment_register = Form(
self.env["account.payment"].with_context(
active_model="account.move",
active_ids=self.invoice_customer_without_paymeny_mode.ids,
)
)
payment_register.payment_date = Date.context_today(self.env.user)
payment_register.journal_id = self.journal_cash
payment_register.payment_method_id = self.payment_method_manual_in

# Perform the partial payment by setting the amount at 300 instead of 500
payment_register.amount = open_amount

payment = payment_register.save()
self.assertEqual(len(payment), 1)
payment.post()

# I verify that invoice is now in Paid state
self.assertEqual(
self.invoice_customer_without_paymeny_mode.state,
self.invoice_customer_without_paymeny_mode.invoice_payment_state,
"paid",
"Invoice is not in Paid state",
)

def test_cancel_invoice_no_payment_mode_cancel(self):
""" Test Cancel Invoice Without Payment Mode """
self.invoice_customer_without_paymeny_mode.action_invoice_cancel()
self.invoice_customer_without_paymeny_mode.button_cancel()

# I check that the invoice state is "Cancel"
self.assertEqual(self.invoice_customer_without_paymeny_mode.state, "cancel")
18 changes: 11 additions & 7 deletions l10n_br_account_payment_order/tests/test_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Magno Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.exceptions import ValidationError
from odoo.tests import SavepointCase, tagged


Expand All @@ -18,11 +17,10 @@ def setUpClass(cls):

def test_payment_mode_without_payment_order(self):
""" Test Invoice when Payment Mode not generate Payment Order. """
self.invoice_cheque._onchange_payment_mode_id()
# I validate invoice by creating on
self.invoice_cheque.action_invoice_open()
# I check that the invoice state is "Open"
self.assertEqual(self.invoice_cheque.state, "open")
self.invoice_cheque.post()
# I check that the invoice state is "posted"
self.assertEqual(self.invoice_cheque.state, "posted")
payment_order = self.env["account.payment.order"].search(
[("payment_mode_id", "=", self.invoice_cheque.payment_mode_id.id)]
)
Expand All @@ -31,11 +29,17 @@ def test_payment_mode_without_payment_order(self):
def test_bra_number_constrains(self):
""" Test bra_number constrains. """
self.banco_bradesco = self.env["res.bank"].search([("code_bc", "=", "033")])
with self.assertRaises(ValidationError):
self.env["res.partner.bank"].create(
try:
result = self.env["res.partner.bank"].create(
dict(
bank_id=self.banco_bradesco.id,
partner_id=self.ref("l10n_br_base.res_partner_akretion"),
bra_number="12345",
)
)
except Exception:
result = False
self.assertFalse(
result,
"Error to check included bank BRA Number greater than four caracters",
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def setUpClass(cls):
"l10n_br_account_payment_order." "demo_invoice_automatic_test"
)
if cls.invoice_auto.state == "draft":
cls.invoice_auto.action_invoice_open()

assert cls.invoice_auto.move_id, "Move not created for open invoice"
cls.invoice_auto.action_post()

cls.financial_move_line_ids = cls.invoice_auto.financial_move_line_ids
cls.financial_move_line_0 = cls.financial_move_line_ids[0]
Expand Down
Loading

0 comments on commit 455edc4

Please sign in to comment.