Files
tryton/modules/stock_supply/tests/test_module.py
T

160 lines
6.1 KiB
Python
Raw Normal View History

2014-12-02 12:56:15 +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.
2016-02-06 19:13:26 +01:00
import datetime
2016-02-06 19:13:26 +01:00
from trytond.modules.account.tests import create_chart
2021-12-11 17:58:44 +01:00
from trytond.modules.company.tests import (
CompanyTestMixin, create_company, set_company)
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
2011-11-29 16:35:44 +01:00
DATES = [
2016-02-02 21:17:22 +01:00
# purchase date, lead time, supply date
(datetime.date(2011, 11, 21), datetime.timedelta(10),
datetime.date(2011, 12, 1)),
(datetime.date(2011, 11, 21), datetime.timedelta(9),
datetime.date(2011, 11, 30)),
(datetime.date(2011, 11, 21), datetime.timedelta(8),
datetime.date(2011, 11, 29)),
(datetime.date(2011, 11, 21), datetime.timedelta(7),
datetime.date(2011, 11, 28)),
(datetime.date(2011, 11, 21), datetime.timedelta(6),
datetime.date(2011, 11, 27)),
(datetime.date(2011, 11, 21), datetime.timedelta(5),
datetime.date(2011, 11, 26)),
(datetime.date(2011, 11, 21), datetime.timedelta(4),
datetime.date(2011, 11, 25)),
2011-11-29 16:35:44 +01:00
]
2009-06-29 09:18:36 +02:00
class StockSupplyTestCase(CompanyTestMixin, ModuleTestCase):
2014-01-12 20:00:20 +01:00
'Test StockSupply module'
2015-01-27 18:14:18 +01:00
module = 'stock_supply'
2009-06-29 09:18:36 +02:00
2016-02-06 19:13:26 +01:00
def test_compute_supply_date(self):
2014-01-12 20:00:20 +01:00
'Test compute_supply_date'
2016-02-06 19:13:26 +01:00
@with_transaction()
def run(purchase_date, lead_time, supply_date):
pool = Pool()
ProductSupplier = pool.get('purchase.product_supplier')
product_supplier = self.create_product_supplier(lead_time)
date = ProductSupplier.compute_supply_date(
product_supplier, purchase_date)
self.assertEqual(date, supply_date)
2016-02-02 21:17:22 +01:00
for purchase_date, lead_time, supply_date in DATES:
2016-02-06 19:13:26 +01:00
run(purchase_date, lead_time, supply_date)
2011-11-29 16:35:44 +01:00
2016-02-06 19:13:26 +01:00
def test_compute_purchase_date(self):
2014-01-12 20:00:20 +01:00
'Test compute_purchase_date'
2016-02-06 19:13:26 +01:00
@with_transaction()
def run(purchase_date, lead_time, supply_date):
pool = Pool()
ProductSupplier = pool.get('purchase.product_supplier')
product_supplier = self.create_product_supplier(lead_time)
date = ProductSupplier.compute_purchase_date(
product_supplier, supply_date)
self.assertEqual(date, purchase_date)
2016-02-02 21:17:22 +01:00
for purchase_date, lead_time, supply_date in DATES:
2016-02-06 19:13:26 +01:00
run(purchase_date, lead_time, supply_date)
2011-11-29 16:35:44 +01:00
2016-02-02 21:17:22 +01:00
def create_product_supplier(self, lead_time):
2011-11-29 16:35:44 +01:00
'''
Create a Product with a Product Supplier
2016-02-02 21:17:22 +01:00
:param lead_time: timedelta needed to supply
2011-11-29 16:35:44 +01:00
:return: the id of the Product Supplier
'''
2016-02-06 19:13:26 +01:00
pool = Pool()
Uom = pool.get('product.uom')
UomCategory = pool.get('product.uom.category')
Template = pool.get('product.template')
Product = pool.get('product.product')
Party = pool.get('party.party')
Account = pool.get('account.account')
ProductSupplier = pool.get('purchase.product_supplier')
uom_category, = UomCategory.create([{'name': 'Test'}])
uom, = Uom.create([{
2013-01-06 22:18:14 +01:00
'name': 'Test',
'symbol': 'T',
'category': uom_category.id,
'rate': 1.0,
'factor': 1.0,
}])
2016-02-06 19:13:26 +01:00
template, = Template.create([{
2013-01-06 22:18:14 +01:00
'name': 'ProductTest',
'default_uom': uom.id,
}])
2016-02-06 19:13:26 +01:00
product, = Product.create([{
2013-03-20 22:51:19 +01:00
'template': template.id,
}])
2016-02-06 19:13:26 +01:00
company = create_company()
with set_company(company):
create_chart(company)
receivable, = Account.search([
2019-03-24 18:00:01 +01:00
('type.receivable', '=', True),
2016-02-06 19:13:26 +01:00
('company', '=', company.id),
2014-01-16 22:10:59 +01:00
])
2016-02-06 19:13:26 +01:00
payable, = Account.search([
2019-03-24 18:00:01 +01:00
('type.payable', '=', True),
2016-02-06 19:13:26 +01:00
('company', '=', company.id),
])
supplier, = Party.create([{
'name': 'supplier',
'account_receivable': receivable.id,
'account_payable': payable.id,
}])
product_supplier, = ProductSupplier.create([{
'template': template.id,
2016-02-06 19:13:26 +01:00
'company': company.id,
'party': supplier.id,
'lead_time': lead_time,
}])
return product_supplier
2011-11-29 16:35:44 +01:00
@with_transaction()
def test_order_point_location_searcher(self):
pool = Pool()
Uom = pool.get('product.uom')
Template = pool.get('product.template')
Product = pool.get('product.product')
Location = pool.get('stock.location')
OrderPoint = pool.get('stock.order_point')
unit, = Uom.search([('symbol', '=', 'u')])
template, = Template.create([{
'name': 'ProductTest',
'type': 'goods',
'default_uom': unit.id,
'purchase_uom': unit.id,
'purchasable': True,
}])
product, = Product.create([{
'template': template.id,
}])
warehouse, = Location.search([('type', '=', 'warehouse')])
storage, = Location.search([('code', '=', 'STO')])
company = create_company()
with set_company(company):
order_point, = OrderPoint.create([{
'product': product.id,
'type': 'purchase',
'warehouse_location': warehouse.id,
'min_quantity': 0.0,
'target_quantity': 5.0,
}])
for clause, result in [
(('location', '=', warehouse.name), [order_point]),
(('location', '=', 'storage'), []),
(('location', '!=', warehouse.name), []),
(('location', '!=', 'storage'), [order_point]),
]:
self.assertListEqual(
OrderPoint.search(clause), result, msg=clause)
2011-11-29 16:35:44 +01:00
del ModuleTestCase