[IMP] product: add python tests
bzr revid: mat@openerp.com-20140306133456-cnqjcwmo73ioqxxf
This commit is contained in:
parent
5db649549c
commit
378dbbfaae
|
@ -61,7 +61,6 @@ Print product labels with barcode.
|
|||
],
|
||||
'test': [
|
||||
'product_pricelist_demo.yml',
|
||||
'test/product_uom.yml',
|
||||
'test/product_pricelist.yml',
|
||||
],
|
||||
'installable': True,
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
-
|
||||
In order to test conversation of UOM,
|
||||
-
|
||||
I convert Grams into TON with price.
|
||||
-
|
||||
!python {model: product.uom}: |
|
||||
from_uom_id = ref("product_uom_gram")
|
||||
to_uom_id = ref("product_uom_ton")
|
||||
price = 2
|
||||
qty = 1020000
|
||||
price = self._compute_price(cr, uid, from_uom_id, price, to_uom_id)
|
||||
qty = self._compute_qty(cr, uid, from_uom_id, qty, to_uom_id)
|
||||
assert qty == 1.02, "Qty is not correspond."
|
||||
assert price == 2000000.0, "Price is not correspond."
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
from . import test_uom
|
||||
|
||||
fast_suite = [
|
||||
test_uom,
|
||||
]
|
|
@ -0,0 +1,37 @@
|
|||
from openerp.tests.common import TransactionCase
|
||||
|
||||
class TestUom(TransactionCase):
|
||||
"""Tests for unit of measure conversion"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestUom, self).setUp()
|
||||
self.product = self.registry('product.product')
|
||||
self.uom = self.registry('product.uom')
|
||||
self.imd = self.registry('ir.model.data')
|
||||
|
||||
def test_10_conversion(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
gram_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_gram')[1]
|
||||
tonne_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_ton')[1]
|
||||
|
||||
qty = self.uom._compute_qty(cr, uid, gram_id, 1020000, tonne_id)
|
||||
self.assertEquals(qty, 1.02, "Converted quantity does not correspond.")
|
||||
|
||||
price = self.uom._compute_price(cr, uid, gram_id, 2, tonne_id)
|
||||
self.assertEquals(price, 2000000.0, "Converted price does not correspond.")
|
||||
|
||||
def test_20_rounding(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
unit_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_unit')[1]
|
||||
categ_unit_id = self.imd.get_object_reference(cr, uid, 'product', 'product_uom_categ_unit')[1]
|
||||
|
||||
score_id = self.uom.create(cr, uid, {
|
||||
'name': 'Score',
|
||||
'factor_inv': 20,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 1.0,
|
||||
'category_id': categ_unit_id
|
||||
})
|
||||
|
||||
qty = self.uom._compute_qty(cr, uid, unit_id, 2, score_id)
|
||||
self.assertEquals(qty, 1, "Converted quantity should be rounded up.")
|
Loading…
Reference in New Issue