Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
sale_order_secondary_unit/tests/__init__.py
Executable file
3
sale_order_secondary_unit/tests/__init__.py
Executable file
@@ -0,0 +1,3 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from . import test_product_template
|
||||
from . import test_sale_order
|
||||
135
sale_order_secondary_unit/tests/test_product_template.py
Executable file
135
sale_order_secondary_unit/tests/test_product_template.py
Executable file
@@ -0,0 +1,135 @@
|
||||
# Copyright 2018-2020 Tecnativa - Carlos Dauden
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestProductTemplate(BaseCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||
cls.product_attribute_model = cls.env["product.attribute"]
|
||||
cls.product_attribute_value_model = cls.env["product.attribute.value"]
|
||||
# Create product attributes
|
||||
cls.color_attribute = cls.product_attribute_model.create(
|
||||
{
|
||||
"name": "Test Color (sale_order_secondary_unit)",
|
||||
"create_variant": "always",
|
||||
}
|
||||
)
|
||||
cls.color_values = cls.product_attribute_value_model.create(
|
||||
[
|
||||
{"name": "Red", "attribute_id": cls.color_attribute.id},
|
||||
{"name": "Blue", "attribute_id": cls.color_attribute.id},
|
||||
{"name": "Green", "attribute_id": cls.color_attribute.id},
|
||||
]
|
||||
)
|
||||
cls.size_attribute = cls.product_attribute_model.create(
|
||||
{
|
||||
"name": "Test Size (sale_order_secondary_unit)",
|
||||
"create_variant": "always",
|
||||
}
|
||||
)
|
||||
cls.size_values = cls.product_attribute_value_model.create(
|
||||
[
|
||||
{"name": "S", "attribute_id": cls.size_attribute.id},
|
||||
{"name": "M", "attribute_id": cls.size_attribute.id},
|
||||
{"name": "L", "attribute_id": cls.size_attribute.id},
|
||||
]
|
||||
)
|
||||
|
||||
# Create product template
|
||||
cls.product_template_1 = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Test Product 1",
|
||||
}
|
||||
)
|
||||
# Create product variants
|
||||
cls.product_template_2 = cls.env["product.template"].create(
|
||||
{
|
||||
"name": "Test Product 2",
|
||||
"attribute_line_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"attribute_id": cls.color_attribute.id,
|
||||
"value_ids": [(6, 0, cls.color_values.ids)],
|
||||
},
|
||||
),
|
||||
Command.create(
|
||||
{
|
||||
"attribute_id": cls.size_attribute.id,
|
||||
"value_ids": [(6, 0, cls.size_values.ids)],
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
# Create secondary units
|
||||
cls.secondary_uom_1 = cls.env["product.secondary.unit"].create(
|
||||
{
|
||||
"name": "Unit 1",
|
||||
"uom_id": cls.product_uom_unit.id,
|
||||
"factor": 1,
|
||||
"product_tmpl_id": cls.product_template_1.id,
|
||||
}
|
||||
)
|
||||
cls.secondary_uom_2 = cls.env["product.secondary.unit"].create(
|
||||
{
|
||||
"name": "Unit 2",
|
||||
"uom_id": cls.product_uom_unit.id,
|
||||
"factor": 1,
|
||||
"product_tmpl_id": cls.product_template_1.id,
|
||||
}
|
||||
)
|
||||
cls.secondary_uom_3 = cls.env["product.secondary.unit"].create(
|
||||
{
|
||||
"name": "Unit 3",
|
||||
"uom_id": cls.product_uom_unit.id,
|
||||
"factor": 1,
|
||||
"product_tmpl_id": cls.product_template_2.id,
|
||||
}
|
||||
)
|
||||
cls.secondary_uom_4 = cls.env["product.secondary.unit"].create(
|
||||
{
|
||||
"name": "Unit 4",
|
||||
"uom_id": cls.product_uom_unit.id,
|
||||
"factor": 1,
|
||||
"product_tmpl_id": cls.product_template_2.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_create_sets_sale_secondary_uom_id_for_single_variant(self):
|
||||
product_variant_ids = self.product_template_1.product_variant_ids
|
||||
product_variant_ids.sale_secondary_uom_id = self.secondary_uom_1
|
||||
self.assertEqual(self.product_template_1.sale_secondary_uom_id.name, "Unit 1")
|
||||
|
||||
def test_create_not_sale_secondary_uom_id_for_variants_and_warns(self):
|
||||
product_variant_ids = self.product_template_2.product_variant_ids
|
||||
product_variant_ids[0].sale_secondary_uom_id = self.secondary_uom_3
|
||||
product_variant_ids[1].sale_secondary_uom_id = self.secondary_uom_4
|
||||
self.assertFalse(self.product_template_2.sale_secondary_uom_id)
|
||||
|
||||
warning = self.product_template_2.onchange_sale_secondary_uom_id()
|
||||
self.assertIn("warning", warning)
|
||||
self.assertIn(
|
||||
"Product variants have distinct sale secondary uom",
|
||||
warning["warning"]["message"],
|
||||
)
|
||||
|
||||
def test_create_sale_secondary_uom_id_multiple_variants_same_uom(self):
|
||||
product_variant_ids = self.product_template_2.product_variant_ids
|
||||
product_variant_ids[0].sale_secondary_uom_id = self.secondary_uom_3
|
||||
product_variant_ids[1].sale_secondary_uom_id = self.secondary_uom_3
|
||||
self.assertEqual(self.product_template_2.sale_secondary_uom_id.name, "Unit 3")
|
||||
|
||||
def test_inverse_sale_secondary_uom_id_updates_variants_correctly(self):
|
||||
self.product_template_1.sale_secondary_uom_id = self.secondary_uom_2
|
||||
self.product_template_1._inverse_sale_secondary_uom_id()
|
||||
self.assertEqual(
|
||||
self.product_template_1.product_variant_ids.sale_secondary_uom_id,
|
||||
self.product_template_1.sale_secondary_uom_id,
|
||||
)
|
||||
109
sale_order_secondary_unit/tests/test_sale_order.py
Executable file
109
sale_order_secondary_unit/tests/test_sale_order.py
Executable file
@@ -0,0 +1,109 @@
|
||||
# Copyright 2018-2020 Tecnativa - Carlos Dauden
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import Command
|
||||
from odoo.tests import Form, tagged
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestSaleOrder(BaseCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
# Remove this variable in v16 and put instead:
|
||||
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
|
||||
cls.product_uom_kg = cls.env.ref("uom.product_uom_kgm")
|
||||
cls.product_uom_gram = cls.env.ref("uom.product_uom_gram")
|
||||
cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "test",
|
||||
"uom_id": cls.product_uom_kg.id,
|
||||
"uom_po_id": cls.product_uom_kg.id,
|
||||
"list_price": 1000,
|
||||
}
|
||||
)
|
||||
# Set secondary uom on product template
|
||||
cls.product.product_tmpl_id.write(
|
||||
{
|
||||
"secondary_uom_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"name": "unit-500",
|
||||
"uom_id": cls.product_uom_unit.id,
|
||||
"factor": 0.5,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.secondary_unit = cls.env["product.secondary.unit"].search(
|
||||
[("product_tmpl_id", "=", cls.product.product_tmpl_id.id)]
|
||||
)
|
||||
cls.product.sale_secondary_uom_id = cls.secondary_unit.id
|
||||
cls.partner = cls.env["res.partner"].create({"name": "test - partner"})
|
||||
with Form(cls.env["sale.order"]) as order_form:
|
||||
order_form.partner_id = cls.partner
|
||||
with order_form.order_line.new() as line_form:
|
||||
line_form.product_id = cls.product
|
||||
line_form.product_uom_qty = 1
|
||||
cls.order = order_form.save()
|
||||
|
||||
def test_onchange_secondary_uom(self):
|
||||
self.order.order_line.write(
|
||||
{"secondary_uom_id": self.secondary_unit.id, "secondary_uom_qty": 5}
|
||||
)
|
||||
self.order.order_line._compute_product_uom_qty()
|
||||
self.assertEqual(self.order.order_line.product_uom_qty, 2.5)
|
||||
|
||||
def test_onchange_secondary_unit_product_uom_qty(self):
|
||||
self.order.order_line.update(
|
||||
{"secondary_uom_id": self.secondary_unit.id, "product_uom_qty": 3.5}
|
||||
)
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 7.0)
|
||||
|
||||
def test_default_secondary_unit(self):
|
||||
self.order.order_line._onchange_product_id_warning()
|
||||
self.assertEqual(self.order.order_line.secondary_uom_id, self.secondary_unit)
|
||||
|
||||
def test_onchange_order_product_uom(self):
|
||||
self.order.order_line.update(
|
||||
{
|
||||
"secondary_uom_id": self.secondary_unit.id,
|
||||
"product_uom": self.product_uom_gram.id,
|
||||
"product_uom_qty": 3500.00,
|
||||
}
|
||||
)
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 7.0)
|
||||
|
||||
def test_independent_type(self):
|
||||
# dependent type is already tested as dependency_type by default
|
||||
self.order.order_line.secondary_uom_id = self.secondary_unit.id
|
||||
self.order.order_line.secondary_uom_id.write({"dependency_type": "independent"})
|
||||
|
||||
# Remember previous UoM quantity for avoiding interactions with other modules
|
||||
previous_uom_qty = self.order.order_line.product_uom_qty
|
||||
self.order.order_line.write({"secondary_uom_qty": 2})
|
||||
self.assertEqual(self.order.order_line.product_uom_qty, previous_uom_qty)
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 2)
|
||||
|
||||
self.order.order_line.write({"product_uom_qty": 17})
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 2)
|
||||
self.assertEqual(self.order.order_line.product_uom_qty, 17)
|
||||
|
||||
def test_secondary_uom_unit_price(self):
|
||||
# Remove secondary uom in sale line to do a complete test of secondary price
|
||||
self.order.order_line.secondary_uom_id = False
|
||||
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 0)
|
||||
self.order.order_line.update(
|
||||
{"secondary_uom_id": self.secondary_unit.id, "product_uom_qty": 2}
|
||||
)
|
||||
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 4)
|
||||
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500)
|
||||
|
||||
self.order.order_line.write({"product_uom_qty": 8})
|
||||
self.assertEqual(self.order.order_line.secondary_uom_qty, 16)
|
||||
self.assertEqual(self.order.order_line.secondary_uom_unit_price, 500)
|
||||
self.assertEqual(self.order.order_line.price_subtotal, 8000)
|
||||
Reference in New Issue
Block a user