2024-02-24 14:36:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# This file is part of the cashbook-planner from m-ds for Tryton.
|
|
|
|
# The COPYRIGHT file at the top level of this repository contains the
|
|
|
|
# full copyright notices and license terms.
|
|
|
|
|
|
|
|
from trytond.tests.test_tryton import with_transaction
|
|
|
|
from trytond.pool import Pool
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
from trytond.exceptions import UserError
|
2024-02-25 22:10:40 +00:00
|
|
|
|
2024-02-24 14:36:15 +00:00
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
|
|
|
|
class PlannerTestCase(object):
|
|
|
|
""" test planner
|
|
|
|
"""
|
2024-02-25 22:10:40 +00:00
|
|
|
def prep_create_job(self, name='Job 1'):
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
Planner = pool.get('cashbook.planner')
|
|
|
|
|
|
|
|
types = self.prep_type()
|
|
|
|
company = self.prep_company()
|
|
|
|
job = None
|
|
|
|
with Transaction().set_context({
|
|
|
|
'company': company.id,
|
|
|
|
'start_date': date(2022, 5, 1)}):
|
|
|
|
book, = Book.create([{
|
|
|
|
'name': 'Book 1',
|
|
|
|
'btype': types.id,
|
|
|
|
'company': company.id,
|
|
|
|
'currency': company.currency.id,
|
|
|
|
'number_sequ': self.prep_sequence().id,
|
|
|
|
'start_date': date(2022, 5, 1),
|
|
|
|
}])
|
|
|
|
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
|
|
|
|
|
|
|
|
job, = Planner.create([{
|
|
|
|
'cashbook': book.id,
|
|
|
|
'name': name,
|
|
|
|
'start_date': date(2022, 5, 1)}])
|
|
|
|
# check applied defaults
|
|
|
|
self.assertEqual(job.rec_name, 'Job 1')
|
|
|
|
self.assertEqual(job.start_date, date(2022, 5, 1))
|
|
|
|
self.assertEqual(job.end_date, None)
|
|
|
|
self.assertEqual(job.frequ, 'month')
|
|
|
|
self.assertEqual(job.weekday, '99')
|
|
|
|
self.assertEqual(job.monthday, 1)
|
|
|
|
self.assertEqual(job.interval, 1)
|
|
|
|
self.assertEqual(job.setpos, None)
|
|
|
|
self.assertEqual(
|
|
|
|
job.nextdates,
|
|
|
|
'05/01/2022 | 06/01/2022 | 07/01/2022 | 08/01/2022 |' +
|
|
|
|
' 09/01/2022')
|
|
|
|
return job
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_planner_create_job(self):
|
|
|
|
""" create job, check rule
|
|
|
|
"""
|
|
|
|
Planner = Pool().get('cashbook.planner')
|
|
|
|
|
|
|
|
job = self.prep_create_job()
|
|
|
|
self.assertEqual(
|
|
|
|
job._compute_dates_by_rrule(
|
|
|
|
start_date=date(2022, 5, 1), count=5), [
|
|
|
|
date(2022, 5, 1), date(2022, 6, 1),
|
|
|
|
date(2022, 7, 1), date(2022, 8, 1),
|
|
|
|
date(2022, 9, 1)])
|
|
|
|
|
|
|
|
self.assertRaisesRegex(
|
|
|
|
UserError,
|
|
|
|
r'The value "2022-05-01" for field "End Date" in "Job 1" of ' +
|
|
|
|
r'"Scheduled Booking" is not valid according to its domain\.',
|
|
|
|
Planner.write,
|
|
|
|
*[[job], {'end_date': date(2022, 5, 1)}])
|
|
|
|
|
|
|
|
Planner.write(*[[job], {
|
|
|
|
'end_date': date(2022, 9, 15), 'monthday': 3}])
|
|
|
|
self.assertEqual(
|
|
|
|
job._compute_dates_by_rrule(start_date=date(2022, 5, 1)), [
|
|
|
|
date(2022, 5, 3), date(2022, 6, 3),
|
|
|
|
date(2022, 7, 3), date(2022, 8, 3),
|
|
|
|
date(2022, 9, 3)])
|
|
|
|
|
|
|
|
Planner.write(*[[job], {
|
|
|
|
'end_date': date(2022, 9, 15), 'monthday': 3, 'interval': 2}])
|
|
|
|
self.assertEqual(
|
|
|
|
job._compute_dates_by_rrule(start_date=date(2022, 5, 1)), [
|
|
|
|
date(2022, 5, 3), date(2022, 7, 3),
|
|
|
|
date(2022, 9, 3)])
|
|
|
|
|
|
|
|
# 3rd of each 2nd month
|
|
|
|
Planner.write(*[[job], {
|
|
|
|
'end_date': None, 'monthday': 1, 'interval': 1}])
|
|
|
|
self.assertEqual(
|
|
|
|
job._compute_dates_by_rrule(
|
|
|
|
start_date=date(2022, 5, 1),
|
|
|
|
params={
|
|
|
|
'end_date': date(2022, 9, 15), 'monthday': 3,
|
|
|
|
'interval': 2}),
|
|
|
|
[date(2022, 5, 3), date(2022, 7, 3), date(2022, 9, 3)])
|
|
|
|
|
|
|
|
# 1st wednesday of each 2nd month
|
|
|
|
self.assertEqual(
|
|
|
|
job._compute_dates_by_rrule(
|
|
|
|
start_date=date(2022, 5, 1),
|
|
|
|
params={
|
|
|
|
'end_date': date(2022, 9, 15), 'weekday': '2',
|
|
|
|
'interval': 2, 'setpos': 1}),
|
|
|
|
[date(2022, 5, 4), date(2022, 7, 6), date(2022, 9, 7)])
|
2024-02-24 14:36:15 +00:00
|
|
|
|
|
|
|
# end PlannerTestCase
|