summaryrefslogtreecommitdiff
path: root/addons/account_check_printing/tests/test_print_check.py
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2019-10-29 12:21:27 +0000
committerqdp-odoo <qdp@odoo.com>2020-04-10 09:47:24 +0000
commitcaeb782841fc5a7ad71a196e2c9ee67644ef9074 (patch)
tree28103bc29ab4f0d98162095f607c4c6ab1433f25 /addons/account_check_printing/tests/test_print_check.py
parentb4d1360ed1d71c8fda44ca0c3b1a80d5a112b93f (diff)
[IMP] account,*: Improve bank statements/payments workflow
- Create journal entries as soon as bank/cash statement lines are created, temporary booked on a suspense account set on the journal. - Simplify the management of "blue" lines in the reconciliation widget. A "blue" line is now a journal item using a temporary liquidity account (outstanding payment/receipt accounts, set on the journal). - Adapt and simplify the bank reconciliation report. - Remove the bank reconciliation threshold date. The reconciliation report will show the not already reconciled journal entries using a liquidity account and the not already reconciled journal entries using a temporary liquidity account. Without accounting, an account.payment will involve directly the liquidity account and then, will be considered as a statement line directly. - Remove the post_at bank reconciliation feature. The "paid" state will be set on the invoices only if reconciled with a journal entry involving the journal's liquidity account. With invoicing, the payment will do that so the "in_payment" state should never be shown up. With accounting, only the statement lines have the power to move an invoice to the "paid" state. - Fix various corner cases about the management of multi-currency in bank statement lines. - Fix the conversion dates in multi-currency: Since the bank/cash is always used on the statement lines, it will use always the real "bank" date instead of the fictive payment one. - Ensure the 'reconcile' method will raise an error if the involved moves are not posted. related enterprise PR odoo/enterprise#7019 closes odoo/odoo#41301 --task: 2092096 Related: odoo/upgrade#1018 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
Diffstat (limited to 'addons/account_check_printing/tests/test_print_check.py')
-rw-r--r--addons/account_check_printing/tests/test_print_check.py152
1 files changed, 88 insertions, 64 deletions
diff --git a/addons/account_check_printing/tests/test_print_check.py b/addons/account_check_printing/tests/test_print_check.py
index 1a79d7c419b..d693bdc3bb4 100644
--- a/addons/account_check_printing/tests/test_print_check.py
+++ b/addons/account_check_printing/tests/test_print_check.py
@@ -1,81 +1,105 @@
-# Make sure / performs a floating point division even if environment is python 2
-from __future__ import division
-
-from odoo.addons.account.tests.common import AccountTestCommon
+# -*- coding: utf-8 -*-
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.account_check_printing.models.account_payment import INV_LINES_PER_STUB
from odoo.tests import tagged
-from odoo.tests.common import Form
-import time
-import math
+import math
@tagged('post_install', '-at_install')
-class TestPrintCheck(AccountTestCommon):
+class TestPrintCheck(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
- super(TestPrintCheck, cls).setUpClass()
+ super().setUpClass()
- cls.invoice_model = cls.env['account.move']
- cls.invoice_line_model = cls.env['account.move.line']
- cls.payment_model = cls.env['account.payment']
-
- cls.partner_axelor = cls.env['res.partner'].create({'name': 'A Partner'})
- cls.product = cls.env['product.product'].create({'name': 'A test Product'})
cls.payment_method_check = cls.env.ref("account_check_printing.account_payment_method_check")
- cls.account_payable = cls.env['account.account'].search([('user_type_id', '=', cls.env.ref('account.data_account_type_payable').id)], limit=1)
- cls.account_expenses = cls.env['account.account'].search([('user_type_id', '=', cls.env.ref('account.data_account_type_expenses').id)], limit=1)
-
- cls.bank_journal = cls.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'BNK67'})
- cls.bank_journal.check_manual_sequencing = True
-
- def create_invoice(self, amount=100, is_refund=False):
- invoice = self.env['account.move'].with_context(default_move_type=is_refund and 'out_refund' or 'in_invoice').create({
- 'partner_id': self.partner_axelor.id,
- 'invoice_date': time.strftime('%Y') + '-06-26',
- 'date': time.strftime('%Y') + '-06-26',
- 'invoice_line_ids': [
- (0, 0, {
- 'product_id': self.product.id,
- 'quantity': 1,
- 'price_unit': is_refund and amount / 4 or amount,
- })
- ]
+ cls.company_data['default_journal_bank'].write({
+ 'outbound_payment_method_ids': [(6, 0, (
+ cls.env.ref('account.account_payment_method_manual_out').id,
+ cls.payment_method_check.id,
+ ))],
})
- invoice.post()
- return invoice
-
- def create_payment(self, invoices):
- payment_register = Form(self.env['account.payment'].with_context(active_model='account.move', active_ids=invoices.ids))
- payment_register.payment_date = time.strftime('%Y') + '-07-15'
- payment_register.journal_id = self.bank_journal
- payment_register.payment_method_id = self.payment_method_check
- payment = payment_register.save()
- payment.post()
- return payment
-
- def test_print_check(self):
- # Make a payment for 10 invoices and 5 credit notes
- invoices = self.env['account.move']
- for i in range(0, 15):
- invoices |= self.create_invoice(is_refund=(i % 3 == 0))
- payment = self.create_payment(invoices)
- self.assertEqual(all(payment.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')
- self.assertEqual(all(payment.mapped('check_number')), True, 'The check number is not set on all the payments')
-
- # Check the data generated for the report
- self.env.ref('base.main_company').write({'account_check_printing_multi_stub': True})
+
+ def test_inbound_check_manual_sequencing(self):
+ ''' Test the check generation for customer invoices. '''
+ nb_invoices_to_test = INV_LINES_PER_STUB + 1
+
+ self.company_data['default_journal_bank'].write({
+ 'check_manual_sequencing': True,
+ 'check_next_number': 42,
+ })
+
+ # Create 10 customer invoices.
+ out_invoices = self.env['account.move'].create([{
+ 'move_type': 'out_invoice',
+ 'partner_id': self.partner_a.id,
+ 'date': '2017-01-01',
+ 'invoice_date': '2017-01-01',
+ 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 100.0})]
+ } for i in range(nb_invoices_to_test)])
+ out_invoices.post()
+
+ # Create a single payment.
+ payment = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=out_invoices.ids).create({
+ 'group_payment': True,
+ 'payment_method_id': self.payment_method_check.id,
+ })._create_payments()
+
+ # Check created payment.
+ self.assertRecordValues(payment, [{
+ 'payment_method_id': self.payment_method_check.id,
+ 'check_amount_in_words': payment.currency_id.amount_to_text(100.0 * nb_invoices_to_test),
+ 'check_number': '00042',
+ }])
+
+ # Check pages.
+ self.company_data['company'].account_check_printing_multi_stub = True
report_pages = payment._check_get_pages()
- self.assertEqual(len(report_pages), int(math.ceil(len(payment.reconciled_invoice_ids) / INV_LINES_PER_STUB)))
- self.env.ref('base.main_company').write({'account_check_printing_multi_stub': False})
+ self.assertEqual(len(report_pages), int(math.ceil(len(out_invoices) / INV_LINES_PER_STUB)))
+
+ self.company_data['company'].account_check_printing_multi_stub = False
report_pages = payment._check_get_pages()
self.assertEqual(len(report_pages), 1)
- def test_from_register(self):
- invoices = self.env['account.move']
- for i in range(0, 3):
- invoices |= self.create_invoice(is_refund=(i % 3 == 0))
- payment = self.create_payment(invoices)
- self.assertEqual(all(payment.mapped('check_amount_in_words')), True, 'The amount in words is not set on all the payments')
+ def test_outbound_check_manual_sequencing(self):
+ ''' Test the check generation for refunds. '''
+ nb_invoices_to_test = INV_LINES_PER_STUB + 1
+
+ self.company_data['default_journal_bank'].write({
+ 'check_manual_sequencing': True,
+ 'check_next_number': 42,
+ })
+
+ # Create 10 refunds.
+ out_refunds = self.env['account.move'].create([{
+ 'move_type': 'out_refund',
+ 'partner_id': self.partner_a.id,
+ 'date': '2017-01-01',
+ 'invoice_date': '2017-01-01',
+ 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 100.0})]
+ } for i in range(nb_invoices_to_test)])
+ out_refunds.post()
+
+ # Create a single payment.
+ payment = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=out_refunds.ids).create({
+ 'group_payment': True,
+ 'payment_method_id': self.payment_method_check.id,
+ })._create_payments()
+
+ # Check created payment.
+ self.assertRecordValues(payment, [{
+ 'payment_method_id': self.payment_method_check.id,
+ 'check_amount_in_words': payment.currency_id.amount_to_text(100.0 * nb_invoices_to_test),
+ 'check_number': '00042',
+ }])
+
+ # Check pages.
+ self.company_data['company'].account_check_printing_multi_stub = True
+ report_pages = payment._check_get_pages()
+ self.assertEqual(len(report_pages), int(math.ceil(len(out_refunds) / INV_LINES_PER_STUB)))
+
+ self.company_data['company'].account_check_printing_multi_stub = False
+ report_pages = payment._check_get_pages()
+ self.assertEqual(len(report_pages), 1)