formatting, line: test for delete of party

This commit is contained in:
Frederik Jaeckel 2023-05-18 12:15:53 +02:00
parent 78f160bf0b
commit 619a17bcd6
16 changed files with 701 additions and 516 deletions

View file

@ -4,13 +4,12 @@
# full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, Workflow, fields, Check
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
from trytond.pyson import Eval, If
from trytond.report import Report
from trytond.i18n import gettext
from trytond.transaction import Transaction
from .line import sel_linetype, sel_bookingtype, STATES, DEPENDS
from .line import sel_bookingtype, STATES, DEPENDS
from .book import sel_state_book
from .mixin import SecondCurrencyMixin, MemCacheIndexMx
@ -30,15 +29,18 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
'Split booking line'
__name__ = 'cashbook.split'
line = fields.Many2One(string='Line', required=True,
line = fields.Many2One(
string='Line', required=True,
select=True, ondelete='CASCADE', model_name='cashbook.line',
readonly=True)
description = fields.Text(string='Description',
states=STATES, depends=DEPENDS)
splittype = fields.Selection(string='Type', required=True,
description = fields.Text(
string='Description', states=STATES, depends=DEPENDS)
splittype = fields.Selection(
string='Type', required=True,
help='Type of split booking line', selection=sel_linetype,
states=STATES, depends=DEPENDS, select=True)
category = fields.Many2One(string='Category', select=True,
category = fields.Many2One(
string='Category', select=True,
model_name='cashbook.category', ondelete='RESTRICT',
states={
'readonly': STATES['readonly'],
@ -51,9 +53,11 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
('cattype', '=', 'in'),
('cattype', '=', 'out'),
)])
category_view = fields.Function(fields.Char(string='Category', readonly=True),
category_view = fields.Function(fields.Char(
string='Category', readonly=True),
'on_change_with_category_view')
booktransf = fields.Many2One(string='Source/Dest',
booktransf = fields.Many2One(
string='Source/Dest',
ondelete='RESTRICT', model_name='cashbook.book',
domain=[
('owner.id', '=', Eval('owner_cashbook', -1)),
@ -66,32 +70,43 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
'required': Eval('splittype', '') == 'tr',
}, depends=DEPENDS+['bookingtype', 'owner_cashbook', 'cashbook'])
amount = fields.Numeric(string='Amount', digits=(16, Eval('currency_digits', 2)),
amount = fields.Numeric(
string='Amount', digits=(16, Eval('currency_digits', 2)),
required=True, states=STATES, depends=DEPENDS+['currency_digits'])
date = fields.Function(fields.Date(string='Date', readonly=True),
'on_change_with_date')
target = fields.Function(fields.Reference(string='Target', readonly=True,
date = fields.Function(fields.Date(
string='Date', readonly=True), 'on_change_with_date')
target = fields.Function(fields.Reference(
string='Target', readonly=True,
selection=sel_target), 'on_change_with_target')
currency = fields.Function(fields.Many2One(model_name='currency.currency',
currency = fields.Function(fields.Many2One(
model_name='currency.currency',
string="Currency", readonly=True), 'on_change_with_currency')
currency_digits = fields.Function(fields.Integer(string='Currency Digits',
currency_digits = fields.Function(fields.Integer(
string='Currency Digits',
readonly=True), 'on_change_with_currency_digits')
bookingtype = fields.Function(fields.Selection(string='Type', readonly=True,
bookingtype = fields.Function(fields.Selection(
string='Type', readonly=True,
selection=sel_bookingtype), 'on_change_with_bookingtype')
state = fields.Function(fields.Selection(string='State', readonly=True,
state = fields.Function(fields.Selection(
string='State', readonly=True,
selection=sel_linetype), 'on_change_with_state')
cashbook = fields.Function(fields.Many2One(string='Cashbook',
cashbook = fields.Function(fields.Many2One(
string='Cashbook',
readonly=True, states={'invisible': True}, model_name='cashbook.book'),
'on_change_with_cashbook')
feature = fields.Function(fields.Char(string='Feature', readonly=True,
feature = fields.Function(fields.Char(
string='Feature', readonly=True,
states={'invisible': True}), 'on_change_with_feature')
booktransf_feature = fields.Function(fields.Char(string='Feature', readonly=True,
booktransf_feature = fields.Function(fields.Char(
string='Feature', readonly=True,
states={'invisible': True}), 'on_change_with_booktransf_feature')
state_cashbook = fields.Function(fields.Selection(string='State of Cashbook',
state_cashbook = fields.Function(fields.Selection(
string='State of Cashbook',
readonly=True, states={'invisible': True}, selection=sel_state_book),
'on_change_with_state_cashbook')
owner_cashbook = fields.Function(fields.Many2One(string='Owner', readonly=True,
owner_cashbook = fields.Function(fields.Many2One(
string='Owner', readonly=True,
states={'invisible': True}, model_name='res.user'),
'on_change_with_owner_cashbook')
@ -108,8 +123,10 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
'desc': (self.description or '-')[:40],
'amount': Report.format_number(self.amount, None),
'symbol': getattr(self.currency, 'symbol', '-'),
'target': self.category_view if self.splittype == 'cat' else self.booktransf.rec_name,
'type': gettext('cashbook.msg_line_bookingtype_%s' % self.line.bookingtype),
'target': self.category_view
if self.splittype == 'cat' else self.booktransf.rec_name,
'type': gettext(
'cashbook.msg_line_bookingtype_%s' % self.line.bookingtype),
}
@fields.depends('splittype', 'category', 'booktransf')
@ -151,9 +168,9 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
if self.category:
cfg1 = Configuration.get_singleton()
if getattr(cfg1, 'catnamelong', True) == True:
if getattr(cfg1, 'catnamelong', True) is True:
return self.category.rec_name
else :
else:
return self.category.name
@fields.depends('line', '_parent_line.state')
@ -246,7 +263,7 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
to_update_line = []
for record in records:
if not record.line in to_update_line:
if record.line not in to_update_line:
to_update_line.append(record.line)
to_write = Line2.update_values_by_splitlines(to_update_line)
@ -268,7 +285,7 @@ class SplitLine(SecondCurrencyMixin, MemCacheIndexMx, ModelSQL, ModelView):
if 'amount' in values.keys():
for record in records:
if not record.line in to_update_line:
if record.line not in to_update_line:
to_update_line.append(record.line)
super(SplitLine, cls).write(*args)