19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:27 +01:00
parent d1963a3c3a
commit 2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions

View file

@ -1,27 +1,29 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import TransactionCase
from odoo.addons.base.tests.common import BaseCommon
class UomCommon(TransactionCase):
class UomCommon(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.uom_gram = cls.env.ref('uom.product_uom_gram')
cls.uom_kgm = cls.env.ref('uom.product_uom_kgm')
cls.uom_ton = cls.env.ref('uom.product_uom_ton')
cls.uom_unit = cls.env.ref('uom.product_uom_unit')
cls.uom_dozen = cls.env.ref('uom.product_uom_dozen')
cls.uom_gram = cls.quick_ref('uom.product_uom_gram')
cls.uom_kgm = cls.quick_ref('uom.product_uom_kgm')
cls.uom_ton = cls.quick_ref('uom.product_uom_ton')
cls.uom_unit = cls.quick_ref('uom.product_uom_unit')
cls.uom_dozen = cls.quick_ref('uom.product_uom_dozen')
cls.uom_dozen.active = True
cls.uom_hour = cls.quick_ref('uom.product_uom_hour')
cls.group_uom = cls.env.ref('uom.group_uom')
cls.group_uom = cls.quick_ref('uom.group_uom')
@classmethod
def _enable_uom(cls):
cls.env.user.groups_id += cls.group_uom
cls.env.user.group_ids += cls.group_uom
@classmethod
def _disable_uom(cls):
cls.env.user.groups_id -= cls.group_uom
cls.env.user.group_ids -= cls.group_uom

View file

@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.exceptions import ValidationError
from odoo.addons.uom.tests.common import UomCommon
@ -25,85 +23,28 @@ class TestUom(UomCommon):
# Regression test for side-effect of commit 311c77bb - converting 1234 Grams
# into Kilograms should work even if grams are rounded to 1.
self.uom_gram.write({'rounding': 1})
qty = self.uom_gram._compute_quantity(1234, self.uom_kgm)
self.assertEqual(qty, 1.24, "Converted quantity does not correspond.")
def test_20_rounding(self):
product_uom = self.env['uom.uom'].create({
'name': 'Score',
'factor_inv': 20,
'uom_type': 'bigger',
'rounding': 1.0,
'category_id': self.env.ref('uom.product_uom_categ_unit').id
'relative_factor': 20,
'relative_uom_id': self.uom_unit.id,
})
self.env['decimal.precision'].search([('name', '=', 'Product Unit')]).digits = 0
qty = self.uom_unit._compute_quantity(2, product_uom)
self.assertEqual(qty, 1, "Converted quantity should be rounded up.")
def test_30_reference_uniqueness(self):
""" Check the uniqueness of the reference UoM in a category """
time_category = self.env.ref('uom.product_uom_categ_unit')
def test_30_quantity(self):
""" _check_qty rounds the available quantity of a product. To prevent rounding issue,
there should be no rounding if the product uom is the same as the package uom.
"""
uom = self.uom_unit
quantity = 22.43
rounding_method = 'DOWN'
with self.assertRaises(ValidationError):
self.env['uom.uom'].create({
'name': 'Second Time Reference',
'factor_inv': 1,
'uom_type': 'reference',
'rounding': 1.0,
'category_id': time_category.id,
'active': False,
})
result = self.uom_unit._check_qty(quantity, uom, rounding_method)
def test_40_custom_uom(self):
""" A custom UoM is an UoM in a category without measurement type. It should behave like a normal UoM """
category = self.env['uom.category'].create({
'name': 'Custom UoM category',
})
# at first we can not create a non reference in custom category
with self.assertRaises(ValidationError):
self.env['uom.uom'].create({
'name': 'Bigger UoM of my category',
'factor_inv': 42,
'uom_type': 'bigger',
'rounding': 0.5,
'category_id': category.id
})
# create the reference
self.env['uom.uom'].create({
'name': 'Reference UoM of my category',
'factor_inv': 1,
'uom_type': 'reference',
'rounding': 1.0,
'category_id': category.id
})
# we can create another UoM now
self.env['uom.uom'].create({
'name': 'Bigger UoM of my category',
'factor_inv': 42,
'uom_type': 'bigger',
'rounding': 0.5,
'category_id': category.id
})
# we can not create a second reference in custom category
with self.assertRaises(ValidationError):
self.env['uom.uom'].create({
'name': 'Second Time Reference',
'factor_inv': 1,
'uom_type': 'reference',
'rounding': 1.0,
'category_id': category.id
})
def test_50_check_ratio(self):
with self.assertRaises(ValidationError):
self.env['uom.uom'].create({
'name': 'Custom UoM',
'uom_type': 'bigger',
'ratio': 0,
'category_id': self.env.ref('uom.product_uom_categ_unit').id
})
self.assertEqual(result, quantity, 'Quantity should not be rounded.')