add field 'target' for category/cashbook in list view

This commit is contained in:
Frederik Jaeckel 2024-03-09 20:44:33 +01:00
parent acc8911a8d
commit be92110ae1
5 changed files with 59 additions and 7 deletions

View file

@ -302,6 +302,10 @@ msgctxt "help:cashbook.planner,wfcheck:"
msgid "Switches the booking to the 'Verified' state." msgid "Switches the booking to the 'Verified' state."
msgstr "Schaltet die Buchung in den Zustand 'Geprüft'" msgstr "Schaltet die Buchung in den Zustand 'Geprüft'"
msgctxt "field:cashbook.planner,booking_target:"
msgid "Target"
msgstr "Ziel"
############################ ############################
# cashbook.planner.nextrun # # cashbook.planner.nextrun #

View file

@ -278,6 +278,10 @@ msgctxt "help:cashbook.planner,wfcheck:"
msgid "Switches the booking to the 'Verified' state." msgid "Switches the booking to the 'Verified' state."
msgstr "Switches the booking to the 'Verified' state." msgstr "Switches the booking to the 'Verified' state."
msgctxt "field:cashbook.planner,booking_target:"
msgid "Target"
msgstr "Target"
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"

View file

@ -148,6 +148,9 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
wfcheck = fields.Boolean( wfcheck = fields.Boolean(
string="Set to 'Checked'", string="Set to 'Checked'",
help="Switches the booking to the 'Verified' state.") help="Switches the booking to the 'Verified' state.")
booking_target = fields.Function(fields.Reference(
string='Target', selection='get_booking_modelnames', readonly=True),
'on_change_with_booking_target')
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
@ -249,6 +252,38 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
break break
return result return result
@classmethod
def get_booking_modelnames(cls):
""" get list of model for field 'booking_target
Returns:
list: list of tuple: (model_name, Description)
"""
Model = Pool().get('ir.model')
return [
(x.model, x.name)
for x in Model.search([
('model', 'in', ['cashbook.book', 'cashbook.category'])])]
@fields.depends('bookingtype', 'category', 'booktransf')
def on_change_with_booking_target(self, name=None):
""" get category of target-cashbook
Args:
name (str, optional): name of field. Defaults to None.
Returns:
tuple: tuple with model-name and id of booking-target
"""
if self.bookingtype in ['in', 'out']:
if self.category:
return '%s,%d' % (
self.category.__name__, self.category.id)
elif self.bookingtype in ['mvin', 'mvout']:
if self.booktransf:
return '%s,%d' % (
self.booktransf.__name__, self.booktransf.id)
@fields.depends('cashbook', '_parent_cashbook.currency') @fields.depends('cashbook', '_parent_cashbook.currency')
def on_change_with_currency_cashbook(self, name=None): def on_change_with_currency_cashbook(self, name=None):
""" get currency of selected cashbook """ get currency of selected cashbook

View file

@ -137,6 +137,7 @@ class PlannerTestCase(object):
Planner.write, Planner.write,
*[[job], {'end_date': date(2022, 5, 1)}]) *[[job], {'end_date': date(2022, 5, 1)}])
self.assertEqual(job.booking_target.name, 'Cat1')
Planner.write(*[[job], { Planner.write(*[[job], {
'end_date': date(2022, 9, 15), 'monthday': 3}]) 'end_date': date(2022, 9, 15), 'monthday': 3}])
self.assertEqual( self.assertEqual(
@ -466,6 +467,7 @@ class PlannerTestCase(object):
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)
self.assertEqual(job.booking_target.name, 'Book 2')
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))

View file

@ -5,11 +5,18 @@ full copyright notices and license terms. -->
<tree> <tree>
<field name="active"/> <field name="active"/>
<field name="name"/> <field name="name"/>
<field name="cashbook"/>
<field name="nextrun_link"/> <field name="start_date" optional="1"/>
<field name="bookingtype"/> <field name="end_date" optional="1"/>
<field name="amount"/> <field name="frequ" optional="1"/>
<field name="category"/> <field name="weekday" optional="1"/>
<field name="party"/> <field name="interval" optional="1"/>
<field name="booktransf"/> <field name="wfcheck" optional="1"/>
<field name="cashbook" optional="0"/>
<field name="nextrun_link" optional="0"/>
<field name="amount" optional="0"/>
<field name="bookingtype" optional="0"/>
<field name="booking_target" optional="0"/>
<field name="party" optional="0"/>
</tree> </tree>