Skip to content

Commit

Permalink
[IMP] l10n_br_account_payment_order: Tests for CNAB Codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Feb 27, 2024
1 parent 017199b commit 07d4073
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_account_payment_order/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import test_invoice_manual_workflow
from . import test_payment_mode
from . import test_payment_order_outbound_pix
from . import test_cnab_codes
127 changes: 127 additions & 0 deletions l10n_br_account_payment_order/tests/test_cnab_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Copyright (C) 2024-Today - Akretion (<http://www.akretion.com>).
# @author Magno Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


@tagged("post_install", "-at_install")
class TestPaymentOrder(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.instruction_unicred_01 = cls.env.ref(
"l10n_br_account_payment_order.unicred_240_400_instruction_01"
)

def test_cnab_code_abstract(self):
"""Test CNAB Code Abstract Model"""
# Testa o name_get do objeto
self.instruction_unicred_01.name_get()

def test_cnab_instruction_move_code(self):
"""Test CNAB Instruction Move Code"""
instruction_code_form = Form(self.instruction_unicred_01)

# Testa os campos compute
# TODO: Ver a questão do Group By a aprtir da v15 ou v16
instruction_code_form.bank_ids.add(self.env.ref("l10n_br_base.res_bank_237"))
instruction_code_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab500")
)
instruction_code_form.save()

# Testa o caso do tamanho do campo 2
instruction_code_form.code = "123"
with self.assertRaises(ValidationError):
instruction_code_form.save()

# Testa o caso do Codigo Duplicado
instruction_code_new_form = Form(
self.env["l10n_br_cnab.mov.instruction.code"],
"l10n_br_account_payment_order.l10n_br_cnab_mov_instruction_code_form_view",
)

instruction_code_new_form.code = "01"
instruction_code_new_form.name = "Remessa*"
instruction_code_new_form.bank_ids.add(
self.env.ref("l10n_br_base.res_bank_136")
)
instruction_code_new_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab400")
)
with self.assertRaises(ValidationError):
instruction_code_new_form.save()

def test_cnab_return_move_code(self):
"""Test CNAB Return Move Code"""
# Caso campo deve ter o tamanho 2
return_unicred_01 = self.env.ref(
"l10n_br_account_payment_order.unicred_240_400_return_01"
)
return_code_form = Form(return_unicred_01)

# Testa o caso dos campos compute
# TODO: Ver a questão do Group By a partir da v15 ou v16
return_code_form.bank_ids.add(self.env.ref("l10n_br_base.res_bank_237"))
return_code_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab500")
)
return_code_form.save()

# Testa caso do tamanho ser 2
return_code_form.code = "123"
with self.assertRaises(ValidationError):
return_code_form.save()

# Caso Codigo Duplicado
return_move_code_new_form = Form(
self.env["l10n_br_cnab.return.move.code"],
"l10n_br_account_payment_order.l10n_br_cnab_return_move_code_form_view",
)

return_move_code_new_form.code = "01"
return_move_code_new_form.name = "Pago (Título protestado pago em cartório)"
return_move_code_new_form.bank_ids.add(
self.env.ref("l10n_br_base.res_bank_136")
)
return_move_code_new_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab400")
)
with self.assertRaises(ValidationError):
return_move_code_new_form.save()

def test_cnab_boleto_wallet_code(self):
"""Test CNAB Boleto Wallet Code"""
boleto_wallet_code_1 = self.env.ref(
"l10n_br_account_payment_order.santander_240_boleto_wallet_code_1"
)
boleto_wallet_code_form = Form(boleto_wallet_code_1)

# Testa o caso dos campos compute
# TODO: Ver a questão do Group By a partir da v15 ou v16
boleto_wallet_code_form.bank_ids.add(self.env.ref("l10n_br_base.res_bank_136"))
boleto_wallet_code_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab500")
)
boleto_wallet_code_form.save()

# Caso Codigo Duplicado
boleto_wallet_code_new_form = Form(
self.env["l10n_br_cnab.boleto.wallet.code"],
"l10n_br_account_payment_order.l10n_br_cnab_boleto_wallet_code_form_view",
)

boleto_wallet_code_new_form.code = "1"
boleto_wallet_code_new_form.name = (
"Cobrança Simples (Sem Registro e Eletrônica com Registro)"
)
boleto_wallet_code_new_form.bank_ids.add(
self.env.ref("l10n_br_base.res_bank_033")
)
boleto_wallet_code_new_form.payment_method_ids.add(
self.env.ref("l10n_br_account_payment_order.payment_mode_type_cnab400")
)
with self.assertRaises(ValidationError):
boleto_wallet_code_new_form.save()

0 comments on commit 07d4073

Please sign in to comment.