add notify

This commit is contained in:
=Frederik Jaeckel 2024-09-28 20:42:32 +02:00
parent 321aeb827d
commit 7504c676e7
6 changed files with 85 additions and 2 deletions

View file

@ -3,6 +3,18 @@ msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
##############
# ir.message #
##############
msgctxt "model:ir.message,text:msg_title_notify"
msgid "Cashbook Scheduled Booking"
msgstr "Kassenbuch geplante Buchung"
msgctxt "model:ir.message,text:msg_text_notify"
msgid "The following transaction was generated: %(bname)s"
msgstr "Die folgende Buchung wurde erzeugt: %(bname)s"
###########
# ir.cron #
###########
@ -386,6 +398,14 @@ msgctxt "help:cashbook.planner,last_day_of_month:"
msgid "The booking is made on the last day of the month."
msgstr "Die Buchung wird am letzten Tag des Monats ausgeführt."
msgctxt "field:cashbook.planner,notify_bycron:"
msgid "Notify"
msgstr "Benachrichtigen"
msgctxt "help:cashbook.planner,notify_bycron:"
msgid "A notification will appear in the web browser when the booking has been created."
msgstr "Es wird eine Benachrichtigung im Webbrowser angezeigt wenn die Buchung erstellt wurde."
############################
# cashbook.planner.nextrun #

View file

@ -2,6 +2,14 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "model:ir.message,text:msg_title_notify"
msgid "Cashbook Scheduled Booking"
msgstr "Cashbook Scheduled Booking"
msgctxt "model:ir.message,text:msg_text_notify"
msgid "The following transaction was generated: %(bname)s"
msgstr "The following transaction was generated: %(bname)s"
msgctxt "selection:ir.cron,method:"
msgid "Execute scheduled bookings"
msgstr "Execute scheduled bookings"
@ -389,3 +397,11 @@ msgstr "Last day of the month"
msgctxt "help:cashbook.planner,last_day_of_month:"
msgid "The booking is made on the last day of the month."
msgstr "The booking is made on the last day of the month."
msgctxt "field:cashbook.planner,notify_bycron:"
msgid "Notify"
msgstr "Notify"
msgctxt "help:cashbook.planner,notify_bycron:"
msgid "A notification will appear in the web browser when the booking has been created."
msgstr "A notification will appear in the web browser when the booking has been created."

16
message.xml Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!-- 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. -->
<tryton>
<data>
<record model="ir.message" id="msg_title_notify">
<field name="text">Cashbook Scheduled Booking</field>
</record>
<record model="ir.message" id="msg_text_notify">
<field name="text">The following transaction was generated: %(bname)s</field>
</record>
</data>
</tryton>

View file

@ -14,6 +14,7 @@ from trytond.pool import Pool
from trytond.report import Report
from trytond.i18n import gettext
from trytond.pyson import Eval, Bool, If, And
from trytond.bus import notify
from trytond.modules.currency.fields import Monetary
from trytond.modules.cashbook.book import sel_state_book
from trytond.modules.cashbook.line import sel_bookingtype as sel_bookingtype_cb
@ -117,6 +118,9 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
string='If no business day', required=True, selection=SEL_MOVE_EVENT,
help='If the date of execution falls on a weekend or holiday, ' +
'it can be moved to a business day.')
notify_bycron = fields.Boolean(
string='Notify', help='A notification will appear in the web ' +
'browser when the booking has been created.')
bookingtype = fields.Selection(
string='Type', selection=sel_bookingtype, required=True,
@ -614,6 +618,15 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
IrDate = Pool().get('ir.date')
return IrDate.today()
@classmethod
def default_notify_bycron(cls):
""" get False as default
Returns:
boolean: False
"""
return False
@classmethod
def fill_placeholder(cls, linedata):
""" replace placeholder in description
@ -843,11 +856,27 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
else:
to_create.append(line)
to_notify = []
if to_create_check:
lines = Line.create(to_create_check)
Line.wfcheck(lines)
to_notify.extend([
x for x in lines
if x.planners[0].notify_bycron])
if to_create:
Line.create(to_create)
lines = Line.create(to_create)
to_notify.extend([
x for x in lines
if x.planners[0].notify_bycron])
for line in to_notify:
notify(
title=gettext('cashbook_planner.msg_title_notify'),
body=gettext(
'cashbook_planner.msg_text_notify',
bname=line.rec_name),
user=line.cashbook.owner.id)
@classmethod
def cronjob(cls):

View file

@ -5,6 +5,7 @@ depends:
extras_depend:
cashbook_investment
xml:
message.xml
group.xml
planner.xml
nextrun.xml

View file

@ -61,7 +61,8 @@ full copyright notices and license terms. -->
<label name="wfcheck"/>
<field name="wfcheck"/>
<newline/>
<label name="notify_bycron"/>
<field name="notify_bycron"/>
<separator name="subject" colspan="4" string="Booking text"/>
<field name="subject" colspan="4"/>