mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-22 03:52:07 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -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.')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue