planner: add formatted rec_name
This commit is contained in:
parent
2e8f81bd99
commit
42aeefaa19
2 changed files with 53 additions and 14 deletions
22
planner.py
22
planner.py
|
@ -11,6 +11,7 @@ from trytond.model import ModelSQL, ModelView, fields, Index, DeactivableMixin
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.report import Report
|
from trytond.report import Report
|
||||||
|
from trytond.i18n import gettext
|
||||||
from trytond.pyson import Eval, Bool, If, And
|
from trytond.pyson import Eval, Bool, If, And
|
||||||
from trytond.modules.currency.fields import Monetary
|
from trytond.modules.currency.fields import Monetary
|
||||||
from trytond.modules.cashbook.book import sel_state_book
|
from trytond.modules.cashbook.book import sel_state_book
|
||||||
|
@ -164,6 +165,27 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
||||||
where=t.end_date != DEF_NONE),
|
where=t.end_date != DEF_NONE),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def get_rec_name(self, name=None):
|
||||||
|
""" get formatted name of record
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str, optional): name of field. Defaults to None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: formatted description of record
|
||||||
|
"""
|
||||||
|
return '|'.join([
|
||||||
|
self.name,
|
||||||
|
self.cashbook.name,
|
||||||
|
gettext('cashbook.msg_line_bookingtype_%s' % self.bookingtype),
|
||||||
|
self.booktransf.name
|
||||||
|
if self.booktransf
|
||||||
|
else self.category.rec_name if self.category else '-',
|
||||||
|
self.nextrun_link.rec_name if self.nextrun_link else '-',
|
||||||
|
Report.format_currency(
|
||||||
|
self.amount, lang=None, currency=self.cashbook.currency)
|
||||||
|
])
|
||||||
|
|
||||||
def _compute_dates_by_rrule(self, query_date=None, count=5, params={}):
|
def _compute_dates_by_rrule(self, query_date=None, count=5, params={}):
|
||||||
""" run rrule with values from record or from 'params'
|
""" run rrule with values from record or from 'params'
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ class PlannerTestCase(object):
|
||||||
'party': party.id,
|
'party': party.id,
|
||||||
'subject': 'Booking text'}])
|
'subject': 'Booking text'}])
|
||||||
# check applied defaults
|
# check applied defaults
|
||||||
self.assertEqual(job.rec_name, 'Job 1')
|
|
||||||
self.assertEqual(job.start_date, date(2022, 5, 1))
|
self.assertEqual(job.start_date, date(2022, 5, 1))
|
||||||
self.assertEqual(job.end_date, None)
|
self.assertEqual(job.end_date, None)
|
||||||
self.assertEqual(job.frequ, 'month')
|
self.assertEqual(job.frequ, 'month')
|
||||||
|
@ -132,7 +131,8 @@ class PlannerTestCase(object):
|
||||||
|
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
r'The value "2022-05-01" for field "End Date" in "Job 1" of ' +
|
r'The value "2022-05-01" for field "End Date" in ' +
|
||||||
|
r'"Job 1|Book 1|Exp|Cat1|05/01/2022|usd0.00" of ' +
|
||||||
r'"Scheduled Booking" is not valid according to its domain\.',
|
r'"Scheduled Booking" is not valid according to its domain\.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {'end_date': date(2022, 5, 1)}])
|
*[[job], {'end_date': date(2022, 5, 1)}])
|
||||||
|
@ -199,7 +199,8 @@ class PlannerTestCase(object):
|
||||||
# invalid end_date
|
# invalid end_date
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "2022-04-30" for field "End Date" in "Job 1" of ' +
|
'The value "2022-04-30" for field "End Date" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -209,7 +210,8 @@ class PlannerTestCase(object):
|
||||||
# monthday and weekday used together
|
# monthday and weekday used together
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "2" for field "Day of month" in "Job 1" of ' +
|
'The value "2" for field "Day of month" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -219,7 +221,8 @@ class PlannerTestCase(object):
|
||||||
# monthday out of range 1
|
# monthday out of range 1
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "0" for field "Day of month" in "Job 1" of ' +
|
'The value "0" for field "Day of month" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -229,7 +232,8 @@ class PlannerTestCase(object):
|
||||||
# monthday out of range 2
|
# monthday out of range 2
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "32" for field "Day of month" in "Job 1" of ' +
|
'The value "32" for field "Day of month" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -239,7 +243,8 @@ class PlannerTestCase(object):
|
||||||
# invalid usage of setpos
|
# invalid usage of setpos
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "1" for field "Occurrence" in "Job 1" of ' +
|
'The value "1" for field "Occurrence" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -250,7 +255,8 @@ class PlannerTestCase(object):
|
||||||
# setpos out of range 1
|
# setpos out of range 1
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "0" for field "Occurrence" in "Job 1" of ' +
|
'The value "0" for field "Occurrence" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -261,7 +267,8 @@ class PlannerTestCase(object):
|
||||||
# setpos out of range 2
|
# setpos out of range 2
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
UserError,
|
UserError,
|
||||||
'The value "5" for field "Occurrence" in "Job 1" of ' +
|
'The value "5" for field "Occurrence" in ' +
|
||||||
|
'"Job 1|Book 1|Exp|Cat1|05/01/2024|usd0.00" of ' +
|
||||||
'"Scheduled Booking" is not valid according to its domain.',
|
'"Scheduled Booking" is not valid according to its domain.',
|
||||||
Planner.write,
|
Planner.write,
|
||||||
*[[job], {
|
*[[job], {
|
||||||
|
@ -374,7 +381,9 @@ class PlannerTestCase(object):
|
||||||
'category': category.id,
|
'category': category.id,
|
||||||
'subject': 'booking ${month}/${year}, ${date}',
|
'subject': 'booking ${month}/${year}, ${date}',
|
||||||
'wfcheck': True}])
|
'wfcheck': True}])
|
||||||
self.assertEqual(job.rec_name, 'Booking to category')
|
self.assertEqual(
|
||||||
|
job.rec_name,
|
||||||
|
'Booking to category|Book 1|Exp|Cat1|06/01/2022|usd10.00')
|
||||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
||||||
self.assertEqual(len(job.cashbook.lines), 0)
|
self.assertEqual(len(job.cashbook.lines), 0)
|
||||||
|
|
||||||
|
@ -435,7 +444,9 @@ class PlannerTestCase(object):
|
||||||
'subject': 'booking ${month}/${year}, ${date}',
|
'subject': 'booking ${month}/${year}, ${date}',
|
||||||
'booktransf': target_book.id,
|
'booktransf': target_book.id,
|
||||||
'wfcheck': True}])
|
'wfcheck': True}])
|
||||||
self.assertEqual(job.rec_name, 'Transfer to Book-2')
|
self.assertEqual(
|
||||||
|
job.rec_name,
|
||||||
|
'Transfer to Book-2|Book 1|to|Book 2|06/01/2022|usd10.00')
|
||||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
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(job.booktransf.rec_name, 'Book 2 | 0.00 usd | Open')
|
||||||
self.assertEqual(len(job.cashbook.lines), 0)
|
self.assertEqual(len(job.cashbook.lines), 0)
|
||||||
|
@ -514,7 +525,9 @@ class PlannerTestCase(object):
|
||||||
'subject': 'booking 10 € --> 10.5 usd',
|
'subject': 'booking 10 € --> 10.5 usd',
|
||||||
'booktransf': target_book.id,
|
'booktransf': target_book.id,
|
||||||
'wfcheck': True}])
|
'wfcheck': True}])
|
||||||
self.assertEqual(job.rec_name, 'Transfer to Book-2')
|
self.assertEqual(
|
||||||
|
job.rec_name,
|
||||||
|
'Transfer to Book-2|Book 1|to|Book 2|06/01/2022|€10.00')
|
||||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 € | Open')
|
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 € | Open')
|
||||||
self.assertEqual(job.booktransf.rec_name, 'Book 2 | 0.00 usd | Open')
|
self.assertEqual(job.booktransf.rec_name, 'Book 2 | 0.00 usd | Open')
|
||||||
self.assertEqual(len(job.cashbook.lines), 0)
|
self.assertEqual(len(job.cashbook.lines), 0)
|
||||||
|
@ -583,7 +596,9 @@ class PlannerTestCase(object):
|
||||||
'subject': 'invest 10.00 usd to buy 0.80 units',
|
'subject': 'invest 10.00 usd to buy 0.80 units',
|
||||||
'booktransf': asset_book.id,
|
'booktransf': asset_book.id,
|
||||||
'wfcheck': True}])
|
'wfcheck': True}])
|
||||||
self.assertEqual(job.rec_name, 'buy asset')
|
self.assertEqual(
|
||||||
|
job.rec_name,
|
||||||
|
'buy asset|Book 1|to|Depot|06/01/2022|usd10.00')
|
||||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 usd | Open')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
job.booktransf.rec_name,
|
job.booktransf.rec_name,
|
||||||
|
@ -709,7 +724,9 @@ class PlannerTestCase(object):
|
||||||
'subject': 'invest 10.00 € to buy 0.xx units',
|
'subject': 'invest 10.00 € to buy 0.xx units',
|
||||||
'booktransf': asset_book.id,
|
'booktransf': asset_book.id,
|
||||||
'wfcheck': True}])
|
'wfcheck': True}])
|
||||||
self.assertEqual(job.rec_name, 'buy asset')
|
self.assertEqual(
|
||||||
|
job.rec_name,
|
||||||
|
'buy asset|Book 1|to|Depot|06/01/2022|€10.00')
|
||||||
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 € | Open')
|
self.assertEqual(job.cashbook.rec_name, 'Book 1 | 0.00 € | Open')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
job.booktransf.rec_name,
|
job.booktransf.rec_name,
|
||||||
|
|
Loading…
Reference in a new issue