2016-07-07 06:56:38 +02: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.
|
2013-10-16 13:46:10 +02:00
|
|
|
import datetime
|
|
|
|
import unittest
|
|
|
|
from dateutil.relativedelta import relativedelta
|
2016-07-07 06:56:38 +02:00
|
|
|
from decimal import Decimal
|
2013-10-16 13:46:10 +02:00
|
|
|
import trytond.tests.test_tryton
|
2016-07-07 06:56:38 +02:00
|
|
|
from trytond.pool import Pool
|
|
|
|
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
2013-10-16 13:46:10 +02:00
|
|
|
from trytond.transaction import Transaction
|
2016-07-07 06:56:38 +02:00
|
|
|
from trytond.modules.company.tests import create_company, set_company
|
2013-10-16 13:46:10 +02:00
|
|
|
|
|
|
|
|
2017-02-23 23:47:30 +01:00
|
|
|
class TestStockLotExpiryCase(ModuleTestCase):
|
|
|
|
'Test Stock Lot Expiry module'
|
2016-07-07 06:56:38 +02:00
|
|
|
module = 'stock_lot_expiry'
|
2013-10-16 13:46:10 +02:00
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
@with_transaction()
|
2013-10-16 13:46:10 +02:00
|
|
|
def test0010_lot_on_change_product_and_expired(self):
|
2014-11-05 13:21:17 +01:00
|
|
|
'Test Lot.on_change_product() and Lot.expired'
|
2016-07-07 06:56:38 +02:00
|
|
|
pool = Pool()
|
|
|
|
Lot = pool.get('stock.lot')
|
|
|
|
Product = pool.get('product.product')
|
|
|
|
Template = pool.get('product.template')
|
|
|
|
Uom = pool.get('product.uom')
|
|
|
|
transaction = Transaction()
|
|
|
|
|
|
|
|
unit, = Uom.search([('name', '=', 'Unit')])
|
|
|
|
template, = Template.create([{
|
|
|
|
'name': 'Test Lot.on_change_product() and Lot.expired',
|
|
|
|
'type': 'goods',
|
|
|
|
'consumable': True,
|
|
|
|
'list_price': Decimal(1),
|
|
|
|
'cost_price': Decimal(0),
|
|
|
|
'cost_price_method': 'fixed',
|
|
|
|
'default_uom': unit.id,
|
|
|
|
'life_time': 20,
|
|
|
|
'expiry_time': 10,
|
|
|
|
'alert_time': 5,
|
|
|
|
}])
|
|
|
|
product, = Product.create([{
|
|
|
|
'template': template.id,
|
|
|
|
}])
|
|
|
|
lot, lot2, = Lot.create([{
|
|
|
|
'number': '001',
|
|
|
|
'product': product.id,
|
|
|
|
}, {
|
|
|
|
'number': '002',
|
|
|
|
'product': product.id,
|
|
|
|
}])
|
|
|
|
lot.on_change_product()
|
|
|
|
lot.save()
|
|
|
|
|
|
|
|
today = datetime.date.today()
|
|
|
|
self.assertEqual(lot.life_date, (today + relativedelta(days=20)))
|
|
|
|
self.assertEqual(lot.expiry_date, (today + relativedelta(days=10)))
|
|
|
|
self.assertEqual(lot.removal_date, None)
|
|
|
|
self.assertEqual(lot.alert_date, (today + relativedelta(days=5)))
|
|
|
|
|
|
|
|
self.assertEqual(lot2.expiry_date, None)
|
|
|
|
|
|
|
|
with transaction.set_context(stock_move_date=today):
|
|
|
|
self.assertEqual(Lot(lot.id).expired, False)
|
|
|
|
self.assertEqual(Lot(lot2.id).expired, False)
|
|
|
|
with transaction.set_context(
|
|
|
|
stock_move_date=(today + relativedelta(days=10))):
|
|
|
|
self.assertEqual(Lot(lot.id).expired, True)
|
|
|
|
self.assertEqual(Lot(lot2.id).expired, False)
|
|
|
|
|
|
|
|
@with_transaction()
|
2013-10-16 13:46:10 +02:00
|
|
|
def test0020_move_check_allow_expired(self):
|
|
|
|
'''
|
|
|
|
Test Lot check_allow_expired.
|
|
|
|
'''
|
2016-07-07 06:56:38 +02:00
|
|
|
pool = Pool()
|
|
|
|
Location = pool.get('stock.location')
|
|
|
|
Lot = pool.get('stock.lot')
|
|
|
|
Move = pool.get('stock.move')
|
|
|
|
Product = pool.get('product.product')
|
|
|
|
Template = pool.get('product.template')
|
|
|
|
Uom = pool.get('product.uom')
|
|
|
|
|
|
|
|
company = create_company()
|
|
|
|
with set_company(company):
|
|
|
|
|
|
|
|
unit, = Uom.search([('name', '=', 'Unit')])
|
|
|
|
template, = Template.create([{
|
2013-10-16 13:46:10 +02:00
|
|
|
'name': 'Test Lot.on_change_product() and Lot.expired',
|
|
|
|
'type': 'goods',
|
|
|
|
'consumable': True,
|
|
|
|
'list_price': Decimal(1),
|
|
|
|
'cost_price': Decimal(0),
|
|
|
|
'cost_price_method': 'fixed',
|
|
|
|
'default_uom': unit.id,
|
|
|
|
'life_time': 20,
|
|
|
|
'expiry_time': 10,
|
|
|
|
'alert_time': 5,
|
|
|
|
}])
|
2016-07-07 06:56:38 +02:00
|
|
|
product, = Product.create([{
|
2013-10-28 13:58:39 +01:00
|
|
|
'template': template.id,
|
|
|
|
}])
|
2016-07-07 06:56:38 +02:00
|
|
|
lot, lot2, = Lot.create([{
|
2013-10-16 13:46:10 +02:00
|
|
|
'number': '001',
|
|
|
|
'product': product.id,
|
|
|
|
}, {
|
|
|
|
'number': '002',
|
|
|
|
'product': product.id,
|
|
|
|
}])
|
2016-07-07 06:56:38 +02:00
|
|
|
lot.on_change_product()
|
|
|
|
lot.save()
|
|
|
|
self.assertEqual(lot.expiry_date,
|
|
|
|
datetime.date.today() + datetime.timedelta(days=10))
|
2013-10-16 13:46:10 +02:00
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
lost_found, = Location.search([('type', '=', 'lost_found')])
|
2013-10-16 13:46:10 +02:00
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
storage, = Location.search([('code', '=', 'STO')])
|
2013-10-16 13:46:10 +02:00
|
|
|
storage.allow_expired = True
|
|
|
|
storage.save()
|
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
expired_loc, not_allowed_expired_loc = Location.create([{
|
2013-10-16 13:46:10 +02:00
|
|
|
'name': 'Expired Location',
|
|
|
|
'type': 'storage',
|
|
|
|
'expired': True,
|
|
|
|
'parent': storage.parent.id,
|
|
|
|
}, {
|
|
|
|
'name': 'Not Allowed Expired Location',
|
|
|
|
'type': 'storage',
|
|
|
|
'allow_expired': False,
|
|
|
|
'parent': storage.id,
|
|
|
|
}])
|
|
|
|
self.assertEqual(expired_loc.allow_expired, True)
|
|
|
|
|
|
|
|
today = datetime.date.today()
|
|
|
|
expired_date = today + relativedelta(days=10)
|
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
not_allowed_move, = Move.create([{
|
2013-10-16 13:46:10 +02:00
|
|
|
'product': product.id,
|
|
|
|
'lot': lot.id,
|
|
|
|
'uom': unit.id,
|
|
|
|
'quantity': 1,
|
|
|
|
'from_location': lost_found.id,
|
|
|
|
'to_location': not_allowed_expired_loc.id,
|
|
|
|
'planned_date': today,
|
|
|
|
'unit_price': Decimal('1'),
|
|
|
|
}])
|
|
|
|
not_allowed_move.effective_date = expired_date
|
|
|
|
not_allowed_move.save()
|
|
|
|
|
2016-07-07 06:56:38 +02:00
|
|
|
moves = Move.create([{
|
2013-10-16 13:46:10 +02:00
|
|
|
'product': product.id,
|
|
|
|
'lot': lot.id,
|
|
|
|
'uom': unit.id,
|
|
|
|
'quantity': 1,
|
|
|
|
'from_location': lost_found.id,
|
|
|
|
'to_location': not_allowed_expired_loc.id,
|
|
|
|
'planned_date': today,
|
|
|
|
'unit_price': Decimal('1'),
|
|
|
|
}, {
|
|
|
|
'product': product.id,
|
|
|
|
'lot': lot.id,
|
|
|
|
'uom': unit.id,
|
|
|
|
'quantity': 1,
|
|
|
|
'from_location': lost_found.id,
|
|
|
|
'to_location': storage.id,
|
|
|
|
'planned_date': expired_date,
|
|
|
|
'effective_date': expired_date,
|
|
|
|
'unit_price': Decimal('1'),
|
|
|
|
}, {
|
|
|
|
'product': product.id,
|
|
|
|
'lot': lot.id,
|
|
|
|
'uom': unit.id,
|
|
|
|
'quantity': 1,
|
|
|
|
'from_location': lost_found.id,
|
|
|
|
'to_location': expired_loc.id,
|
|
|
|
'planned_date': expired_date,
|
|
|
|
'effective_date': expired_date,
|
|
|
|
'unit_price': Decimal('1'),
|
|
|
|
}])
|
2016-07-07 06:56:38 +02:00
|
|
|
Move.do(moves)
|
2013-10-16 13:46:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def suite():
|
|
|
|
suite = trytond.tests.test_tryton.suite()
|
2017-02-23 23:47:30 +01:00
|
|
|
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
|
|
|
TestStockLotExpiryCase))
|
2013-10-16 13:46:10 +02:00
|
|
|
return suite
|