From 7b82fc1fe1047439ff42f3285384ab97cfb57323 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 20 Mar 2020 18:19:34 +0100 Subject: [PATCH] [IMP] sale_stock: Add query counter test on SO batch creation This is be a correct metric to ensure the onchanges convertion into compute methods using precompute attribute is going in the right direction. --- addons/sale_stock/tests/__init__.py | 1 + addons/sale_stock/tests/test_create_perf.py | 56 +++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 addons/sale_stock/tests/test_create_perf.py diff --git a/addons/sale_stock/tests/__init__.py b/addons/sale_stock/tests/__init__.py index 3dde82064a6..5c84998bb9b 100644 --- a/addons/sale_stock/tests/__init__.py +++ b/addons/sale_stock/tests/__init__.py @@ -10,3 +10,4 @@ from . import test_sale_order_dates from . import test_sale_stock_multicompany from . import test_sale_stock_accrued_entries from . import test_sale_stock_access_rights +from . import test_create_perf diff --git a/addons/sale_stock/tests/test_create_perf.py b/addons/sale_stock/tests/test_create_perf.py new file mode 100644 index 00000000000..962cc585c53 --- /dev/null +++ b/addons/sale_stock/tests/test_create_perf.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging +import time + +from odoo.tests import common, tagged +from odoo.tests.common import users, warmup + +_logger = logging.getLogger(__name__) + + +@tagged('so_batch_perf') +class TestPERF(common.TransactionCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ENTITIES = 50 + + cls.products = cls.env['product.product'].create([{ + 'name': 'Product %s' % i, + 'list_price': 1 + 10 * i, + 'type': 'service', + } for i in range(10)]) + + cls.partners = cls.env['res.partner'].create([{ + 'name': 'Partner %s' % i, + } for i in range(cls.ENTITIES)]) + + cls.salesmans = cls.env.ref('base.user_admin') | cls.env.ref('base.user_demo') + + cls.env['base'].flush() + + @users('admin') + @warmup + def test_sales_orders_batch_creation_perf(self): + MSG = "Model %s, %i records, %s, time %.2f" + + vals_list = [{ + "partner_id": self.partners[i].id, + "user_id": self.salesmans[i % 2].id, + "order_line": [ + (0, 0, {"display_type": "line_note", "name": "NOTE"}) + ] + [ + (0, 0, {'product_id': product.id}) for product in self.products + ], + } for i in range(self.ENTITIES)] + + with self.assertQueryCount(admin=2753): + t0 = time.time() + self.env["sale.order"].create(vals_list) + t1 = time.time() + _logger.info(MSG, 'sale.order', self.ENTITIES, "BATCH", t1 - t0) + self.env.cr.flush() + _logger.info(MSG, 'sale.order', self.ENTITIES, "FLUSH", time.time() - t1)