evaluation - werte für currency+test
This commit is contained in:
parent
1f7149f472
commit
f4950c5033
2 changed files with 47 additions and 3 deletions
|
@ -310,7 +310,7 @@ class EvaluationTypeRel(RelFieldsMixin, ModelSQL):
|
|||
|
||||
@fields.depends('evaluation', 'eval_currency', 'currency_digits', 'dtype')
|
||||
def on_change_with_balance(self, name=None):
|
||||
""" get balanceof bookings in cashbooks by 'type',
|
||||
""" get balance of bookings in cashbooks by 'type',
|
||||
converted to currency of evaluation
|
||||
"""
|
||||
pool = Pool()
|
||||
|
@ -389,9 +389,44 @@ class EvaluationCurrencyRel(RelFieldsMixin, ModelSQL):
|
|||
if self.currency:
|
||||
return self.currency.rec_name
|
||||
|
||||
@fields.depends('evaluation', 'eval_currency', 'currency_digits', 'currency')
|
||||
def on_change_with_balance(self, name=None):
|
||||
""" balance of cashbook
|
||||
""" get balance of bookings in cashbooks by 'currency',
|
||||
converted to currency of evaluation
|
||||
"""
|
||||
return None
|
||||
pool = Pool()
|
||||
Lines = pool.get('cashbook.line')
|
||||
Currency = pool.get('currency.currency')
|
||||
tab_line = Lines.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
if (self.evaluation is None) or (self.currency is None) or \
|
||||
(self.eval_currency is None) or (self.currency_digits is None):
|
||||
return None
|
||||
|
||||
lines = Lines.search([
|
||||
('cashbook.currency.id', '=', self.currency.id),
|
||||
('cashbook.state', '=', 'open'),
|
||||
('cashbook.owner.id', '=', Transaction().user),
|
||||
], query=True)
|
||||
|
||||
query = lines.join(tab_line, condition=lines.id==tab_line.id,
|
||||
).select(
|
||||
Sum(tab_line.credit - tab_line.debit).as_('balance'),
|
||||
)
|
||||
cursor.execute(*query)
|
||||
balances = cursor.fetchall()
|
||||
|
||||
total_amount = Decimal('0.0')
|
||||
for balance in balances:
|
||||
(bal1,) = balance
|
||||
|
||||
total_amount += Currency.compute(
|
||||
self.currency,
|
||||
bal1,
|
||||
self.eval_currency,
|
||||
)
|
||||
exp = Decimal(Decimal(1) / 10 ** self.currency_digits)
|
||||
return total_amount.quantize(exp)
|
||||
|
||||
# end EvaluationCurrencyRel
|
||||
|
|
|
@ -398,7 +398,16 @@ class ReportTestCase(CashbookTestCase):
|
|||
self.assertEqual(evaluation.posted, False)
|
||||
self.assertEqual(evaluation.maincolor, 'default')
|
||||
self.assertEqual(evaluation.bgcolor, '#ffffc0')
|
||||
self.assertEqual(evaluation.currency.code, 'EUR')
|
||||
|
||||
self.assertEqual(len(evaluation.currencies), 2)
|
||||
self.assertEqual(evaluation.currencies[0].code, 'EUR')
|
||||
self.assertEqual(evaluation.currencies[1].code, 'usd')
|
||||
|
||||
self.assertEqual(len(evaluation.currency_values), 2)
|
||||
self.assertEqual(evaluation.currency_values[0].name, 'Euro')
|
||||
self.assertEqual(evaluation.currency_values[0].balance, Decimal('23.0'))
|
||||
self.assertEqual(evaluation.currency_values[1].name, 'usd')
|
||||
self.assertEqual(evaluation.currency_values[1].balance, Decimal('35.71'))
|
||||
|
||||
# end ReportTestCase
|
||||
|
|
Loading…
Reference in a new issue