add: field 'asset_gainloss' + searcher + test +todos
This commit is contained in:
parent
5aad26da71
commit
9287db67ed
3 changed files with 125 additions and 14 deletions
|
@ -292,4 +292,83 @@ class YieldTestCase(ModuleTestCase):
|
|||
self.assertEqual(lines[0].rec_name,
|
||||
'05/01/2022|Rev/Sp|7.00 usd|Dividend [-]|0.0000 u')
|
||||
|
||||
# add counter-account for profit or loss of
|
||||
# depot-account
|
||||
book_gainloss, = Cashbook.create([{
|
||||
'name': 'Profit-Loss',
|
||||
'btype': type_cash.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
}])
|
||||
|
||||
# sale all shares with profit and fee
|
||||
# buy: 23.50
|
||||
# sale: 32.90 (+40%)
|
||||
# fee: 2.50
|
||||
# asset (buy amount): 23.50
|
||||
# booking: asset -> cash: - 30.40
|
||||
# asset -> (category) fee: - 2.50
|
||||
# asset <- gain-loss: 9.40
|
||||
# -------
|
||||
# 0.00
|
||||
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
||||
self.assertEqual(book_gainloss.rec_name, 'Profit-Loss | 0.00 usd | Open')
|
||||
lines = Line.create([{
|
||||
'cashbook': book_asset.id,
|
||||
'date': date(2022, 5, 2),
|
||||
'bookingtype': 'spout',
|
||||
'description': 'all out',
|
||||
'splitlines': [('create', [{
|
||||
'splittype': 'tr',
|
||||
'booktransf': book_cash.id,
|
||||
'description': 'sale with 40% profit',
|
||||
'quantity': Decimal('3.0'),
|
||||
'amount': Decimal('30.4'),
|
||||
}, {
|
||||
'splittype': 'cat',
|
||||
'description': 'trade fee',
|
||||
'category': as_cfg.fee_category.id,
|
||||
'amount': Decimal('2.5'),
|
||||
'quantity': Decimal('0.0'),
|
||||
}, {
|
||||
'splittype': 'tr',
|
||||
'booktransf': book_gainloss.id,
|
||||
'description': 'profit of sale',
|
||||
'amount': Decimal('-9.4'),
|
||||
'quantity': Decimal('0.0'),
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(len(lines), 1)
|
||||
self.assertEqual(lines[0].rec_name,
|
||||
'05/02/2022|Exp/Sp|-23.50 usd|all out [-]|-3.0000 u')
|
||||
Line.wfcheck(lines)
|
||||
|
||||
self.assertEqual(lines[0].rec_name,
|
||||
'05/02/2022|Exp/Sp|-23.50 usd|all out [-]|-3.0000 u')
|
||||
self.assertEqual(len(lines[0].splitlines), 3)
|
||||
self.assertEqual(lines[0].splitlines[0].rec_name,
|
||||
'Exp/Sp|30.40 usd|sale with 40% profit [Cash | 22.90 usd | Open]|3.0000 u')
|
||||
self.assertEqual(lines[0].splitlines[1].rec_name,
|
||||
'Exp/Sp|2.50 usd|trade fee [Fee]|0.0000 u')
|
||||
self.assertEqual(lines[0].splitlines[2].rec_name,
|
||||
'Exp/Sp|-9.40 usd|profit of sale [Profit-Loss | -9.40 usd | Open]|0.0000 u')
|
||||
|
||||
print('\n# line:', lines[0].asset_gainloss, lines[0].asset_dividend, lines[0].trade_fee)
|
||||
self.assertEqual(lines[0].asset_gainloss, Decimal('0.0'))
|
||||
self.assertEqual(lines[0].asset_dividend, Decimal('0.0'))
|
||||
self.assertEqual(lines[0].trade_fee, Decimal('0.0'))
|
||||
|
||||
self.assertEqual(book_asset.rec_name, 'Depot | 0.00 usd | Open | 0.0000 u')
|
||||
# negative amount on profit/loss-account means success
|
||||
self.assertEqual(book_gainloss.rec_name, 'Profit-Loss | -9.40 usd | Open')
|
||||
|
||||
# check searcher
|
||||
lines = Line.search([('asset_gainloss', '=', Decimal('-9.4'))])
|
||||
self.assertEqual(len(lines), 1)
|
||||
self.assertEqual(lines[0].rec_name,
|
||||
'Exp/Sp|-9.40 usd|profit of sale [Profit-Loss | -9.40 usd | Open]|0.0000 u')
|
||||
|
||||
# end YieldTestCase
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue