| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
from odoo.addons.l10n_latam_check.tests.common import L10nLatamCheckTest |
| 4 |
from odoo.tests import Form, tagged |
| 5 |
from odoo import Command, fields |
| 6 |
|
| 7 |
|
| 8 |
@tagged('post_install_l10n', 'post_install', '-at_install') |
| 9 |
class TestOwnChecks(L10nLatamCheckTest): |
| 10 |
|
| 11 |
def test_01_pay_with_own_checks(self): |
| 12 |
""" Create and post a manual checks with deferred date """ |
| 13 |
|
| 14 |
with Form(self.env['account.payment'].with_context(default_payment_type='outbound')) as payment_form: |
| 15 |
payment_form.partner_id = self.partner_a |
| 16 |
payment_form.journal_id = self.bank_journal |
| 17 |
payment_form.payment_method_line_id = self.bank_journal._get_available_payment_method_lines( |
| 18 |
'outbound').filtered(lambda x: x.code == 'own_checks')[0] |
| 19 |
payment_form.memo = 'Deferred check' |
| 20 |
with payment_form.l10n_latam_new_check_ids.new() as check1: |
| 21 |
check1.name = '00000001' |
| 22 |
check1.payment_date = fields.Date.add(fields.Date.today(), months=1) |
| 23 |
check1.issuer_vat = '30714295698' |
| 24 |
check1.amount = 25 |
| 25 |
|
| 26 |
with payment_form.l10n_latam_new_check_ids.new() as check2: |
| 27 |
check2.name = '00000002' |
| 28 |
check2.payment_date = fields.Date.add(fields.Date.today(), months=1) |
| 29 |
check2.issuer_vat = '30714295698' |
| 30 |
check2.amount = 25 |
| 31 |
|
| 32 |
payment = payment_form.save() |
| 33 |
payment.action_post() |
| 34 |
self.assertEqual(payment.amount, 50) |
| 35 |
outstanding_line_ids = payment.l10n_latam_new_check_ids.mapped('outstanding_line_id') |
| 36 |
self.assertEqual(len(outstanding_line_ids), 2, "There should be a split line per check. (2)") |
| 37 |
all_handed = any(s == 'handed' for s in payment.l10n_latam_new_check_ids.mapped('issue_state')) |
| 38 |
self.assertTrue(all_handed, "All checks should be in handed status.") |
| 39 |
first_check = payment.l10n_latam_new_check_ids[0] |
| 40 |
first_check.action_void() |
| 41 |
self.assertTrue(first_check.issue_state == 'voided', "First checks should be in voided status.") |
| 42 |
|
| 43 |
def test_02_pay_with_own_check_and_cancel_payment(self): |
| 44 |
""" Create and post a manual check with deferred date ands cancel it """ |
| 45 |
|
| 46 |
with Form(self.env['account.payment'].with_context(default_payment_type='outbound')) as payment_form: |
| 47 |
payment_form.partner_id = self.partner_a |
| 48 |
payment_form.journal_id = self.bank_journal |
| 49 |
payment_form.payment_method_line_id = self.bank_journal._get_available_payment_method_lines( |
| 50 |
'outbound').filtered(lambda x: x.code == 'own_checks')[0] |
| 51 |
|
| 52 |
payment_form.memo = 'Deferred check' |
| 53 |
with payment_form.l10n_latam_new_check_ids.new() as check1: |
| 54 |
check1.name = '00000003' |
| 55 |
check1.payment_date = fields.Date.add(fields.Date.today(), months=1) |
| 56 |
check1.issuer_vat = '30714295698' |
| 57 |
check1.amount = 50 |
| 58 |
|
| 59 |
payment = payment_form.save() |
| 60 |
payment.action_post() |
| 61 |
self.assertEqual(payment.amount, 50) |
| 62 |
payment.action_cancel() |
| 63 |
self.assertFalse(payment.l10n_latam_new_check_ids.issue_state, |
| 64 |
"Canceled payment checks must not have issue state") |
| 65 |
self.assertEqual(len(payment.l10n_latam_new_check_ids.outstanding_line_id), 0, |
| 66 |
"Canceled payment checks must not have split move") |
| 67 |
|
| 68 |
def test_post_own_check_with_3_lines(self): |
| 69 |
foreign_currency = self.env.ref('base.EUR') |
| 70 |
foreign_currency.active = True |
| 71 |
payment_method_line = self.bank_journal._get_available_payment_method_lines('outbound').filtered_domain([('code', '=', 'own_checks')])[:1] |
| 72 |
payment = self.env['account.payment'].create({ |
| 73 |
'payment_type': 'outbound', |
| 74 |
'partner_id': self.partner_a.id, |
| 75 |
'journal_id': self.bank_journal.id, |
| 76 |
'currency_id': foreign_currency.id, |
| 77 |
'payment_method_line_id': payment_method_line.id, |
| 78 |
'l10n_latam_new_check_ids': [ |
| 79 |
Command.create({ |
| 80 |
'payment_date': fields.Date.today(), |
| 81 |
'amount': '20', |
| 82 |
}), |
| 83 |
Command.create({ |
| 84 |
'payment_date': fields.Date.today(), |
| 85 |
'amount': '30', |
| 86 |
}), |
| 87 |
Command.create({ |
| 88 |
'payment_date': fields.Date.today(), |
| 89 |
'amount': '70', |
| 90 |
}), |
| 91 |
] |
| 92 |
}) |
| 93 |
payment.action_post() |
| 94 |
self.assertEqual(payment.amount, 120) |