config: new field 'holidays_info' to show generated holidays in config-form
This commit is contained in:
parent
b54a8d678f
commit
e76ec5792c
5 changed files with 55 additions and 6 deletions
29
config.py
29
config.py
|
@ -9,6 +9,9 @@ from dateutil.easter import (
|
|||
easter, EASTER_JULIAN, EASTER_ORTHODOX, EASTER_WESTERN)
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import fields
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.report import Report
|
||||
|
||||
|
||||
holidays = fields.Char(
|
||||
string='Holidays', help='Semicolon separate list of dates: ' +
|
||||
|
@ -21,6 +24,32 @@ class Configuration(metaclass=PoolMeta):
|
|||
__name__ = 'cashbook.configuration'
|
||||
|
||||
holidays = fields.MultiValue(holidays)
|
||||
holidays_info = fields.Function(fields.Char(
|
||||
string='Holidays', readonly=True,
|
||||
help='Holidays in the current year.'), 'on_change_with_holidays_info')
|
||||
|
||||
@fields.depends('holidays')
|
||||
def on_change_with_holidays_info(self, name=None):
|
||||
""" get string of generated holidays for years in
|
||||
context-value 'holiday_years' or current year
|
||||
|
||||
Args:
|
||||
name (str, optional): field. Defaults to None.
|
||||
|
||||
Returns:
|
||||
str: formatted holidays in language of user
|
||||
"""
|
||||
pool = Pool()
|
||||
Config = pool.get('cashbook.configuration')
|
||||
context = Transaction().context
|
||||
|
||||
years = context.get('holiday_years', [])
|
||||
cfg1 = Config.get_singleton()
|
||||
if cfg1:
|
||||
dates = cfg1.holiday_dates(years)
|
||||
dates.sort()
|
||||
return '|'.join([
|
||||
Report.format_date(x) for x in dates])
|
||||
|
||||
def holiday_dates(self, years=[]):
|
||||
""" get list of dates for list of years
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue