Files
tryton/modules/stock_split/tests/test_stock_split.py
T

105 lines
3.8 KiB
Python
Raw Normal View History

2014-12-02 12:56:13 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2017-09-07 18:42:26 +02:00
import doctest
2012-05-13 23:16:11 +02:00
import unittest
from decimal import Decimal
2012-05-13 23:16:11 +02:00
import trytond.tests.test_tryton
2016-02-06 19:13:25 +01:00
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
2017-09-07 18:42:26 +02:00
from trytond.tests.test_tryton import doctest_teardown
from trytond.tests.test_tryton import doctest_checker
2016-02-06 19:13:25 +01:00
from trytond.pool import Pool
from trytond.modules.company.tests import (
create_company, set_company, CompanyTestMixin)
2012-05-13 23:16:11 +02:00
class StockSplitTestCase(CompanyTestMixin, ModuleTestCase):
2014-01-12 20:00:19 +01:00
'Test Stock Lot module'
2015-01-27 18:14:17 +01:00
module = 'stock_split'
2012-05-13 23:16:11 +02:00
2016-02-06 19:13:25 +01:00
@with_transaction()
def test_split(self):
2014-01-12 20:00:19 +01:00
'Test split'
2016-02-06 19:13:25 +01:00
pool = Pool()
Uom = pool.get('product.uom')
Template = pool.get('product.template')
Product = pool.get('product.product')
Location = pool.get('stock.location')
Move = pool.get('stock.move')
unit, = Uom.search([('name', '=', 'Unit')])
template, = Template.create([{
'name': 'Test Split',
'type': 'goods',
'default_uom': unit.id,
'list_price': Decimal(0),
}])
product, = Product.create([{
'template': template.id,
}])
input_, = Location.search([('code', '=', 'IN')])
storage, = Location.search([('code', '=', 'STO')])
company = create_company()
with set_company(company):
2012-05-13 23:16:11 +02:00
def create_move(quantity):
2016-02-06 19:13:25 +01:00
move, = Move.create([{
2013-03-13 17:36:30 +01:00
'product': product.id,
'uom': unit.id,
'quantity': quantity,
'from_location': input_.id,
'to_location': storage.id,
'company': company.id,
}])
2012-09-24 22:18:23 +02:00
return move
2012-05-13 23:16:11 +02:00
move = create_move(10)
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit)
self.assertEqual(len(moves), 2)
self.assertEqual([m.quantity for m in moves], [5, 5])
2012-05-13 23:16:11 +02:00
move = create_move(13)
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit)
self.assertEqual(len(moves), 3)
self.assertEqual([m.quantity for m in moves], [5, 5, 3])
2012-05-13 23:16:11 +02:00
move = create_move(7)
2012-09-24 22:18:23 +02:00
moves = move.split(8, unit)
self.assertEqual(moves, [move])
2012-05-13 23:16:11 +02:00
self.assertEqual(move.quantity, 7)
move = create_move(20)
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit, count=2)
self.assertEqual(len(moves), 3)
self.assertEqual([m.quantity for m in moves], [5, 5, 10])
2012-05-13 23:16:11 +02:00
move = create_move(20)
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit, count=4)
self.assertEqual(len(moves), 4)
self.assertEqual([m.quantity for m in moves], [5, 5, 5, 5])
2012-05-13 23:16:11 +02:00
move = create_move(10)
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit, count=3)
self.assertEqual(len(moves), 2)
self.assertEqual([m.quantity for m in moves], [5, 5])
2012-05-13 23:16:11 +02:00
move = create_move(10)
2016-02-06 19:13:25 +01:00
Move.write([move], {
2012-05-13 23:16:11 +02:00
'state': 'assigned',
})
2012-09-24 22:18:23 +02:00
moves = move.split(5, unit)
self.assertEqual(len(moves), 2)
self.assertEqual([m.quantity for m in moves], [5, 5])
self.assertEqual([m.state for m in moves],
2012-05-13 23:16:11 +02:00
['assigned', 'assigned'])
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
StockSplitTestCase))
2017-09-07 18:42:26 +02:00
suite.addTests(doctest.DocFileSuite('scenario_stock_split_shipment.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
2012-05-13 23:16:11 +02:00
return suite