Add unit tests
issue5542 review27271002
This commit is contained in:
@@ -1,14 +1,83 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
import unittest
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
|
||||
|
||||
class ProductPriceListTestCase(ModuleTestCase):
|
||||
'Test ProductPriceList module'
|
||||
module = 'product_price_list'
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list(self):
|
||||
'Test price_list'
|
||||
pool = Pool()
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Party = pool.get('party.party')
|
||||
Uom = pool.get('product.uom')
|
||||
PriceList = pool.get('product.price_list')
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
party = Party(name='Customer')
|
||||
party.save()
|
||||
|
||||
kilogram, = Uom.search([
|
||||
('name', '=', 'Kilogram'),
|
||||
])
|
||||
gram, = Uom.search([
|
||||
('name', '=', 'Gram'),
|
||||
])
|
||||
|
||||
template = Template(
|
||||
name='Test Lot Sequence',
|
||||
list_price=Decimal(10),
|
||||
cost_price=Decimal(5),
|
||||
default_uom=kilogram,
|
||||
)
|
||||
template.save()
|
||||
product = Product(template=template)
|
||||
product.save()
|
||||
variant = Product(template=template)
|
||||
variant.save()
|
||||
|
||||
price_list, = PriceList.create([{
|
||||
'name': 'Default Price List',
|
||||
'lines': [('create', [{
|
||||
'quantity': 10.0,
|
||||
'product': variant.id,
|
||||
'formula': 'unit_price * 0.8',
|
||||
}, {
|
||||
'quantity': 10.0,
|
||||
'formula': 'unit_price * 0.9',
|
||||
}, {
|
||||
'product': variant.id,
|
||||
'formula': 'unit_price * 1.1',
|
||||
}, {
|
||||
'formula': 'unit_price',
|
||||
}])],
|
||||
}])
|
||||
tests = [
|
||||
(product, 1.0, kilogram, Decimal(10.0)),
|
||||
(product, 1000.0, gram, Decimal(10.0)),
|
||||
(variant, 1.0, kilogram, Decimal(11.0)),
|
||||
(product, 10.0, kilogram, Decimal(9.0)),
|
||||
(product, 10000.0, gram, Decimal(9.0)),
|
||||
(variant, 10.0, kilogram, Decimal(8.0)),
|
||||
(variant, 10000.0, gram, Decimal(8.0)),
|
||||
]
|
||||
for product, quantity, unit, result in tests:
|
||||
self.assertEqual(
|
||||
price_list.compute(party, product, product.list_price,
|
||||
quantity, unit),
|
||||
result)
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
|
||||
Reference in New Issue
Block a user