[IMP] core,sale: enforce batch creation support for sale order (lines)
This commit is contained in:
committed by
Yannick Tivisse
parent
b8a0fe79f4
commit
69dc4bba42
@@ -5,6 +5,7 @@ from . import test_access_rights
|
||||
from . import test_accrued_sale_orders
|
||||
from . import test_onchange
|
||||
from . import test_payment_flow
|
||||
from . import test_performance
|
||||
from . import test_reinvoice
|
||||
from . import test_sale_flow
|
||||
from . import test_sale_order
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.base.tests.common import PerformanceCommon
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestSalePerformance(PerformanceCommon):
|
||||
|
||||
def test_batch_creation_sale_orders(self):
|
||||
"""Enforce sale.order create overrides always support batch creation"""
|
||||
self.assertModelCreateMulti('sale.order')
|
||||
|
||||
def test_batch_creation_sale_order_line(self):
|
||||
"""Enforce sale.order.line create overrides always support batch creation"""
|
||||
self.assertModelCreateMulti('sale.order.line')
|
||||
@@ -8,6 +8,27 @@ from odoo.tests.common import TransactionCase, HttpCase
|
||||
from odoo import Command
|
||||
|
||||
|
||||
class PerformanceCommon(TransactionCase):
|
||||
|
||||
def assertModelCreateMulti(self, model_name, vals_list=None):
|
||||
"""Ensures model_name records can be created in batch.
|
||||
|
||||
:param str model_name: name of the model on which batch record creation should be verified
|
||||
:param list vals_list: example list of values, if needed
|
||||
"""
|
||||
vals_list = vals_list or [dict(), dict()]
|
||||
if not isinstance(vals_list, list):
|
||||
raise ValueError("Invalid arguments for assertModelCreateMulti")
|
||||
assert len(vals_list) > 1, "Batch creation cannot be tested with only one value."
|
||||
def patched_create(self, values_list):
|
||||
if len(values_list) != len(vals_list):
|
||||
raise ValueError(f"Model {model_name} doesn't support batch records creation.")
|
||||
# Do not create anything
|
||||
return self
|
||||
with patch('odoo.models.BaseModel.create', patched_create):
|
||||
self.env[model_name].create(vals_list)
|
||||
|
||||
|
||||
class TransactionCaseWithUserDemo(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user