add placeholders for subject of booking
This commit is contained in:
parent
42aeefaa19
commit
acc8911a8d
5 changed files with 88 additions and 14 deletions
56
planner.py
56
planner.py
|
@ -5,6 +5,7 @@
|
|||
|
||||
from decimal import Decimal
|
||||
from datetime import date, timedelta
|
||||
from string import Template
|
||||
from dateutil.rrule import (
|
||||
rrule, YEARLY, MONTHLY, WEEKLY, DAILY, MO, TU, WE, TH, FR, SA, SU)
|
||||
from trytond.model import ModelSQL, ModelView, fields, Index, DeactivableMixin
|
||||
|
@ -430,6 +431,60 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
return IrDate.today()
|
||||
|
||||
@classmethod
|
||||
def fill_placeholder(cls, linedata):
|
||||
""" replace placeholder in description
|
||||
|
||||
Args:
|
||||
description (str): booking text of planned booking
|
||||
allowed substitution strings:
|
||||
${date}, ${month}, ${year}, ${amount}, ${quantity}
|
||||
|
||||
Returns:
|
||||
str: booking text
|
||||
"""
|
||||
pool = Pool()
|
||||
IrDate = pool.get('ir.date')
|
||||
Cashbook = pool.get('cashbook.book')
|
||||
|
||||
line_date = linedata.get('date', IrDate.today())
|
||||
amount = linedata.get('amount', None)
|
||||
from_book = linedata.get('cashbook', None)
|
||||
if from_book:
|
||||
from_book = Cashbook(from_book)
|
||||
to_book = linedata.get('booktransf', None)
|
||||
if to_book:
|
||||
to_book = Cashbook(to_book)
|
||||
|
||||
quantity_txt = '-'
|
||||
quantity = linedata.get('quantity', None)
|
||||
if quantity is not None:
|
||||
uom = (
|
||||
to_book.quantity_uom if to_book and to_book.quantity_uom
|
||||
else from_book.quantity_uom
|
||||
if from_book and from_book.quantity_uom else None)
|
||||
uom_digits = (
|
||||
to_book.quantity_digits
|
||||
if to_book and to_book.quantity_digits is not None
|
||||
else from_book.quantity_digits
|
||||
if from_book and from_book.quantity_digits is not None
|
||||
else 2)
|
||||
if uom:
|
||||
quantity_txt = Report.format_number_symbol(
|
||||
quantity, lang=None, symbol=uom, digits=uom_digits)
|
||||
else:
|
||||
quantity_txt = Report.format_number(
|
||||
quantity, lang=None, digits=uom_digits)
|
||||
|
||||
return Template(linedata.get('description')).safe_substitute({
|
||||
'date': Report.format_date(line_date, lang=None),
|
||||
'month': line_date.month,
|
||||
'year': line_date.year,
|
||||
'amount': Report.format_currency(
|
||||
amount, lang=None, currency=from_book.currency)
|
||||
if (amount is not None) and from_book else '-',
|
||||
'quantity': quantity_txt})
|
||||
|
||||
@classmethod
|
||||
def update_next_occurence(cls, records, query_date=None):
|
||||
""" compute date of next execution, create/update nextrun-record,
|
||||
|
@ -573,6 +628,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
if record.booktransf.feature == 'asset':
|
||||
line.update(add_asset_values(
|
||||
line, record.cashbook, record.booktransf))
|
||||
line['description'] = cls.fill_placeholder(line)
|
||||
|
||||
if record.wfcheck:
|
||||
to_create_check.append(line)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue