Skip to content
Permalink
Browse files

[FIX] account: add performance test

The test is split to ease forward-port.

opw 2121587

Co-authored by: François Honoré <francois.honore@acsone.eu>

closes #41053

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
  • Loading branch information
len-odoo committed Nov 26, 2019
1 parent 5db13a3 commit 7f0c8155f48492ff79c07af06cdf4196ff7587a3
Showing with 80 additions and 0 deletions.
  1. +1 −0 addons/account/tests/__init__.py
  2. +79 −0 addons/account/tests/test_reconciliation_heavy_load.py
@@ -22,3 +22,4 @@
from . import test_account_fiscal_year
from . import test_account_all_l10n
from . import test_reconciliation_matching_rules
from . import test_reconciliation_heavy_load
@@ -0,0 +1,79 @@
from odoo import api, fields
from odoo.tests import tagged
from odoo.addons.account.tests.account_test_classes import AccountingTestCase


@tagged('post_install', '-at_install')
class TestReconciliationHeavyLoad(AccountingTestCase):
"""Check that reconciliation can be done for a move with many lines
"""

def _create_move(self, journal):
values = {
'ref': "Test reconcile - Auto-generated by script",
'journal_id': journal.id,
'state': 'draft',
'company_id': journal.env.user.company_id.id,
}
return journal.env['account.move'].create(values)

def _get_values_account_move_line(
self, account, journal, name, move,
credit=0, debit=0, date=fields.Date.today()):
return {
'journal_id': journal.id,
'name': name,
'account_id': account.id,
'move_id': move.id,
'quantity': 1,
'credit': credit,
'debit': debit,
'date': date,
}

def setUp(self):
super(TestReconciliationHeavyLoad, self).setUp()

self.account_type = self.env.ref('account.data_account_type_receivable')

self.journal = self.env['account.journal'].search([
('type', '=', 'bank'),
('company_id', '=', self.env.user.company_id.id),
], limit=1)

self.account = self.env['account.account'].search([
('user_type_id', '=', self.account_type.id),
('company_id', '=', self.env.user.company_id.id),
], limit=1)

def test_heavy_load_reconciliation(self):
"""Does reconciliation on a move with nb_lines lines.
To avoid burdening uselessly the runbot, we only set nb_lines to 10,
but it should be of order 10^3 to be meaningful.
The day we manage to use system build settings to execute tests
this could be done automatically for "heavy load builds",
but for now this should be changed manually.
"""

total = 0
line_ids = []
amount_per_line = 1
nb_lines = 10 # change this to 1000 or more
move = self._create_move(self.journal)

for i in range(nb_lines):
name = "Move line credit #%s" % i
total += amount_per_line
values = self._get_values_account_move_line(
self.account, self.journal, name, move, credit=amount_per_line)
line_ids.append((0, False, values))

values = self._get_values_account_move_line(
self.account, self.journal, "Move line Debit", move, debit=total)
line_ids.append((0, False, values))

move.write({'line_ids': line_ids})

move.line_ids.reconcile()

self.assertTrue(all(move.line_ids.mapped('reconciled')))

0 comments on commit 7f0c815

Please sign in to comment.
You can’t perform that action at this time.