add list of booking lines on scheduled bookings

This commit is contained in:
Frederik Jaeckel 2024-03-09 22:36:51 +01:00
parent be92110ae1
commit 9b0af0d64e
7 changed files with 118 additions and 3 deletions

View file

@ -5,8 +5,8 @@
from trytond.pool import Pool from trytond.pool import Pool
from .ir import Rule from .ir import Rule
from .planner import ScheduledBooking from .planner import ScheduledBooking, ScheduledBookingCashbookRel
from .cashbook import Cashbook from .cashbook import Cashbook, CashbookLine
from .cron import Cron from .cron import Cron
from .nextrun import NextRun from .nextrun import NextRun
@ -17,5 +17,7 @@ def register():
ScheduledBooking, ScheduledBooking,
NextRun, NextRun,
Cashbook, Cashbook,
CashbookLine,
Cron, Cron,
ScheduledBookingCashbookRel,
module='cashbook_planner', type_='model') module='cashbook_planner', type_='model')

View file

@ -18,3 +18,13 @@ class Cashbook(metaclass=PoolMeta):
states={'invisible': ~Bool(Eval('btype'))}) states={'invisible': ~Bool(Eval('btype'))})
# end Cashbook # end Cashbook
class CashbookLine(metaclass=PoolMeta):
__name__ = 'cashbook.line'
planners = fields.Many2Many(
string='Scheduled Bookings', relation_name='cashbook.planner_rel',
origin='line', target='planner')
# end CashbookLine

View file

@ -110,6 +110,10 @@ msgctxt "view:cashbook.planner:"
msgid "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}" msgid "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}"
msgstr "verfügbare Platzhalter: ${date} ${month} ${year} ${amount} ${quantity}" msgstr "verfügbare Platzhalter: ${date} ${month} ${year} ${amount} ${quantity}"
msgctxt "view:cashbook.planner:"
msgid "Cashbook lines"
msgstr "Kassenbuchzeilen"
msgctxt "field:cashbook.planner,company:" msgctxt "field:cashbook.planner,company:"
msgid "Company" msgid "Company"
msgstr "Unternehmen" msgstr "Unternehmen"
@ -306,6 +310,14 @@ msgctxt "field:cashbook.planner,booking_target:"
msgid "Target" msgid "Target"
msgstr "Ziel" msgstr "Ziel"
msgctxt "field:cashbook.planner,cashbook_lines:"
msgid "Cashbook lines"
msgstr "Kassenbuchzeilen"
msgctxt "help:cashbook.planner,cashbook_lines:"
msgid "This cash book lines was generated by the current scheduled booking."
msgstr "Diese Kassenbuchzeilen wurden durch die aktuelle geplante Buchung generiert."
############################ ############################
# cashbook.planner.nextrun # # cashbook.planner.nextrun #
@ -323,6 +335,22 @@ msgid "Date"
msgstr "Datum" msgstr "Datum"
########################
# cashbook.planner_rel #
########################
msgctxt "model:cashbook.planner_rel,name:"
msgid "Scheduled Booking - Cashbook - Relation"
msgstr "geplante Buchung - Kassenbuch - Verknüpfung"
msgctxt "field:cashbook.planner_rel,planner:"
msgid "Planner"
msgstr "geplante Buchung"
msgctxt "field:cashbook.planner_rel,line:"
msgid "Cashbook Line"
msgstr "Kassenbuchzeile"
################# #################
# cashbook.book # # cashbook.book #
################# #################
@ -333,3 +361,15 @@ msgstr "geplante Buchungen"
msgctxt "field:cashbook.book,planner:" msgctxt "field:cashbook.book,planner:"
msgid "Scheduled Bookings" msgid "Scheduled Bookings"
msgstr "geplante Buchungen" msgstr "geplante Buchungen"
#################
# cashbook.line #
#################
msgctxt "view:cashbook.line:"
msgid "Scheduled Bookings"
msgstr "geplante Buchungen"
msgctxt "field:cashbook.line,planners:"
msgid "Scheduled Bookings"
msgstr "geplante Buchungen"

View file

@ -86,6 +86,10 @@ msgctxt "view:cashbook.planner:"
msgid "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}" msgid "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}"
msgstr "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}" msgstr "Available placeholders: ${date} ${month} ${year} ${amount} ${quantity}"
msgctxt "view:cashbook.planner:"
msgid "Cashbook lines"
msgstr "Cashbook lines"
msgctxt "field:cashbook.planner,company:" msgctxt "field:cashbook.planner,company:"
msgid "Company" msgid "Company"
msgstr "Company" msgstr "Company"
@ -282,6 +286,14 @@ msgctxt "field:cashbook.planner,booking_target:"
msgid "Target" msgid "Target"
msgstr "Target" msgstr "Target"
msgctxt "field:cashbook.planner,cashbook_lines:"
msgid "Cashbook lines"
msgstr "Cashbook lines"
msgctxt "help:cashbook.planner,cashbook_lines:"
msgid "This cash book lines was generated by the current scheduled booking."
msgstr "This cash book lines was generated by the current scheduled booking."
msgctxt "model:cashbook.planner.nextrun,name:" msgctxt "model:cashbook.planner.nextrun,name:"
msgid "Next Execution Date" msgid "Next Execution Date"
msgstr "Next Execution Date" msgstr "Next Execution Date"
@ -294,7 +306,27 @@ msgctxt "field:cashbook.planner.nextrun,date:"
msgid "Date" msgid "Date"
msgstr "Date" msgstr "Date"
msgctxt "model:cashbook.planner_rel,name:"
msgid "Scheduled Booking - Cashbook - Relation"
msgstr "Scheduled Booking - Cashbook - Relation"
msgctxt "field:cashbook.planner_rel,planner:"
msgid "Planner"
msgstr "Planner"
msgctxt "field:cashbook.planner_rel,line:"
msgid "Cashbook Line"
msgstr "Cashbook Line"
msgctxt "view:cashbook.book:" msgctxt "view:cashbook.book:"
msgid "Scheduled Bookings" msgid "Scheduled Bookings"
msgstr "Scheduled Bookings" msgstr "Scheduled Bookings"
msgctxt "field:cashbook.book,planner:"
msgid "Scheduled Bookings"
msgstr "Scheduled Bookings"
msgctxt "view:cashbook.line:"
msgid "Scheduled Bookings"
msgstr "Scheduled Bookings"

View file

@ -151,6 +151,10 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
booking_target = fields.Function(fields.Reference( booking_target = fields.Function(fields.Reference(
string='Target', selection='get_booking_modelnames', readonly=True), string='Target', selection='get_booking_modelnames', readonly=True),
'on_change_with_booking_target') 'on_change_with_booking_target')
cashbook_lines = fields.Many2Many(
string='Cashbook lines', relation_name='cashbook.planner_rel',
help='This cash book lines was generated by the current ' +
'scheduled booking.', origin='planner', target='line')
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
@ -664,6 +668,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
line.update(add_asset_values( line.update(add_asset_values(
line, record.cashbook, record.booktransf)) line, record.cashbook, record.booktransf))
line['description'] = cls.fill_placeholder(line) line['description'] = cls.fill_placeholder(line)
line['planners'] = [('add', [record.id])]
if record.wfcheck: if record.wfcheck:
to_create_check.append(line) to_create_check.append(line)
@ -694,4 +699,18 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
records, records,
query_date=query_date + timedelta(days=1)) query_date=query_date + timedelta(days=1))
# ens ScheduledBooking # end ScheduledBooking
class ScheduledBookingCashbookRel(ModelSQL):
'Scheduled Booking - Cashbook Line - Relation'
__name__ = 'cashbook.planner_rel'
planner = fields.Many2One(
string='Scheduled Booking', required=True,
model_name='cashbook.planner', ondelete='CASCADE')
line = fields.Many2One(
string='Cashbook Line', required=True,
model_name='cashbook.line', ondelete='CASCADE')
# end ScheduledBookingCashbookRel

View file

@ -407,12 +407,21 @@ class PlannerTestCase(object):
job, = Planner.search([]) job, = Planner.search([])
self.assertEqual(job.nextrun[0].date, date(2022, 6, 1)) self.assertEqual(job.nextrun[0].date, date(2022, 6, 1))
self.assertEqual(len(job.cashbook_lines), 0)
IrDate.today = MagicMock(return_value=date(2022, 6, 1)) IrDate.today = MagicMock(return_value=date(2022, 6, 1))
Planner.cronjob() Planner.cronjob()
self.assertEqual(job.nextrun[0].date, date(2022, 7, 1)) self.assertEqual(job.nextrun[0].date, date(2022, 7, 1))
self.assertEqual(len(job.cashbook_lines), 1)
self.assertEqual(
job.cashbook_lines[0].rec_name,
'06/01/2022|Exp|-10.00 usd|booking 6/2022, 06/01/2022 [Cat1]')
# check cashbook # check cashbook
self.assertEqual(len(job.cashbook.lines), 1) self.assertEqual(len(job.cashbook.lines), 1)
self.assertEqual(len(job.cashbook.lines[0].planners), 1)
self.assertEqual(job.cashbook.lines[0].planners[0].id, job.id)
self.assertEqual( self.assertEqual(
job.cashbook.lines[0].rec_name, job.cashbook.lines[0].rec_name,
"06/01/2022|Exp|-10.00 usd|booking 6/2022, 06/01/2022 [Cat1]") "06/01/2022|Exp|-10.00 usd|booking 6/2022, 06/01/2022 [Cat1]")

View file

@ -64,6 +64,9 @@ full copyright notices and license terms. -->
<page name="description" col="1" string="Description"> <page name="description" col="1" string="Description">
<field name="description"/> <field name="description"/>
</page> </page>
<page name="cashbook_lines" col="1" string="Cashbook lines">
<field name="cashbook_lines"/>
</page>
</notebook> </notebook>