19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -1,66 +1,75 @@
# -*- coding: utf-8 -*-
from contextlib import nullcontext
from unittest.mock import patch
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.addons.base.tests.common import BaseCommon
from odoo.addons.uom.tests.common import UomCommon
class ProductCommon(
BaseCommon, # enforce constant test currency (USD)
UomCommon,
):
class ProductCommon(UomCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Ideally, this logic should be moved into sthg like a NoAccountCommon in account :D
# Since tax fields are specified in account module, cannot be given as create values
NO_TAXES_CONTEXT = {
'default_taxes_id': False
}
cls.group_product_pricelist = cls.quick_ref('product.group_product_pricelist')
cls.group_product_variant = cls.quick_ref('product.group_product_variant')
cls.product_category = cls.env['product.category'].create({
'name': 'Test Category',
})
cls.product = cls.env['product.product'].with_context(**NO_TAXES_CONTEXT).create({
cls.product, cls.service_product = cls.env['product.product'].create([{
'name': 'Test Product',
'detailed_type': 'consu',
'type': 'consu',
'list_price': 20.0,
'categ_id': cls.product_category.id,
})
cls.service_product = cls.env['product.product'].with_context(**NO_TAXES_CONTEXT).create({
}, {
'name': 'Test Service Product',
'detailed_type': 'service',
'type': 'service',
'list_price': 50.0,
'categ_id': cls.product_category.id,
})
cls.consumable_product = cls.product
}])
cls.pricelist = cls.env['product.pricelist'].create({
'name': 'Test Pricelist',
})
cls._archive_other_pricelists()
# Archive all existing pricelists
cls.env['product.pricelist'].search([
('id', '!=', cls.pricelist.id),
]).action_archive()
@classmethod
def _archive_other_pricelists(cls):
"""Do not raise if there is no pricelist(s) for a given website"""
website_sale = cls.env['ir.module.module']._get('website_sale')
if website_sale.state == 'installed':
archive_context = patch('odoo.addons.website_sale.models.product_pricelist.ProductPricelist._check_website_pricelist')
else:
archive_context = nullcontext()
def get_default_groups(cls):
groups = super().get_default_groups()
return groups | cls.quick_ref('product.group_product_manager')
with archive_context:
cls.env['product.pricelist'].search([
('id', '!=', cls.pricelist.id),
]).action_archive()
@classmethod
def _enable_pricelists(cls):
cls.env.user.group_ids += cls.group_product_pricelist
@classmethod
def _enable_variants(cls):
cls.env.user.group_ids += cls.group_product_variant
@classmethod
def _create_pricelist(cls, **create_vals):
return cls.env['product.pricelist'].create({
'name': "Test Pricelist",
**create_vals,
})
@classmethod
def _create_product(cls, **create_vals):
return cls.env['product.product'].create({
'name': "Test Product",
'type': 'consu',
'list_price': 100.0,
'standard_price': 50.0,
'uom_id': cls.uom_unit.id,
'categ_id': cls.product_category.id,
**create_vals,
})
class ProductAttributesCommon(ProductCommon):
class ProductVariantsCommon(ProductCommon):
@classmethod
def setUpClass(cls):
@ -94,17 +103,31 @@ class ProductAttributesCommon(ProductCommon):
cls.color_attribute_green,
) = cls.color_attribute.value_ids
cls.no_variant_attribute = cls.env['product.attribute'].create({
'name': 'No variant',
'create_variant': 'no_variant',
'value_ids': [
Command.create({'name': 'extra'}),
Command.create({'name': 'second'}),
]
})
(
cls.no_variant_attribute_extra,
cls.no_variant_attribute_second,
) = cls.no_variant_attribute.value_ids
class ProductVariantsCommon(ProductAttributesCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.dynamic_attribute = cls.env['product.attribute'].create({
'name': 'Dynamic',
'create_variant': 'dynamic',
'value_ids': [
Command.create({'name': 'dyn1'}),
Command.create({'name': 'dyn2'}),
]
})
cls.product_template_sofa = cls.env['product.template'].create({
'name': 'Sofa',
'uom_id': cls.uom_unit.id,
'uom_po_id': cls.uom_unit.id,
'categ_id': cls.product_category.id,
'attribute_line_ids': [Command.create({
'attribute_id': cls.color_attribute.id,
@ -116,62 +139,21 @@ class ProductVariantsCommon(ProductAttributesCommon):
})]
})
cls.product_template_shirt = cls.env['product.template'].create({
'name': 'Shirt',
'categ_id': cls.product_category.id,
'attribute_line_ids': [
Command.create({
'attribute_id': cls.size_attribute.id,
'value_ids': [Command.set([cls.size_attribute_l.id])],
}),
],
})
class TestProductCommon(ProductVariantsCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Product environment related data
cls.uom_dunit = cls.env['uom.uom'].create({
'name': 'DeciUnit',
'category_id': cls.uom_unit.category_id.id,
'factor_inv': 0.1,
'factor': 10.0,
'uom_type': 'smaller',
'rounding': 0.001,
})
cls.product_1, cls.product_2 = cls.env['product.product'].create([{
'name': 'Courage', # product_1
'type': 'consu',
'default_code': 'PROD-1',
'uom_id': cls.uom_dunit.id,
'uom_po_id': cls.uom_dunit.id,
}, {
'name': 'Wood', # product_2
}])
# Kept for reduced diff in other modules (mainly stock & mrp)
cls.prod_att_1 = cls.color_attribute
cls.prod_attr1_v1 = cls.color_attribute_red
cls.prod_attr1_v2 = cls.color_attribute_blue
cls.prod_attr1_v3 = cls.color_attribute_green
cls.product_7_template = cls.product_template_sofa
cls.product_7_attr1_v1 = cls.product_7_template.attribute_line_ids[
0].product_template_value_ids[0]
cls.product_7_attr1_v2 = cls.product_7_template.attribute_line_ids[
0].product_template_value_ids[1]
cls.product_7_attr1_v3 = cls.product_7_template.attribute_line_ids[
0].product_template_value_ids[2]
cls.product_7_1 = cls.product_7_template._get_variant_for_combination(
cls.product_7_attr1_v1)
cls.product_7_2 = cls.product_7_template._get_variant_for_combination(
cls.product_7_attr1_v2)
cls.product_7_3 = cls.product_7_template._get_variant_for_combination(
cls.product_7_attr1_v3)
cls.product_sofa_red = cls.product_template_sofa.product_variant_ids.filtered(
lambda pp:
pp.product_template_attribute_value_ids.product_attribute_value_id
==
cls.color_attribute_red
)
cls.product_sofa_blue = cls.product_template_sofa.product_variant_ids.filtered(
lambda pp:
pp.product_template_attribute_value_ids.product_attribute_value_id
==
cls.color_attribute_blue
)
cls.product_sofa_green = cls.product_template_sofa.product_variant_ids.filtered(
lambda pp:
pp.product_template_attribute_value_ids.product_attribute_value_id
==
cls.color_attribute_green
)