Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FW] [15.0][IMP] bank-payment : test performance improvement #1350

90 changes: 42 additions & 48 deletions account_banking_mandate/tests/test_invoice_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo.tests.common import TransactionCase

from odoo.addons.account.models.account_payment_method import AccountPaymentMethod
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestInvoiceMandate(TransactionCase):
Expand Down Expand Up @@ -192,112 +193,105 @@ def test_invoice_constrains(self):
with self.assertRaises(UserError):
invoice.mandate_id = mandate_2

def _create_res_partner(self, name):
return self.env["res.partner"].create({"name": name})
@classmethod
def _create_res_partner(cls, name):
return cls.env["res.partner"].create({"name": name})

def _create_res_bank(self, name, bic, city, country):
return self.env["res.bank"].create(
@classmethod
def _create_res_bank(cls, name, bic, city, country):
return cls.env["res.bank"].create(
{"name": name, "bic": bic, "city": city, "country": country.id}
)

def setUp(self):
res = super(TestInvoiceMandate, self).setUp()
self.company = self.env.ref("base.main_company")

self.partner = self._create_res_partner("Peter with ACME Bank")
self.acme_bank = self._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", self.env.ref("base.be")
@classmethod
def setUpClass(cls):
res = super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.company = cls.env.ref("base.main_company")
cls.partner = cls._create_res_partner("Peter with ACME Bank")
cls.acme_bank = cls._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", cls.env.ref("base.be")
)

bank_account = self.env["res.partner.bank"].create(
bank_account = cls.env["res.partner.bank"].create(
{
"acc_number": "0023032234211123",
"partner_id": self.partner.id,
"bank_id": self.acme_bank.id,
"company_id": self.company.id,
"partner_id": cls.partner.id,
"bank_id": cls.acme_bank.id,
"company_id": cls.company.id,
}
)

self.company_2 = self.env["res.company"].create({"name": "Company 2"})

self.mandate = self.env["account.banking.mandate"].create(
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)

self.mandate.validate()

self.mode_inbound_acme = self.env["account.payment.mode"].create(
cls.mandate.validate()
cls.mode_inbound_acme = cls.env["account.payment.mode"].create(
{
"name": "Inbound Credit ACME Bank",
"company_id": self.company.id,
"company_id": cls.company.id,
"bank_account_link": "variable",
"payment_method_id": self.env.ref(
"payment_method_id": cls.env.ref(
"account.account_payment_method_manual_in"
).id,
}
)
bank_journal = self.env["account.journal"].search(
bank_journal = cls.env["account.journal"].search(
[
("type", "=", "bank"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
self.mode_inbound_acme.variable_journal_ids = bank_journal
self.mode_inbound_acme.payment_method_id.mandate_required = True
self.mode_inbound_acme.payment_order_ok = True

self.partner.customer_payment_mode_id = self.mode_inbound_acme

self.invoice_account = self.env["account.account"].search(
cls.mode_inbound_acme.variable_journal_ids = bank_journal
cls.mode_inbound_acme.payment_method_id.mandate_required = True
cls.mode_inbound_acme.payment_order_ok = True
cls.partner.customer_payment_mode_id = cls.mode_inbound_acme
cls.invoice_account = cls.env["account.account"].search(
[
("account_type", "=", "asset_receivable"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
invoice_line_account = (
self.env["account.account"]
cls.env["account.account"]
.search(
[
("account_type", "=", "expense"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
.id
)

invoice_vals = [
(
0,
0,
{
"product_id": self.env.ref("product.product_product_4").id,
"product_id": cls.env.ref("product.product_product_4").id,
"quantity": 1.0,
"account_id": invoice_line_account,
"price_unit": 200.00,
},
)
]

self.invoice = self.env["account.move"].create(
cls.invoice = cls.env["account.move"].create(
{
"partner_id": self.partner.id,
"partner_id": cls.partner.id,
"move_type": "out_invoice",
"company_id": self.company.id,
"journal_id": self.env["account.journal"]
"company_id": cls.company.id,
"journal_id": cls.env["account.journal"]
.search(
[("type", "=", "sale"), ("company_id", "=", self.company.id)],
[("type", "=", "sale"), ("company_id", "=", cls.company.id)],
limit=1,
)
.id,
"invoice_line_ids": invoice_vals,
}
)

return res
25 changes: 15 additions & 10 deletions account_banking_mandate/tests/test_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestMandate(TransactionCase):
def setUp(self):
super(TestMandate, self).setUp()
self.company = self.env.company
self.company_2 = self.env["res.company"].create({"name": "company 2"})
self.company_2.partner_id.company_id = self.company_2.id
self.bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
self.bank_account.partner_id.company_id = self.company.id
self.mandate = self.env["account.banking.mandate"].create(
@classmethod
def setUpClass(cls):
res = super(TestMandate, cls).setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.company = cls.env.ref("base.main_company")
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
cls.company_2.partner_id.company_id = cls.company_2.id
cls.bank_account = cls.env.ref("account_payment_mode.res_partner_12_iban")
cls.bank_account.partner_id.company_id = cls.company.id
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": self.bank_account.id,
"partner_bank_id": cls.bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)
return res

def test_mandate_01(self):
self.assertEqual(self.mandate.state, "draft")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
from odoo import fields
from odoo.tests.common import Form, TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestAccountPaymentOrder(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.partner_bank_core = cls._create_res_partner_bank("N-CORE")
Expand Down
3 changes: 3 additions & 0 deletions account_banking_sepa_credit_transfer/tests/test_sct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestSCT(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.account_model = cls.env["account.account"]
cls.move_model = cls.env["account.move"]
cls.journal_model = cls.env["account.journal"]
Expand Down
21 changes: 16 additions & 5 deletions account_banking_sepa_direct_debit/tests/test_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ def test_action_mandate_send(self):
self.assertEqual(self.mandate.state, "draft")
self.assertTrue(self.mandate.is_sent)

def setUp(self):
res = super().setUp()
self.partner = self.env.ref("base.res_partner_12")
bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
self.mandate = self.env["account.banking.mandate"].create(
@classmethod
def setUpClass(cls):
res = super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.partner = cls.env.ref("base.res_partner_12")
bank_account = cls.env.ref("account_payment_mode.res_partner_12_iban")
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": bank_account.id,
"format": "sepa",
Expand Down
3 changes: 3 additions & 0 deletions account_banking_sepa_direct_debit/tests/test_sdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
from odoo.tests.common import TransactionCase
from odoo.tools import float_compare

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestSDDBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.company_B = cls.env["res.company"].create({"name": "Company B"})
cls.account_payable_company_B = cls.env["account.account"].create(
{
Expand Down
4 changes: 3 additions & 1 deletion account_payment_mode/tests/test_account_payment_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestAccountPaymentMode(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

cls.res_users_model = cls.env["res.users"]
cls.journal_model = cls.env["account.journal"]
Expand Down
7 changes: 7 additions & 0 deletions account_payment_order/tests/test_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestBank(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

def test_bank(self):
bank = self.env["res.bank"].search([], limit=1)
self.assertTrue(bank)
Expand Down
4 changes: 2 additions & 2 deletions account_payment_order/tests/test_payment_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def setUpClass(cls):
AccountPaymentMethod._get_payment_method_information
)

def _get_payment_method_information(self):
res = Method_get_payment_method_information(self)
def _get_payment_method_information(cls):
res = Method_get_payment_method_information(cls)
res["IN"] = {"mode": "multi", "domain": [("type", "=", "bank")]}
res["IN2"] = {"mode": "multi", "domain": [("type", "=", "bank")]}
res["electronic_out"] = {"mode": "multi", "domain": [("type", "=", "bank")]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from odoo.fields import Date
from odoo.tests.common import Form, TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class TestAccountPaymentPartner(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

cls.res_users_model = cls.env["res.users"]
cls.move_model = cls.env["account.move"]
Expand Down
5 changes: 3 additions & 2 deletions account_payment_sale/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


class CommonTestCase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))

cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.bank = cls.env["res.partner.bank"].create(
{"acc_number": "test", "partner_id": cls.env.user.company_id.partner_id.id}
)
Expand Down
7 changes: 7 additions & 0 deletions account_payment_sale/tests/test_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

from odoo.tests import Form

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT

from .common import CommonTestCase


class TestSaleOrder(CommonTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

def create_sale_order(self, payment_mode=None):
with Form(self.env["sale.order"]) as sale_form:
sale_form.partner_id = self.base_partner
Expand Down
Loading