1
0
Fork 0
mirror of synced 2023-12-14 09:32:52 +01:00

Add tests

This commit is contained in:
Sergi Almacellas Abellana 2015-11-18 13:31:45 +01:00
parent dbb64a3521
commit 7a5613c84b

View file

@ -1,9 +1,13 @@
#!/usr/bin/env python
# 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 POOL, DB_NAME, USER, CONTEXT
from trytond.tests.test_tryton import test_view, test_depends
from trytond.transaction import Transaction
from trytond.exceptions import UserError
class TestCase(unittest.TestCase):
@ -20,8 +24,108 @@ class TestCase(unittest.TestCase):
'Test depends'
test_depends()
def test_lot_sequence(self):
'Test lot sequence'
Company = POOL.get('company.company')
User = POOL.get('res.user')
Template = POOL.get('product.template')
Product = POOL.get('product.product')
Category = POOL.get('product.category')
Uom = POOL.get('product.uom')
Sequence = POOL.get('ir.sequence')
Config = POOL.get('stock.configuration')
Lot = POOL.get('stock.lot')
with Transaction().start(DB_NAME, USER, context=CONTEXT):
company, = Company.search([
('rec_name', '=', 'Dunder Mifflin'),
])
category = Category(name='Category')
category.save()
unit, = Uom.search([
('name', '=', 'Unit'),
])
template = Template(
name='Test Lot Sequence',
list_price=Decimal(10),
cost_price=Decimal(3),
default_uom=unit,
category=category,
)
template.save()
product = Product(template=template)
product.save()
with self.assertRaises(UserError):
lot, = Lot.create([{'product': product.id}])
sequence = Sequence(code='stock.lot', name='Config Sequence')
sequence.save()
cat_sequence = Sequence(code='stock.lot', name='Category Sequence')
cat_sequence.save()
tem_sequence = Sequence(code='stock.lot', name='Template Sequence')
tem_sequence.save()
with Transaction().set_context(company=company.id):
config = Config()
config.lot_sequence = sequence
config.save()
lots = Lot.create([
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
])
self.assertEqual([l.number for l in lots], [str(x) for x
in range(1, 6)])
# Set number manualy
lot = Lot(product=product, number='M1')
lot.save()
self.assertEqual(lot.number, 'M1')
lots = Lot.create([
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
])
self.assertEqual([l.number for l in lots], [str(x) for x
in range(6, 11)])
category.lot_sequence = cat_sequence
category.save()
# It should use the category sequence
lots = Lot.create([
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
{'product': product.id},
])
self.assertEqual([l.number for l in lots], [str(x) for x
in range(1, 6)])
template.lot_sequence = tem_sequence
template.save()
# It should use the template sequence
lots = Lot.create([
{'product': product.id},
{'product': product.id},
{'product': product.id},
])
self.assertEqual([l.number for l in lots], [str(x) for x
in range(1, 4)])
def suite():
suite = trytond.tests.test_tryton.suite()
from trytond.modules.company.tests import test_company
for test in test_company.suite():
if test not in suite:
suite.addTest(test)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
return suite