tasts: add test for transfer between cash/cash
This commit is contained in:
parent
b86e421298
commit
ce0b9ff946
1 changed files with 81 additions and 20 deletions
101
tests/planner.py
101
tests/planner.py
|
@ -65,6 +65,51 @@ class PlannerTestCase(object):
|
|||
' 09/01/2022')
|
||||
return job
|
||||
|
||||
def prep_planner_asset_book(self):
|
||||
""" prepare asset-cashbook
|
||||
"""
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
Book = pool.get('cashbook.book')
|
||||
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({'company': company.id}):
|
||||
type_depot = self.prep_type('Depot', 'D')
|
||||
|
||||
asset = self.prep_asset_item(
|
||||
company=company,
|
||||
product=self.prep_asset_product(name='Product 1'))
|
||||
self.assertEqual(asset.symbol, 'usd/u')
|
||||
self.assertEqual(company.currency.symbol, 'usd')
|
||||
|
||||
Asset.write(*[
|
||||
[asset],
|
||||
{
|
||||
'rates': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'rate': Decimal('10.0'),
|
||||
}, {
|
||||
'date': date(2022, 5, 2),
|
||||
'rate': Decimal('12.5'),
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(
|
||||
asset.rec_name, 'Product 1 | 12.5000 usd/u | 05/02/2022')
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Depot',
|
||||
'btype': type_depot.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
'asset': asset.id,
|
||||
'quantity_uom': asset.uom.id,
|
||||
}])
|
||||
self.prep_valstore_run_worker()
|
||||
self.assertEqual(book.rec_name, 'ww')
|
||||
return book
|
||||
|
||||
@with_transaction()
|
||||
def test_planner_create_job(self):
|
||||
""" create job, check rule + constraints
|
||||
|
@ -322,8 +367,7 @@ class PlannerTestCase(object):
|
|||
'bookingtype': 'out',
|
||||
'category': category.id,
|
||||
'subject': 'booking ${month}/${year}, ${date}',
|
||||
'wfcheck': True,
|
||||
}])
|
||||
'wfcheck': True}])
|
||||
self.assertEqual(job.rec_name, 'Booking to category')
|
||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
||||
self.assertEqual(len(job.cashbook.lines), 0)
|
||||
|
@ -359,11 +403,18 @@ class PlannerTestCase(object):
|
|||
Category = pool.get('cashbook.category')
|
||||
Cashbook = pool.get('cashbook.book')
|
||||
|
||||
job = self.prep_create_job()
|
||||
self.assertEqual(
|
||||
job._compute_dates_by_rrule(
|
||||
count=1, query_date=date(2022, 5, 1)), [
|
||||
date(2022, 5, 1)])
|
||||
company = self.prep_company()
|
||||
with Transaction().set_context({'company': company.id}):
|
||||
job = self.prep_create_job()
|
||||
target_book, = Cashbook.create([{
|
||||
'name': 'Book 2',
|
||||
'btype': job.cashbook.btype.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1)}])
|
||||
self.assertEqual(target_book.rec_name, 'Book 2 | 0.00 usd | Open')
|
||||
self.assertEqual(len(target_book.lines), 0)
|
||||
|
||||
IrDate.today = MagicMock(return_value=date(2022, 5, 24))
|
||||
|
||||
|
@ -371,15 +422,16 @@ class PlannerTestCase(object):
|
|||
Planner.write(*[
|
||||
[job],
|
||||
{
|
||||
'name': 'Booking to category',
|
||||
'name': 'Transfer to Book-2',
|
||||
'amount': Decimal('10.0'),
|
||||
'bookingtype': 'out',
|
||||
'bookingtype': 'mvout',
|
||||
'category': category.id,
|
||||
'subject': 'booking ${month}/${year}, ${date}',
|
||||
'wfcheck': True,
|
||||
}])
|
||||
self.assertEqual(job.rec_name, 'Booking to category')
|
||||
'booktransf': target_book.id,
|
||||
'wfcheck': True}])
|
||||
self.assertEqual(job.rec_name, 'Transfer to Book-2')
|
||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
||||
self.assertEqual(job.booktransf.rec_name, 'Book 2 | 0.00 usd | Open')
|
||||
self.assertEqual(len(job.cashbook.lines), 0)
|
||||
|
||||
job, = Planner.search([])
|
||||
|
@ -388,17 +440,26 @@ class PlannerTestCase(object):
|
|||
Planner.cronjob()
|
||||
self.assertEqual(job.nextrun[0].date, date(2022, 7, 1))
|
||||
|
||||
# check cashbook
|
||||
self.assertEqual(len(job.cashbook.lines), 1)
|
||||
self.assertEqual(
|
||||
job.cashbook.lines[0].rec_name,
|
||||
"06/01/2022|Exp|-10.00 usd|booking " +
|
||||
"${month}/${year}, ${date} [Cat1]")
|
||||
self.assertEqual(job.cashbook.lines[0].state, 'check')
|
||||
|
||||
# check both cashbooks
|
||||
with Transaction().set_context({'date': date(2022, 6, 1)}):
|
||||
cashbook, = Cashbook.browse([job.cashbook])
|
||||
self.assertEqual(cashbook.rec_name, 'Book 1 | -10.00 usd | Open')
|
||||
self.assertEqual(len(cashbook.lines), 1)
|
||||
self.assertEqual(
|
||||
cashbook.lines[0].rec_name,
|
||||
"06/01/2022|to|-10.00 usd|booking ${month}/${year}, " +
|
||||
"${date} [Book 2 | 10.00 usd | Open]")
|
||||
self.assertEqual(cashbook.lines[0].state, 'check')
|
||||
|
||||
target_book, = Cashbook.browse([job.booktransf])
|
||||
self.assertEqual(target_book.rec_name, 'Book 2 | 10.00 usd | Open')
|
||||
self.assertEqual(len(target_book.lines), 1)
|
||||
self.assertEqual(
|
||||
target_book.lines[0].rec_name,
|
||||
"06/01/2022|from|10.00 usd|booking ${month}/${year}, " +
|
||||
"${date} [Book 1 | -10.00 usd | Open]")
|
||||
self.assertEqual(target_book.lines[0].state, 'check')
|
||||
self.assertEqual(target_book.lines[0].state, 'check')
|
||||
|
||||
IrDate.today = MagicMock(return_value=date.today())
|
||||
|
||||
|
|
Loading…
Reference in a new issue