line/splitline: fremdwährung ok+test+migration
This commit is contained in:
parent
0f6180ebdb
commit
25dcdde09b
10 changed files with 485 additions and 217 deletions
|
@ -70,6 +70,7 @@ class BookTestCase(ModuleTestCase):
|
|||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
category = self.prep_category(cattype='in')
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
party = self.prep_party()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -84,6 +85,7 @@ class BookTestCase(ModuleTestCase):
|
|||
'bookingtype': 'in',
|
||||
'category': category.id,
|
||||
'amount': Decimal('10.0'),
|
||||
'party': party.id,
|
||||
}])],
|
||||
}])
|
||||
|
||||
|
@ -118,6 +120,7 @@ class BookTestCase(ModuleTestCase):
|
|||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
category = self.prep_category(cattype='in')
|
||||
self.assertEqual(company.currency.rec_name, 'Euro')
|
||||
party = self.prep_party()
|
||||
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
|
@ -136,6 +139,7 @@ class BookTestCase(ModuleTestCase):
|
|||
'bookingtype': 'in',
|
||||
'category': category.id,
|
||||
'amount': Decimal('10.0'),
|
||||
'party': party.id,
|
||||
}])],
|
||||
}])],
|
||||
}])
|
||||
|
|
|
@ -156,6 +156,71 @@ class LineTestCase(ModuleTestCase):
|
|||
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('10.5'))
|
||||
self.assertEqual(books[0].lines[0].amount, Decimal('12.0'))
|
||||
|
||||
@with_transaction()
|
||||
def test_line_check_migrate_amount_2nd_currency(self):
|
||||
""" create cashbook, lines, transfer
|
||||
check migration
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Lines = pool.get('cashbook.line')
|
||||
tab_line = Lines.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
types = self.prep_type()
|
||||
company = self.prep_company()
|
||||
|
||||
# add EURO, set company-currency to EURO
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
|
||||
books = Book.create([{
|
||||
'name': 'Book USD',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}, {
|
||||
'name': 'Book EURO',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}])
|
||||
self.assertEqual(len(books), 2)
|
||||
self.assertEqual(books[0].rec_name, 'Book USD | 0.00 usd | Open')
|
||||
self.assertEqual(books[1].rec_name, 'Book EURO | 0.00 € | Open')
|
||||
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 5),
|
||||
'description': 'Transfer USD --> EUR',
|
||||
'bookingtype': 'mvout',
|
||||
'amount': Decimal('10.0'),
|
||||
'booktransf': books[1].id,
|
||||
}])],
|
||||
}])
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
self.assertEqual(books[0].lines[0].rec_name,
|
||||
'05/05/2022|to|-10.00 usd|Transfer USD --> EUR [Book EURO | 0.00 € | Open]')
|
||||
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.52'))
|
||||
|
||||
# clear field 'amount_2nd_currency' to prepare for migration
|
||||
clear_field = tab_line.update(
|
||||
columns = [tab_line.amount_2nd_currency],
|
||||
values = [None],
|
||||
where = (tab_line.id == books[0].lines[0].id),
|
||||
)
|
||||
cursor.execute(*clear_field)
|
||||
|
||||
# migrate
|
||||
Lines.migrate_amount_2nd_currency()
|
||||
self.assertEqual(books[0].lines[0].amount_2nd_currency, Decimal('9.52'))
|
||||
|
||||
@with_transaction()
|
||||
def test_line_check_transfer_2nd_currency_out(self):
|
||||
""" create cashbook, lines, transfer amount between
|
||||
|
|
|
@ -106,6 +106,103 @@ class SplitLineTestCase(ModuleTestCase):
|
|||
self.assertEqual(len(books[0].lines[0].references), 0)
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_splitline_category_and_transfer_2ndcurrency(self):
|
||||
""" add book, line, two split-lines,
|
||||
category + transfer, target-cashbook in USD
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Line = pool.get('cashbook.line')
|
||||
|
||||
types = self.prep_type()
|
||||
category1 = self.prep_category(cattype='out')
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
(usd, euro) = self.prep_2nd_currency(company)
|
||||
|
||||
books = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': euro.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category1.id,
|
||||
'bookingtype': 'out',
|
||||
'amount': Decimal('1.0'),
|
||||
'party': party.id,
|
||||
}])],
|
||||
}, {
|
||||
'name': 'Book 2',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': usd.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}])
|
||||
self.assertEqual(books[0].rec_name, 'Book 1 | -1.00 € | Open')
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Exp|-1.00 €|Text 1 [Cat1]')
|
||||
self.assertEqual(books[1].rec_name, 'Book 2 | 0.00 usd | Open')
|
||||
|
||||
# EUR --> USD
|
||||
Book.write(*[
|
||||
[books[0]],
|
||||
{
|
||||
'lines': [('write', [books[0].lines[0]], {
|
||||
'bookingtype': 'spout',
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'splittype': 'cat',
|
||||
'description': 'to category',
|
||||
'category': category1.id,
|
||||
}, {
|
||||
'amount': Decimal('6.0'),
|
||||
'splittype': 'tr',
|
||||
'description': 'to book2',
|
||||
'booktransf': books[1].id,
|
||||
}])],
|
||||
})]
|
||||
}])
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].rec_name, '05/01/2022|Exp/Sp|-11.00 €|Text 1 [-]')
|
||||
self.assertEqual(books[0].lines[0].category, None)
|
||||
self.assertEqual(len(books[0].lines[0].splitlines), 2)
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|5.00 €|to category [Cat1]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[0].amount_2nd_currency, None)
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|6.00 €|to book2 [Book 2 | 0.00 usd | Open]')
|
||||
self.assertEqual(books[0].lines[0].splitlines[1].amount_2nd_currency, Decimal('6.3'))
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
# wf: edit -> check
|
||||
Line.wfcheck(books[0].lines)
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(books[0].lines[0].state, 'check')
|
||||
self.assertEqual(books[0].lines[0].number, '1')
|
||||
self.assertEqual(len(books[0].lines[0].references), 1)
|
||||
self.assertEqual(books[0].lines[0].references[0].rec_name,
|
||||
'05/01/2022|from|6.30 usd|to book2 [Book 1 | -11.00 € | Open]')
|
||||
|
||||
self.assertEqual(len(books[1].lines), 1)
|
||||
self.assertEqual(books[1].lines[0].reference.rec_name,
|
||||
'05/01/2022|Exp/Sp|-11.00 €|Text 1 [-]')
|
||||
self.assertEqual(books[1].lines[0].rec_name,
|
||||
'05/01/2022|from|6.30 usd|to book2 [Book 1 | -11.00 € | Open]')
|
||||
self.assertEqual(books[1].lines[0].amount, Decimal('6.3'))
|
||||
self.assertEqual(books[1].lines[0].amount_2nd_currency, Decimal('6.0'))
|
||||
|
||||
# wf: check --> edit
|
||||
Line.wfedit(books[0].lines)
|
||||
self.assertEqual(len(books[0].lines), 1)
|
||||
self.assertEqual(len(books[0].lines[0].references), 0)
|
||||
self.assertEqual(len(books[1].lines), 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_splitline_check_clear_by_bookingtype(self):
|
||||
""" add book, line, category, set line to 'in',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue