evaluation - currency filtert ungenutzte währungen + test
This commit is contained in:
parent
01470569e7
commit
3278fc7e52
4 changed files with 125 additions and 2 deletions
|
@ -6,9 +6,11 @@
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from .evaluation import Evaluation, EvaluationCashbookRel, \
|
from .evaluation import Evaluation, EvaluationCashbookRel, \
|
||||||
EvaluationTypeRel, EvaluationCurrencyRel
|
EvaluationTypeRel, EvaluationCurrencyRel
|
||||||
|
from .currency import Currency
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
Currency,
|
||||||
Evaluation,
|
Evaluation,
|
||||||
EvaluationCashbookRel,
|
EvaluationCashbookRel,
|
||||||
EvaluationTypeRel,
|
EvaluationTypeRel,
|
||||||
|
|
62
currency.py
Normal file
62
currency.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# This file is part of the cashbook-module from m-ds for Tryton.
|
||||||
|
# The COPYRIGHT file at the top level of this repository contains the
|
||||||
|
# full copyright notices and license terms.
|
||||||
|
|
||||||
|
from trytond.model import fields
|
||||||
|
from trytond.transaction import Transaction
|
||||||
|
from trytond.pool import Pool, PoolMeta
|
||||||
|
from sql.aggregate import Count
|
||||||
|
from sql.conditionals import Case
|
||||||
|
|
||||||
|
|
||||||
|
class Currency(metaclass=PoolMeta):
|
||||||
|
__name__ = 'currency.currency'
|
||||||
|
|
||||||
|
cashbook_hasbookings = fields.Function(fields.Boolean(string='Has Bookings',
|
||||||
|
readonly=True), 'on_change_with_cashbook_hasbookings',
|
||||||
|
searcher='search_cashbook_hasbookings')
|
||||||
|
|
||||||
|
@fields.depends('id')
|
||||||
|
def on_change_with_cashbook_hasbookings(self, name=None):
|
||||||
|
""" result: True if there are bookings
|
||||||
|
"""
|
||||||
|
Lines = Pool().get('cashbook.line')
|
||||||
|
|
||||||
|
with Transaction().set_context({
|
||||||
|
'_check_access': True,
|
||||||
|
}):
|
||||||
|
if Lines.search_count([
|
||||||
|
('cashbook.currency.id', '=', self.id),
|
||||||
|
]) > 0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_cashbook_hasbookings(cls, name, clause):
|
||||||
|
""" indicate existing bookings
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Currency2 = pool.get('currency.currency')
|
||||||
|
Cashbook = pool.get('cashbook.book')
|
||||||
|
Line = pool.get('cashbook.line')
|
||||||
|
tab_cur = Currency2.__table__()
|
||||||
|
tab_book = Cashbook.__table__()
|
||||||
|
tab_line = Line.__table__()
|
||||||
|
Operator = fields.SQL_OPERATORS[clause[1]]
|
||||||
|
|
||||||
|
query = tab_book.join(tab_line,
|
||||||
|
condition=tab_book.id==tab_line.cashbook,
|
||||||
|
).join(tab_cur,
|
||||||
|
condition=tab_cur.id==tab_book.currency,
|
||||||
|
).select(
|
||||||
|
tab_cur.id,
|
||||||
|
having=Operator(Case(
|
||||||
|
(Count(tab_line.id) > 0, True),
|
||||||
|
else_ = False,
|
||||||
|
), clause[2]),
|
||||||
|
group_by=[tab_cur.id,],
|
||||||
|
)
|
||||||
|
return [('id', 'in', query)]
|
||||||
|
|
||||||
|
# end Currency
|
|
@ -73,12 +73,14 @@ class Evaluation(ModelSQL, ModelView):
|
||||||
currencies = fields.Many2Many(string='Currencies',
|
currencies = fields.Many2Many(string='Currencies',
|
||||||
relation_name='cashbook_report.eval_currency',
|
relation_name='cashbook_report.eval_currency',
|
||||||
origin='evaluation', target='currency',
|
origin='evaluation', target='currency',
|
||||||
|
filter=[('cashbook_hasbookings', '=', True)],
|
||||||
states={
|
states={
|
||||||
'invisible': Eval('dtype', '') != 'currencies',
|
'invisible': Eval('dtype', '') != 'currencies',
|
||||||
}, depends=['dtype'])
|
}, depends=['dtype'])
|
||||||
|
|
||||||
values = fields.One2Many(string='Values', field='evaluation',
|
currency_values = fields.One2Many(string='Currency Values',
|
||||||
model_name='cashbook_report.eval_book', readonly=True)
|
field='evaluation', readonly=True,
|
||||||
|
model_name='cashbook_report.eval_currency')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_company():
|
def default_company():
|
||||||
|
|
|
@ -21,10 +21,21 @@ class ReportTestCase(CashbookTestCase):
|
||||||
"""
|
"""
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Book = pool.get('cashbook.book')
|
Book = pool.get('cashbook.book')
|
||||||
|
ResUser = pool.get('res.user')
|
||||||
|
|
||||||
|
user_admin, = ResUser.search([])
|
||||||
type_cash = self.prep_type()
|
type_cash = self.prep_type()
|
||||||
type_bank = self.prep_type(name='Bank', short='BK')
|
type_bank = self.prep_type(name='Bank', short='BK')
|
||||||
company = self.prep_company()
|
company = self.prep_company()
|
||||||
|
|
||||||
|
ResUser.write(*[
|
||||||
|
[user_admin],
|
||||||
|
{
|
||||||
|
'companies': [('add', [company.id])],
|
||||||
|
'company': company.id,
|
||||||
|
}])
|
||||||
|
self.assertEqual(user_admin.company.id, company.id)
|
||||||
|
|
||||||
(usd, euro) = self.prep_2nd_currency(company)
|
(usd, euro) = self.prep_2nd_currency(company)
|
||||||
sequ_id = self.prep_sequence().id
|
sequ_id = self.prep_sequence().id
|
||||||
category = self.prep_category(cattype='in')
|
category = self.prep_category(cattype='in')
|
||||||
|
@ -113,6 +124,52 @@ class ReportTestCase(CashbookTestCase):
|
||||||
self.assertEqual(books[2].balance, Decimal('23.0'))
|
self.assertEqual(books[2].balance, Decimal('23.0'))
|
||||||
return books
|
return books
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_report_currency_hasbookings(self):
|
||||||
|
""" check detectpn of bookings @ currency
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Currency = pool.get('currency.currency')
|
||||||
|
Lines = pool.get('cashbook.line')
|
||||||
|
|
||||||
|
books = self.prep_report_3books()
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
with Transaction().set_context({
|
||||||
|
'company': company.id,
|
||||||
|
}):
|
||||||
|
self.assertEqual(len(books[0].lines), 2)
|
||||||
|
self.assertEqual(books[0].currency.code, 'usd')
|
||||||
|
self.assertEqual(len(books[1].lines), 2)
|
||||||
|
self.assertEqual(books[1].currency.code, 'usd')
|
||||||
|
self.assertEqual(len(books[2].lines), 2)
|
||||||
|
self.assertEqual(books[2].currency.code, 'EUR')
|
||||||
|
|
||||||
|
euro, = Currency.search([('code', '=', 'EUR')])
|
||||||
|
self.assertEqual(euro.cashbook_hasbookings, True)
|
||||||
|
self.assertEqual(Currency.search_count([
|
||||||
|
('cashbook_hasbookings', '=', True)
|
||||||
|
]), 2)
|
||||||
|
|
||||||
|
Lines.delete(books[2].lines)
|
||||||
|
self.assertEqual(euro.cashbook_hasbookings, False)
|
||||||
|
|
||||||
|
self.assertEqual(Currency.search_count([
|
||||||
|
('cashbook_hasbookings', '=', True)
|
||||||
|
]), 1)
|
||||||
|
|
||||||
|
usd, = Currency.search([('code', '=', 'usd')])
|
||||||
|
self.assertEqual(usd.cashbook_hasbookings, True)
|
||||||
|
|
||||||
|
Lines.delete(books[0].lines)
|
||||||
|
self.assertEqual(usd.cashbook_hasbookings, True)
|
||||||
|
Lines.delete(books[1].lines)
|
||||||
|
self.assertEqual(usd.cashbook_hasbookings, False)
|
||||||
|
|
||||||
|
self.assertEqual(Currency.search_count([
|
||||||
|
('cashbook_hasbookings', '=', True)
|
||||||
|
]), 0)
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_report_dtype_update(self):
|
def test_report_dtype_update(self):
|
||||||
""" check unlink of cashbooks/types/currenciews
|
""" check unlink of cashbooks/types/currenciews
|
||||||
|
|
Loading…
Reference in a new issue