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

IMP: allow inheritance on tests #58

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this import is useless as you import it from the required python module.

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", "-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