line: 'values' für counterpart-buchung als funktion
This commit is contained in:
parent
7a715d5ea1
commit
e0a6d39bdb
1 changed files with 31 additions and 23 deletions
54
line.py
54
line.py
|
@ -349,20 +349,7 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
||||||
if line.reference is None:
|
if line.reference is None:
|
||||||
if line.bookingtype in ['mvout', 'mvin']:
|
if line.bookingtype in ['mvout', 'mvin']:
|
||||||
# in case of 'mvin' or 'mvout' - add counterpart
|
# in case of 'mvin' or 'mvout' - add counterpart
|
||||||
values = {
|
values = cls.get_counterpart_values(line)
|
||||||
'cashbook': line.booktransf.id,
|
|
||||||
'bookingtype': 'mvin' if line.bookingtype == 'mvout' else 'mvout',
|
|
||||||
'date': line.date,
|
|
||||||
'description': line.description,
|
|
||||||
'booktransf': line.cashbook.id,
|
|
||||||
'reference': line.id,
|
|
||||||
'amount': line.amount \
|
|
||||||
if line.currency.id == line.booktransf.currency.id \
|
|
||||||
else line.amount_2nd_currency,
|
|
||||||
'amount_2nd_currency': line.amount \
|
|
||||||
if line.currency.id != line.booktransf.currency.id \
|
|
||||||
else None,
|
|
||||||
}
|
|
||||||
values.update(cls.get_debit_credit(values))
|
values.update(cls.get_debit_credit(values))
|
||||||
to_create_line.append(values)
|
to_create_line.append(values)
|
||||||
elif line.bookingtype in ['spout', 'spin']:
|
elif line.bookingtype in ['spout', 'spin']:
|
||||||
|
@ -371,23 +358,18 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
||||||
if sp_line.splittype != 'tr':
|
if sp_line.splittype != 'tr':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
values = {
|
values = cls.get_counterpart_values(line, {
|
||||||
'cashbook': sp_line.booktransf.id,
|
'cashbook': sp_line.booktransf.id,
|
||||||
'date': line.date,
|
|
||||||
'description': sp_line.description,
|
'description': sp_line.description,
|
||||||
'booktransf': line.cashbook.id,
|
|
||||||
'reference': line.id,
|
|
||||||
'amount': sp_line.amount \
|
'amount': sp_line.amount \
|
||||||
if sp_line.currency.id == sp_line.booktransf.currency.id \
|
if sp_line.currency.id == sp_line.booktransf.currency.id \
|
||||||
else sp_line.amount_2nd_currency,
|
else sp_line.amount_2nd_currency,
|
||||||
'amount_2nd_currency': sp_line.amount \
|
'amount_2nd_currency': sp_line.amount \
|
||||||
if sp_line.currency.id != sp_line.booktransf.currency.id \
|
if sp_line.currency.id != sp_line.booktransf.currency.id \
|
||||||
else None,
|
else None,
|
||||||
}
|
'bookingtype': 'mvin' \
|
||||||
if line.bookingtype.endswith('out'):
|
if line.bookingtype.endswith('out') else 'mvout',
|
||||||
values['bookingtype'] = 'mvin'
|
})
|
||||||
else :
|
|
||||||
values['bookingtype'] = 'mvout'
|
|
||||||
values.update(cls.get_debit_credit(values))
|
values.update(cls.get_debit_credit(values))
|
||||||
to_create_line.append(values)
|
to_create_line.append(values)
|
||||||
|
|
||||||
|
@ -784,6 +766,32 @@ class Line(SecondCurrencyMixin, Workflow, ModelSQL, ModelView):
|
||||||
values2['category'] = None
|
values2['category'] = None
|
||||||
return values2
|
return values2
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_counterpart_values(cls, line, values={}):
|
||||||
|
""" get values to create counter-part of
|
||||||
|
transfer booking
|
||||||
|
"""
|
||||||
|
line_currency = getattr(line.currency, 'id', None)
|
||||||
|
booktransf_currency = getattr(getattr(line.booktransf, 'currency', {}), 'id', None)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
'cashbook': getattr(line.booktransf, 'id', None),
|
||||||
|
'bookingtype': 'mvin' if line.bookingtype == 'mvout' else 'mvout',
|
||||||
|
'date': line.date,
|
||||||
|
'description': line.description,
|
||||||
|
'booktransf': line.cashbook.id,
|
||||||
|
'reference': line.id,
|
||||||
|
'amount': line.amount \
|
||||||
|
if line_currency == booktransf_currency \
|
||||||
|
else line.amount_2nd_currency,
|
||||||
|
'amount_2nd_currency': line.amount \
|
||||||
|
if line_currency != booktransf_currency \
|
||||||
|
else None,
|
||||||
|
}
|
||||||
|
# update values from 'values'
|
||||||
|
result.update(values)
|
||||||
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_debit_credit(cls, values):
|
def get_debit_credit(cls, values):
|
||||||
""" compute debit/credit from amount
|
""" compute debit/credit from amount
|
||||||
|
|
Loading…
Reference in a new issue