/usr/lib/python2.7/dist-packages/trytond/modules/stock_supply_day/tests/test_stock_supply_day.py is in tryton-modules-stock-supply-day 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import unittest
import doctest
import datetime
from decimal import Decimal
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, test_view,\
test_depends
from trytond.transaction import Transaction
class StockSupplyDayTestCase(unittest.TestCase):
'Test StockSupplyDay module'
def setUp(self):
trytond.tests.test_tryton.install_module('stock_supply_day')
self.uom = POOL.get('product.uom')
self.uom_category = POOL.get('product.uom.category')
self.category = POOL.get('product.category')
self.template = POOL.get('product.template')
self.product = POOL.get('product.product')
self.company = POOL.get('company.company')
self.party = POOL.get('party.party')
self.account = POOL.get('account.account')
self.product_supplier = POOL.get('purchase.product_supplier')
self.product_supplier_day = POOL.get('purchase.product_supplier.day')
self.user = POOL.get('res.user')
def test0005views(self):
'Test views'
test_view('stock_supply_day')
def test0006depends(self):
'Test depends'
test_depends()
def test0010compute_supply_date(self):
'Test compute_supply_date'
dates = [
# purchase date, delivery time, weekday, supply date
(datetime.date(2011, 11, 21), 10, 0, datetime.date(2011, 12, 5)),
(datetime.date(2011, 11, 21), 9, 1, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 21), 8, 2, datetime.date(2011, 11, 30)),
(datetime.date(2011, 11, 21), 7, 3, datetime.date(2011, 12, 1)),
(datetime.date(2011, 11, 21), 6, 4, datetime.date(2011, 12, 2)),
(datetime.date(2011, 11, 21), 5, 5, datetime.date(2011, 11, 26)),
(datetime.date(2011, 11, 21), 4, 6, datetime.date(2011, 11, 27)),
(datetime.date(2011, 12, 22), 12, 6, datetime.date(2012, 1, 8)),
(datetime.date(2011, 11, 21), 10, None,
datetime.date(2011, 12, 1)),
]
# Purchase date is Monday, 2011-11-21, the regular days to deliver
# is 10 days, which would be Wednesday 2011-12-01. But with the
# supplier weekday 0 (Monday) the forecast supply date is next
# Monday, the 2011-12-05.
for purchase_date, delivery_time, weekday, supply_date in dates:
with Transaction().start(DB_NAME, USER, context=CONTEXT):
product_supplier = self.create_product_supplier_day(
delivery_time, weekday)
date = product_supplier.compute_supply_date(purchase_date)
self.assertEqual(date, supply_date)
def test0020compute_purchase_date(self):
'Test compute_purchase_date'
dates = [
# purchase date, delivery time, weekday, supply date
(datetime.date(2011, 11, 25), 10, 0, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 27), 9, 1, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 22), 8, 2, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 24), 7, 3, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 26), 6, 4, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 28), 5, 5, datetime.date(2011, 12, 6)),
(datetime.date(2011, 11, 30), 4, 6, datetime.date(2011, 12, 6)),
(datetime.date(2011, 12, 27), 6, 0, datetime.date(2012, 1, 3)),
]
# Supply date max is Tuesday, 2012-01-03, the supplier weekday 0
# which would be Monday 2012-01-02. But with the 6 days of delivery
# the forecast purchase date is the 2011-12-27.
for purchase_date, delivery_time, weekday, supply_date in dates:
with Transaction().start(DB_NAME, USER, context=CONTEXT):
product_supplier = self.create_product_supplier_day(
delivery_time, weekday)
date = product_supplier.compute_purchase_date(supply_date)
self.assertEqual(date, purchase_date)
def create_product_supplier_day(self, delivery_time, weekday):
'''
Create a Product with a Product Supplier Day
:param delivery_time: minimal time in days needed to supply
:param weekday: supply day of the week (0 - 6)
:return: the id of the Product Supplier Day
'''
uom_category, = self.uom_category.create([{'name': 'Test'}])
uom, = self.uom.create([{
'name': 'Test',
'symbol': 'T',
'category': uom_category.id,
'rate': 1.0,
'factor': 1.0,
}])
category, = self.category.create([{'name': 'ProdCategoryTest'}])
template, = self.template.create([{
'name': 'ProductTest',
'default_uom': uom.id,
'category': category.id,
'account_category': True,
'list_price': Decimal(0),
'cost_price': Decimal(0),
}])
product, = self.product.create([{
'template': template.id,
}])
company, = self.company.search([
('rec_name', '=', 'Dunder Mifflin'),
])
self.user.write([self.user(USER)], {
'main_company': company.id,
'company': company.id,
})
receivable, = self.account.search([
('kind', '=', 'receivable'),
('company', '=', company.id),
])
payable, = self.account.search([
('kind', '=', 'payable'),
('company', '=', company.id),
])
supplier, = self.party.create([{
'name': 'supplier',
'account_receivable': receivable.id,
'account_payable': payable.id,
}])
product_supplier, = self.product_supplier.create([{
'product': template.id,
'company': company.id,
'party': supplier.id,
'delivery_time': delivery_time,
}])
if weekday is not None:
self.product_supplier_day.create([{
'product_supplier': product_supplier.id,
'weekday': str(weekday),
}])
return product_supplier
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)
from trytond.modules.account.tests import test_account
for test in test_account.suite():
if test not in suite and not isinstance(test, doctest.DocTestCase):
suite.addTest(test)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
StockSupplyDayTestCase))
return suite
|