Allow to fixate a booking from Booking-Wizard

This commit is contained in:
Frederik Jaeckel 2024-05-30 12:44:11 +02:00
parent 65437bc52e
commit 852ff6871d
5 changed files with 47 additions and 7 deletions

View file

@ -1646,6 +1646,18 @@ msgctxt "field:cashbook.enterbooking.start,party:"
msgid "Party"
msgstr "Partei"
msgctxt "field:cashbook.enterbooking.start,description:"
msgid "Description"
msgstr "Beschreibung"
msgctxt "field:cashbook.enterbooking.start,fixate:"
msgid "Fixate"
msgstr "Festschreiben"
msgctxt "help:cashbook.enterbooking.start,fixate:"
msgid "The booking is fixed immediately."
msgstr "Die Buchung wird sofort festgeschrieben."
#########################
# cashbook.enterbooking #

View file

@ -1554,6 +1554,18 @@ msgctxt "field:cashbook.enterbooking.start,party:"
msgid "Party"
msgstr "Party"
msgctxt "field:cashbook.enterbooking.start,description:"
msgid "Description"
msgstr "Description"
msgctxt "field:cashbook.enterbooking.start,fixate:"
msgid "Fixate"
msgstr "Fixate"
msgctxt "help:cashbook.enterbooking.start,fixate:"
msgid "The booking is fixed immediately."
msgstr "The booking is fixed immediately."
msgctxt "model:cashbook.enterbooking,name:"
msgid "Enter Booking"
msgstr "Enter Booking"

View file

@ -65,6 +65,7 @@ class BookingWizardTestCase(object):
self.assertEqual(result['view']['defaults']['booktransf'], None)
self.assertEqual(result['view']['defaults']['description'], None)
self.assertEqual(result['view']['defaults']['category'], None)
self.assertEqual(result['view']['defaults']['fixate'], False)
self.assertEqual(len(book.lines), 0)
@ -75,7 +76,7 @@ class BookingWizardTestCase(object):
'description': 'Test 1',
'category': categories[1].id,
'bookingtype': 'out',
}
'fixate': True}
for x in r1.keys():
setattr(w_obj.start, x, r1[x])
@ -88,6 +89,7 @@ class BookingWizardTestCase(object):
self.assertEqual(
book.lines[0].rec_name,
'05/01/2022|Exp|-10.00 usd|Test 1 [Food]')
self.assertEqual(book.lines[0].state, 'check')
@with_transaction()
def test_bookwiz_transfer(self):
@ -147,6 +149,7 @@ class BookingWizardTestCase(object):
self.assertEqual(result['view']['defaults']['booktransf'], None)
self.assertEqual(result['view']['defaults']['description'], None)
self.assertEqual(result['view']['defaults']['category'], None)
self.assertEqual(result['view']['defaults']['fixate'], False)
self.assertEqual(len(books[0].lines), 0)
self.assertEqual(len(books[1].lines), 0)
@ -157,7 +160,7 @@ class BookingWizardTestCase(object):
'description': 'Test 1',
'booktransf': books[1].id,
'bookingtype': 'mvout',
}
'fixate': False}
for x in r1.keys():
setattr(w_obj.start, x, r1[x])

View file

@ -22,6 +22,10 @@ full copyright notices and license terms. -->
<page id="descr" string="Description" col="1">
<field name="description"/>
</page>
<page name="fixate" col="2">
<label name="fixate"/>
<field name="fixate"/>
</page>
</notebook>
<field name="cashbooks"/>
@ -29,4 +33,3 @@ full copyright notices and license terms. -->
<field name="currency"/>
<field name="owner_cashbook"/>
</form>

View file

@ -7,7 +7,7 @@ from trytond.model import ModelView, fields
from trytond.wizard import Wizard, StateView, StateTransition, Button
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.pyson import Eval, Bool, If
from trytond.pyson import Eval, Bool, If, And
from decimal import Decimal
from .line import sel_bookingtype
@ -45,7 +45,9 @@ class EnterBookingStart(ModelView):
depends=['currency_digits', 'bookingtype'],
digits=(16, Eval('currency_digits', 2)), required=True,
domain=[('amount', '>=', Decimal('0.0'))])
description = fields.Text(string='Description')
description = fields.Text(
string='Description', states={'required': Bool(Eval('fixate'))},
depends=['fixate'])
category = fields.Many2One(
string='Category',
model_name='cashbook.category', depends=['bookingtype'],
@ -60,6 +62,8 @@ class EnterBookingStart(ModelView):
('cattype', '=', 'in'),
('cattype', '=', 'out'),
)])
fixate = fields.Boolean(
string='Fixate', help='The booking is fixed immediately.')
# party or cashbook as counterpart
booktransf = fields.Many2One(
@ -77,7 +81,10 @@ class EnterBookingStart(ModelView):
string='Party', model_name='party.party',
states={
'invisible': ~Eval('bookingtype', '').in_(['in', 'out']),
}, depends=['bookingtype'])
'required': And(
Bool(Eval('fixate')),
Eval('bookingtype', '').in_(['in', 'out']))},
depends=['bookingtype', 'fixate'])
@fields.depends('bookingtype', 'category')
def on_change_bookingtype(self):
@ -150,6 +157,7 @@ class EnterBookingWizard(Wizard):
book_ids.append(getattr(cfg1, x, None).id)
result = {
'fixate': False,
'cashbooks': [x.id for x in Cashbook.search([
('state', '=', 'open'),
('btype', '!=', None),
@ -187,7 +195,9 @@ class EnterBookingWizard(Wizard):
elif self.start.bookingtype in ['mvin', 'mvout']:
query['booktransf'] = self.start.booktransf.id
Line.create([query])
lines = Line.create([query])
if self.start.fixate:
Line.wfcheck(lines)
return 'end'
def transition_savenext_(self):