Skip to content

Commit

Permalink
[REF] Tests and Demo data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Mar 29, 2021
1 parent e3d02e4 commit e86ee5c
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 125 deletions.
6 changes: 6 additions & 0 deletions l10n_br_account_payment_order/demo/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_bradesco400"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_line_original" model="account.invoice.line">
Expand All @@ -31,6 +32,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_itau240"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_payment_order_itau_line_cnab240" model="account.invoice.line">
Expand All @@ -51,6 +53,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_itau400"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_payment_order_itau_line_cnab400" model="account.invoice.line">
Expand All @@ -71,6 +74,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_unicred400"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_payment_order_unicred_line_cnab400" model="account.invoice.line">
Expand All @@ -91,6 +95,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_cef240"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_payment_order_cef_line_cnab240" model="account.invoice.line">
Expand All @@ -111,6 +116,7 @@
<field name="type">out_invoice</field>
<field name="user_id" ref="base.user_demo"/>
<field name="payment_mode_id" ref="payment_mode_cobranca_bb400"/>
<field name="instructions">TESTE Intruções Boleto</field>
</record>

<record id="demo_invoice_payment_order_bb_line_cnab400" model="account.invoice.line" >
Expand Down
7 changes: 6 additions & 1 deletion l10n_br_account_payment_order/demo/account_payment_order.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<!-- TODO: Teste falha ao rodar mais de uma vez
return super().unlink()
File "/odoo/external-src/bank-payment/account_payment_order/models/bank_payment_line.py", line 170, in unlink
% order_state)
odoo.tools.convert.ParseError: "Cannot delete a payment order line whose payment order is in state 'uploaded'. You need to cancel it first.
<function model="account.payment.order" name="draft2open">
<value model="account.payment.order" search="[('payment_mode_id', '=', obj().env.ref('l10n_br_account_payment_order.payment_mode_boleto').id)]"/>
</function>
Expand All @@ -9,6 +14,6 @@
</function>
<function model="account.payment.order" name="generated2uploaded">
<value model="account.payment.order" search="[('payment_mode_id', '=', obj().env.ref('l10n_br_account_payment_order.payment_mode_boleto').id)]"/>
</function>
</function>-->

</odoo>
131 changes: 33 additions & 98 deletions l10n_br_account_payment_order/tests/test_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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


@tagged('post_install', '-at_install')
Expand All @@ -14,109 +14,44 @@ class TestPaymentOrder(SavepointCase):
def setUpClass(self):
super().setUpClass()

# Get Invoice for test
self.invoice_cef = self.env.ref(
# Product Tax Boleto
self.invoice_product_tax_boleto = self.env.ref(
'l10n_br_account_payment_order.'
'demo_invoice_payment_order_cef_cnab240'
'demo_invoice_payment_order_bb_cnab400'
)

def test_create_payment_order(self):
""" Test Create Payment Order """
# Product Tax Boleto
self.invoice_cheque = self.env.ref(
'l10n_br_account_payment_order.demo_invoice_payment_order_cheque'
)

# I check that Initially customer invoice is in the "Draft" state
self.assertEquals(self.invoice_cef.state, 'draft')
def test_product_tax_boleto(self):
""" Test Invoice where Payment Mode has Product Tax. """
self.invoice_product_tax_boleto._onchange_payment_mode_id()

# I validate invoice by creating on
self.invoice_cef.action_invoice_open()
# Produto Taxa adicionado
line_product_tax = self.invoice_product_tax_boleto. \
invoice_line_ids.filtered(
lambda l: l.product_id == self.invoice_product_tax_boleto.
payment_mode_id.product_tax_id)

self.assertEquals(len(line_product_tax), 1)
# I validate invoice by creating on
self.invoice_product_tax_boleto.action_invoice_open()
# I check that the invoice state is "Open"
self.assertEquals(self.invoice_cef.state, 'open')

# I check that now there is a move attached to the invoice
assert self.invoice_cef.move_id, \
"Move not created for open invoice"

payment_order = self.env['account.payment.order'].search([
('payment_mode_id', '=', self.invoice_cef.payment_mode_id.id)
])

assert payment_order, "Payment Order not created."

# TODO: Caso CNAB pode cancelar o Move ?
# Aparetemente isso precisa ser validado
# Change status of Move to draft just to test
self.invoice_cef.move_id.button_cancel()

for line in self.invoice_cef.move_id.line_ids.filtered(
lambda l: l.account_id.id == self.invoice_cef.account_id.id):
self.assertEquals(
line.journal_entry_ref, line.invoice_id.name,
"Error with compute field journal_entry_ref")

# Return the status of Move to Posted
self.invoice_cef.move_id.action_post()

# Verificar os campos CNAB na account.move.line
for line in self.invoice_cef.move_id.line_ids.filtered(
lambda l: l.account_id.id == self.invoice_cef.account_id.id):
assert line.own_number,\
'own_number field is not filled in created Move Line.'
assert line.mov_instruction_code_id, \
'mov_instruction_code_id field is not filled in created Move Line.'
self.assertEquals(
line.journal_entry_ref, line.invoice_id.name,
'Error with compute field journal_entry_ref')
# testar com a parcela 700
if line.debit == 700.0:
test_balance_value = line.get_balance()

self.assertEquals(
test_balance_value, 700.0,
'Error with method get_balance()')
self.assertEquals(self.invoice_product_tax_boleto.state, 'open')

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.assertEquals(self.invoice_cheque.state, 'open')
payment_order = self.env['account.payment.order'].search([
('payment_mode_id', '=', self.invoice_cef.payment_mode_id.id)
('payment_mode_id', '=', self.invoice_cheque.payment_mode_id.id)
])

# Verifica os campos CNAB na linhas de pagamentos
for l in payment_order.payment_line_ids:
assert l.own_number, \
'own_number field is not filled in Payment Line.'
assert l.mov_instruction_code_id, \
'mov_instruction_code_id field are not filled in Payment Line.'

# Ordem de Pagto CNAB não pode ser apagada
with self.assertRaises(UserError):
payment_order.unlink()

# Open payment order
payment_order.draft2open()

# Criação da Bank Line
self.assertEquals(len(payment_order.bank_line_ids), 2)

# A geração do arquivo é feita pelo modulo que implementa a
# biblioteca a ser usada
# Generate and upload
# payment_order.open2generated()
# payment_order.generated2uploaded()

self.assertEquals(payment_order.state, 'open')

# Verifica os campos CNAB na linhas de bancarias
for l in payment_order.bank_line_ids:
assert l.own_number, \
'own_number field is not filled in Payment Line.'
assert l.mov_instruction_code_id, \
'mov_instruction_code_id field are not filled in Payment Line.'

# Ordem de Pagto CNAB não pode ser Cancelada
with self.assertRaises(UserError):
payment_order.action_done_cancel()

# Testar Cancelamento
# with self.assertRaises(UserError):
self.invoice_cef.action_invoice_cancel()
self.assertEquals(len(payment_order), 0)

def test_bra_number_constrains(self):
""" Test bra_number constrains. """
Expand All @@ -125,7 +60,7 @@ def test_bra_number_constrains(self):
with self.assertRaises(ValidationError):
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'
))
bank_id=self.banco_bradesco.id,
partner_id=self.ref('l10n_br_base.res_partner_akretion'),
bra_number='12345'
))
Loading

0 comments on commit e86ee5c

Please sign in to comment.