Skip to content

Commit

Permalink
IMP: allow inheritance on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Jun 5, 2023
1 parent b1bc0ef commit 22e9e74
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ repos:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.5.1
rev: 5.12.0
hooks:
- id: isort
name: isort except __init__.py
Expand Down
1 change: 1 addition & 0 deletions sale_configurator_option/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import common
from . import test_sale_order
94 changes: 94 additions & 0 deletions sale_configurator_option/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo.tests import SavepointCase


class SaleOrderCommon(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.sale = cls.env.ref("sale_configurator_option.sale_order_1")
cls.pricelist = cls.env.ref("product.list0")
cls.line_with_opt = cls.env.ref("sale_configurator_option.sale_order_line_1")
cls.line_opt_1 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_1"
)
cls.line_opt_2 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_2"
)
cls.line_opt_3 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_3"
)
cls.product_with_option = cls.env.ref(
"sale_configurator_option.product_with_option"
)
cls.product_option_1 = cls.env.ref("sale_configurator_option.product_option_1")
cls.product_option_2 = cls.env.ref("sale_configurator_option.product_option_2")

@classmethod
def _add_pricelist_item(cls, product, qty, price_unit):
cls.env["product.pricelist.item"].create(
{
"pricelist_id": cls.pricelist.id,
"applied_on": "1_product",
"product_tmpl_id": product.product_tmpl_id.id,
"compute_price": "fixed",
"fixed_price": price_unit,
"min_quantity": qty,
}
)

@classmethod
def _create_sale_order(cls):
return cls.env["sale.order"].create(
{
"partner_id": cls.env.ref("base.res_partner_1").id,
"order_line": [
(
0,
0,
{
"product_id": cls.product_with_option.id,
"product_uom_qty": 2,
"option_ids": [
(
0,
0,
{
"option_unit_qty": 5,
"product_id": cls.product_option_1.id,
"option_qty_type": "proportional_qty",
},
),
(
0,
0,
{
"option_unit_qty": 2,
"product_id": cls.product_option_2.id,
"option_qty_type": "proportional_qty",
},
),
],
},
)
],
}
)

@classmethod
def create_sale_line(cls, product):
sale_line = cls.env["sale.order.line"].create(
{
"name": product.name,
"product_id": product.id,
"product_uom_qty": 1,
"product_uom": product.uom_id.id,
"price_unit": product.list_price,
"order_id": cls.sale.id,
}
)
return sale_line
94 changes: 6 additions & 88 deletions sale_configurator_option/tests/test_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo.tests import SavepointCase
from odoo.tests import tagged

# /!\ /!\ Be carefull when running test /!\ /!\
from odoo.addons.sale_configurator_option.tests.common import SaleOrderCommon

# /!\ /!\ Be carefull when running test with Pytest /!\ /!\
# As Odoo post process the installation of accounting
# you must first install sale module (so the pricelist will be in dollars)
# then you install the sale_configurator_option module so the data are in dollars
# if not you will have inconsistency order in EUR with pricelist in dollars


class SaleOrderCase(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.sale = cls.env.ref("sale_configurator_option.sale_order_1")
cls.pricelist = cls.env.ref("product.list0")
cls.line_with_opt = cls.env.ref("sale_configurator_option.sale_order_line_1")
cls.line_opt_1 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_1"
)
cls.line_opt_2 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_2"
)
cls.line_opt_3 = cls.env.ref(
"sale_configurator_option.sale_order_line_option_3"
)
cls.product_with_option = cls.env.ref(
"sale_configurator_option.product_with_option"
)
cls.product_option_1 = cls.env.ref("sale_configurator_option.product_option_1")
cls.product_option_2 = cls.env.ref("sale_configurator_option.product_option_2")

@classmethod
def _add_pricelist_item(cls, product, qty, price_unit):
cls.env["product.pricelist.item"].create(
{
"pricelist_id": cls.pricelist.id,
"applied_on": "1_product",
"product_tmpl_id": product.product_tmpl_id.id,
"compute_price": "fixed",
"fixed_price": price_unit,
"min_quantity": qty,
}
)

@classmethod
def _create_sale_order(cls):
return cls.env["sale.order"].create(
{
"partner_id": cls.env.ref("base.res_partner_1").id,
"order_line": [
(
0,
0,
{
"product_id": cls.product_with_option.id,
"product_uom_qty": 2,
"option_ids": [
(
0,
0,
{
"option_unit_qty": 5,
"product_id": cls.product_option_1.id,
"option_qty_type": "proportional_qty",
},
),
(
0,
0,
{
"option_unit_qty": 2,
"product_id": cls.product_option_2.id,
"option_qty_type": "proportional_qty",
},
),
],
},
)
],
}
)

def create_sale_line(self, product):
sale_line = self.env["sale.order.line"].create(
{
"name": product.name,
"product_id": product.id,
"product_uom_qty": 1,
"product_uom": product.uom_id.id,
"price_unit": product.list_price,
"order_id": self.sale.id,
}
)
return sale_line

@tagged("post_install/sale", "-at_install")
class SaleOrderCase(SaleOrderCommon):
def test_total_amount(self):
self.assertEqual(self.sale.amount_total, 126.50)
self.assertEqual(self.sale.amount_untaxed, 110)
Expand Down

0 comments on commit 22e9e74

Please sign in to comment.