book: view zeigt in listansicht bei unterkonten in fremdwährung

den korrekten wert,
book-form: feld für saldo in unternehmens-währung
This commit is contained in:
Frederik Jaeckel 2022-10-02 15:04:10 +02:00
parent 4a7ee23e2c
commit 59dfb94bee
7 changed files with 238 additions and 13 deletions

View file

@ -56,6 +56,110 @@ class BookTestCase(ModuleTestCase):
self.assertEqual(book.state, 'open')
self.assertEqual(book.state_string, 'Open')
@with_transaction()
def test_book_create_2nd_currency(self):
""" create cashbook, in 2nd currency, check balance-fields
"""
pool = Pool()
Book = pool.get('cashbook.book')
types = self.prep_type()
company = self.prep_company()
# add EURO, set company-currency to EURO
(usd, euro) = self.prep_2nd_currency(company)
category = self.prep_category(cattype='in')
self.assertEqual(company.currency.rec_name, 'Euro')
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': usd.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 5),
'description': 'Amount in USD',
'bookingtype': 'in',
'category': category.id,
'amount': Decimal('10.0'),
}])],
}])
with Transaction().set_context({
'date': date(2022, 5, 5),
}):
self.assertEqual(book.rec_name, 'Book 1 | 10.00 usd | Open')
self.assertEqual(book.currency.rec_name, 'usd')
self.assertEqual(book.currency.rate, Decimal('1.05'))
self.assertEqual(book.company_currency.rec_name, 'Euro')
self.assertEqual(book.company_currency.rate, Decimal('1.0'))
self.assertEqual(book.balance, Decimal('10.0'))
self.assertEqual(book.balance_ref, Decimal('9.52'))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].rec_name,
'05/05/2022|Rev|10.00 usd|Amount in USD [Cat1]')
@with_transaction()
def test_book_create_2nd_currency_hierarchical(self):
""" create cashbook-hierarchy, in 2nd currency,
check balance-fields
"""
pool = Pool()
Book = pool.get('cashbook.book')
types = self.prep_type()
company = self.prep_company()
# add EURO, set company-currency to EURO
(usd, euro) = self.prep_2nd_currency(company)
category = self.prep_category(cattype='in')
self.assertEqual(company.currency.rec_name, 'Euro')
book, = Book.create([{
'name': 'Book 1',
'company': company.id,
'currency': euro.id,
'childs': [('create', [{
'name': 'Book 2',
'btype': types.id,
'company': company.id,
'currency': usd.id,
'number_sequ': self.prep_sequence().id,
'start_date': date(2022, 5, 1),
'lines': [('create', [{
'date': date(2022, 5, 5),
'description': 'Amount in USD',
'bookingtype': 'in',
'category': category.id,
'amount': Decimal('10.0'),
}])],
}])],
}])
with Transaction().set_context({
'date': date(2022, 5, 5),
}):
self.assertEqual(book.rec_name, 'Book 1')
self.assertEqual(book.currency.rec_name, 'Euro')
self.assertEqual(book.currency.rate, Decimal('1.0'))
self.assertEqual(book.company_currency, None)
self.assertEqual(book.balance, Decimal('9.52'))
self.assertEqual(book.balance_ref, None)
self.assertEqual(len(book.lines), 0)
self.assertEqual(len(book.childs), 1)
self.assertEqual(book.childs[0].rec_name, 'Book 1/Book 2 | 10.00 usd | Open')
self.assertEqual(book.childs[0].currency.rec_name, 'usd')
self.assertEqual(book.childs[0].currency.rate, Decimal('1.05'))
self.assertEqual(book.childs[0].company_currency.rec_name, 'Euro')
self.assertEqual(book.childs[0].balance, Decimal('10.0'))
self.assertEqual(book.childs[0].balance_ref, Decimal('9.52'))
self.assertEqual(len(book.childs[0].lines), 1)
@with_transaction()
def test_book_create_hierarchy(self):
""" create cashbook, hierarchical

View file

@ -98,6 +98,13 @@ class ConfigTestCase(ModuleTestCase):
'rate': Decimal('1.05'),
}])
# delete unwanted rates
usd_1 = CurrencyRate.search([
('currency.id', '=', usd.id),
('date', '!=', date(2022, 5, 2)),
])
CurrencyRate.delete(usd_1)
return (usd, euro)
@with_transaction()