From 07d4073aaf3d268151ceaec44356e55fb477d887 Mon Sep 17 00:00:00 2001 From: Magno Costa Date: Tue, 27 Feb 2024 14:26:51 -0300 Subject: [PATCH] [IMP] l10n_br_account_payment_order: Tests for CNAB Codes. --- .../tests/__init__.py | 1 + .../tests/test_cnab_codes.py | 127 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 l10n_br_account_payment_order/tests/test_cnab_codes.py diff --git a/l10n_br_account_payment_order/tests/__init__.py b/l10n_br_account_payment_order/tests/__init__.py index e8fbe02888b7..e01a3af668d3 100644 --- a/l10n_br_account_payment_order/tests/__init__.py +++ b/l10n_br_account_payment_order/tests/__init__.py @@ -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 diff --git a/l10n_br_account_payment_order/tests/test_cnab_codes.py b/l10n_br_account_payment_order/tests/test_cnab_codes.py new file mode 100644 index 000000000000..9ac53583822e --- /dev/null +++ b/l10n_br_account_payment_order/tests/test_cnab_codes.py @@ -0,0 +1,127 @@ +# Copyright (C) 2024-Today - Akretion (). +# @author Magno Costa +# 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()