line: tests... ok
This commit is contained in:
parent
9f22341005
commit
0c60a8c313
1 changed files with 349 additions and 203 deletions
|
@ -91,208 +91,6 @@ class YieldTestCase(ModuleTestCase):
|
||||||
self.assertEqual(as_cfg.dividend_category.rec_name, 'Dividend')
|
self.assertEqual(as_cfg.dividend_category.rec_name, 'Dividend')
|
||||||
self.assertEqual(as_cfg.gainloss_book.rec_name, 'GainLoss | 0.00 usd | Open')
|
self.assertEqual(as_cfg.gainloss_book.rec_name, 'GainLoss | 0.00 usd | Open')
|
||||||
|
|
||||||
@with_transaction()
|
|
||||||
def test_yield_fee_dividend_gainloss(self):
|
|
||||||
""" add cashbook, categories, bookings for
|
|
||||||
fees, dididend...
|
|
||||||
"""
|
|
||||||
pool = Pool()
|
|
||||||
Cashbook = pool.get('cashbook.book')
|
|
||||||
BType = pool.get('cashbook.type')
|
|
||||||
Category = pool.get('cashbook.category')
|
|
||||||
Line = pool.get('cashbook.line')
|
|
||||||
|
|
||||||
company = self.prep_company()
|
|
||||||
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
|
||||||
|
|
||||||
type_depot = self.prep_type('Depot', 'D')
|
|
||||||
type_cash = self.prep_type('Cash', 'C')
|
|
||||||
BType.write(*[
|
|
||||||
[type_depot],
|
|
||||||
{
|
|
||||||
'feature': 'asset',
|
|
||||||
}])
|
|
||||||
|
|
||||||
asset = self.prep_asset_item(
|
|
||||||
company=company,
|
|
||||||
product = self.prep_asset_product(name='Product 1'))
|
|
||||||
self.assertEqual(asset.symbol, 'usd/u')
|
|
||||||
|
|
||||||
category_office, = Category.create([{
|
|
||||||
'name': 'Office',
|
|
||||||
'company': company.id,
|
|
||||||
}])
|
|
||||||
|
|
||||||
book_asset, = Cashbook.create([{
|
|
||||||
'name': 'Depot',
|
|
||||||
'btype': type_depot.id,
|
|
||||||
'company': company.id,
|
|
||||||
'currency': company.currency.id,
|
|
||||||
'number_sequ': self.prep_sequence().id,
|
|
||||||
'asset': asset.id,
|
|
||||||
'quantity_uom': asset.uom.id,
|
|
||||||
'start_date': date(2022, 5, 1),
|
|
||||||
'lines': [('create', [{
|
|
||||||
'bookingtype': 'out', # [BK01]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'amount': Decimal('2.0'),
|
|
||||||
'quantity': Decimal('0.0'),
|
|
||||||
'category': as_cfg.fee_category.id,
|
|
||||||
'description': 'Fee',
|
|
||||||
}, {
|
|
||||||
'bookingtype': 'in', # [BK02]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'amount': Decimal('10.0'),
|
|
||||||
'quantity': Decimal('1.0'),
|
|
||||||
'category': as_cfg.dividend_category.id,
|
|
||||||
'description': 'reinvested dividend',
|
|
||||||
}, {
|
|
||||||
'bookingtype': 'spin', # [BK03]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'description': 'Dividend',
|
|
||||||
'splitlines': [('create', [{
|
|
||||||
'description': 'Dividend',
|
|
||||||
'splittype': 'cat',
|
|
||||||
'category': as_cfg.dividend_category.id,
|
|
||||||
'amount': Decimal('5.0'),
|
|
||||||
'quantity': Decimal('0.0'),
|
|
||||||
}, {
|
|
||||||
'description': 'Dividend (2)',
|
|
||||||
'splittype': 'cat',
|
|
||||||
'category': as_cfg.dividend_category.id,
|
|
||||||
'amount': Decimal('2.0'),
|
|
||||||
'quantity': Decimal('0.0'),
|
|
||||||
}])],
|
|
||||||
}, {
|
|
||||||
'bookingtype': 'spout', # [BK04]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'description': 'Fee',
|
|
||||||
'splitlines': [('create', [{
|
|
||||||
'description': 'Fee',
|
|
||||||
'splittype': 'cat',
|
|
||||||
'category': as_cfg.fee_category.id,
|
|
||||||
'amount': Decimal('1.5'),
|
|
||||||
'quantity': Decimal('0.0'),
|
|
||||||
}])],
|
|
||||||
}])],
|
|
||||||
}])
|
|
||||||
|
|
||||||
book_cash, = Cashbook.create([{
|
|
||||||
'name': 'Cash',
|
|
||||||
'btype': type_cash.id,
|
|
||||||
'company': company.id,
|
|
||||||
'currency': company.currency.id,
|
|
||||||
'number_sequ': self.prep_sequence().id,
|
|
||||||
'start_date': date(2022, 5, 1),
|
|
||||||
'lines': [('create', [{
|
|
||||||
# dividend, incoming + link to depot-account
|
|
||||||
'bookingtype': 'spin', # [BK05]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'description': 'Dividend',
|
|
||||||
'splitlines': [('create', [{
|
|
||||||
'description': 'Dividend',
|
|
||||||
'splittype': 'cat',
|
|
||||||
'category': as_cfg.dividend_category.id,
|
|
||||||
'amount': Decimal('5.0'),
|
|
||||||
}, {
|
|
||||||
'description': 'Dividend',
|
|
||||||
'splittype': 'tr',
|
|
||||||
'booktransf': book_asset.id,
|
|
||||||
'amount': Decimal('0.0'),
|
|
||||||
'quantity': Decimal('0.0'),
|
|
||||||
}])],
|
|
||||||
}, {
|
|
||||||
# buy shares with trade fee, outgoing + link to depot-account
|
|
||||||
'bookingtype': 'spout', # [BK06]
|
|
||||||
'date': date(2022, 5, 1),
|
|
||||||
'description': '2x shares, trade fee',
|
|
||||||
'splitlines': [('create', [{
|
|
||||||
'description': '2x Shares',
|
|
||||||
'splittype': 'tr',
|
|
||||||
'booktransf': book_asset.id,
|
|
||||||
'amount': Decimal('10.0'),
|
|
||||||
'quantity': Decimal('2.0'),
|
|
||||||
}, {
|
|
||||||
'description': 'Trade Fee',
|
|
||||||
'splittype': 'cat',
|
|
||||||
'category': as_cfg.fee_category.id,
|
|
||||||
'amount': Decimal('2.5'),
|
|
||||||
}])],
|
|
||||||
}])],
|
|
||||||
}])
|
|
||||||
self.assertEqual(len(book_cash.lines), 2)
|
|
||||||
Line.wfcheck(book_cash.lines)
|
|
||||||
|
|
||||||
self.assertEqual(book_cash.lines[0].rec_name,
|
|
||||||
'05/01/2022|Rev/Sp|5.00 usd|Dividend [-]')
|
|
||||||
self.assertEqual(book_cash.lines[0].reference, None)
|
|
||||||
self.assertEqual(len(book_cash.lines[0].references), 1)
|
|
||||||
self.assertEqual(book_cash.lines[0].references[0].rec_name,
|
|
||||||
'05/01/2022|to|0.00 usd|Dividend [Cash | -7.50 usd | Open]|0.0000 u')
|
|
||||||
|
|
||||||
self.assertEqual(book_cash.lines[1].rec_name,
|
|
||||||
'05/01/2022|Exp/Sp|-12.50 usd|2x shares, trade fee [-]')
|
|
||||||
self.assertEqual(book_cash.lines[1].reference, None)
|
|
||||||
self.assertEqual(len(book_cash.lines[1].references), 1)
|
|
||||||
self.assertEqual(book_cash.lines[1].references[0].rec_name,
|
|
||||||
'05/01/2022|from|10.00 usd|2x Shares [Cash | -7.50 usd | Open]|2.0000 u')
|
|
||||||
|
|
||||||
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
|
||||||
self.assertEqual(book_asset.btype.rec_name, 'D - Depot')
|
|
||||||
self.assertEqual(len(book_asset.lines), 6)
|
|
||||||
|
|
||||||
# reference to dividend (1) [BK05]
|
|
||||||
self.assertEqual(book_asset.lines[0].rec_name,
|
|
||||||
'05/01/2022|to|0.00 usd|Dividend [Cash | -7.50 usd | Open]|0.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[0].trade_fee, Decimal('0.0'))
|
|
||||||
self.assertEqual(book_asset.lines[0].asset_dividend, Decimal('5.0'))
|
|
||||||
self.assertEqual(book_asset.lines[0].reference.rec_name,
|
|
||||||
'05/01/2022|Rev/Sp|5.00 usd|Dividend [-]')
|
|
||||||
self.assertEqual(len(book_asset.lines[0].references), 0)
|
|
||||||
|
|
||||||
# reference to fee [BK06]
|
|
||||||
self.assertEqual(book_asset.lines[1].rec_name,
|
|
||||||
'05/01/2022|from|10.00 usd|2x Shares [Cash | -7.50 usd | Open]|2.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[1].trade_fee, Decimal('2.5'))
|
|
||||||
self.assertEqual(book_asset.lines[1].asset_dividend, Decimal('0.0'))
|
|
||||||
self.assertEqual(book_asset.lines[1].reference.rec_name,
|
|
||||||
'05/01/2022|Exp/Sp|-12.50 usd|2x shares, trade fee [-]')
|
|
||||||
self.assertEqual(len(book_asset.lines[1].references), 0)
|
|
||||||
|
|
||||||
# fee payed from asset-account [BK01]
|
|
||||||
self.assertEqual(book_asset.lines[2].rec_name,
|
|
||||||
'05/01/2022|Exp|-2.00 usd|Fee [Fee]|0.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[2].trade_fee, Decimal('2.0'))
|
|
||||||
self.assertEqual(book_asset.lines[2].asset_dividend, Decimal('0.0'))
|
|
||||||
|
|
||||||
# dividend (2) added to asset-account [BK02]
|
|
||||||
self.assertEqual(book_asset.lines[3].rec_name,
|
|
||||||
'05/01/2022|Rev|10.00 usd|reinvested dividend [Dividend]|1.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[3].trade_fee, Decimal('0.0'))
|
|
||||||
self.assertEqual(book_asset.lines[3].asset_dividend, Decimal('10.0'))
|
|
||||||
|
|
||||||
# dividend as split.booking on asset-account, two lines [BK03]
|
|
||||||
self.assertEqual(book_asset.lines[4].rec_name,
|
|
||||||
'05/01/2022|Rev/Sp|7.00 usd|Dividend [-]|0.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[4].trade_fee, Decimal('0.0'))
|
|
||||||
self.assertEqual(book_asset.lines[4].asset_dividend, Decimal('7.0'))
|
|
||||||
|
|
||||||
# fee as split.booking on asset-account [BK04]
|
|
||||||
self.assertEqual(book_asset.lines[5].rec_name,
|
|
||||||
'05/01/2022|Exp/Sp|-1.50 usd|Fee [-]|0.0000 u')
|
|
||||||
self.assertEqual(book_asset.lines[5].trade_fee, Decimal('1.5'))
|
|
||||||
self.assertEqual(book_asset.lines[5].asset_dividend, Decimal('0.0'))
|
|
||||||
|
|
||||||
lines = Line.search([('trade_fee', '=', Decimal('1.5'))])
|
|
||||||
self.assertEqual(len(lines), 1)
|
|
||||||
self.assertEqual(lines[0].rec_name,
|
|
||||||
'05/01/2022|Exp/Sp|-1.50 usd|Fee [-]|0.0000 u')
|
|
||||||
|
|
||||||
lines = Line.search([('asset_dividend', '=', Decimal('7.0'))])
|
|
||||||
self.assertEqual(len(lines), 1)
|
|
||||||
self.assertEqual(lines[0].rec_name,
|
|
||||||
'05/01/2022|Rev/Sp|7.00 usd|Dividend [-]|0.0000 u')
|
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_yield_fee_category_in_out(self):
|
def test_yield_fee_category_in_out(self):
|
||||||
""" check out-booking, category in/out
|
""" check out-booking, category in/out
|
||||||
|
@ -307,7 +105,6 @@ class YieldTestCase(ModuleTestCase):
|
||||||
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
||||||
|
|
||||||
type_depot = self.prep_type('Depot', 'D')
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
type_cash = self.prep_type('Cash', 'C')
|
|
||||||
BType.write(*[
|
BType.write(*[
|
||||||
[type_depot],
|
[type_depot],
|
||||||
{
|
{
|
||||||
|
@ -561,6 +358,355 @@ class YieldTestCase(ModuleTestCase):
|
||||||
self.assertEqual(book_asset.lines[1].asset_dividend, Decimal('0.0'))
|
self.assertEqual(book_asset.lines[1].asset_dividend, Decimal('0.0'))
|
||||||
self.assertEqual(book_asset.lines[1].trade_fee, Decimal('3.0'))
|
self.assertEqual(book_asset.lines[1].trade_fee, Decimal('3.0'))
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_yield_dividend_category_in(self):
|
||||||
|
""" check out-booking, dividend in/out
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Cashbook = pool.get('cashbook.book')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
Category = pool.get('cashbook.category')
|
||||||
|
Line = pool.get('cashbook.line')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
||||||
|
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
type_cash = self.prep_type('Cash', 'C')
|
||||||
|
category_in = self.prep_category(name='Income', cattype='in')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
|
||||||
|
asset = self.prep_asset_item(
|
||||||
|
company=company,
|
||||||
|
product = self.prep_asset_product(name='Product 1'))
|
||||||
|
self.assertEqual(asset.symbol, 'usd/u')
|
||||||
|
|
||||||
|
book_asset, = Cashbook.create([{
|
||||||
|
'name': 'Depot',
|
||||||
|
'btype': type_depot.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'amount': Decimal('23.50'),
|
||||||
|
'quantity': Decimal('3.0'),
|
||||||
|
'category': category_in.id,
|
||||||
|
'description': 'Initial',
|
||||||
|
}, ])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
||||||
|
lines = Line.create([{
|
||||||
|
'cashbook': book_asset.id,
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'description': 'dividend',
|
||||||
|
'category': as_cfg.dividend_category.id,
|
||||||
|
'amount': Decimal('4.0'),
|
||||||
|
'quantity': Decimal('0.0'),
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(len(lines), 1)
|
||||||
|
Line.wfcheck(lines)
|
||||||
|
|
||||||
|
self.assertEqual(lines[0].rec_name,
|
||||||
|
'05/02/2022|Rev|4.00 usd|dividend [Dividend]|0.0000 u')
|
||||||
|
|
||||||
|
self.assertEqual(lines[0].asset_gainloss, Decimal('0.0'))
|
||||||
|
self.assertEqual(lines[0].asset_dividend, Decimal('4.0'))
|
||||||
|
self.assertEqual(lines[0].trade_fee, Decimal('0.0'))
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 27.50 usd | Open | 3.0000 u')
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_yield_dividend_category_out(self):
|
||||||
|
""" check out-booking, dividend in/out
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Cashbook = pool.get('cashbook.book')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
Category = pool.get('cashbook.category')
|
||||||
|
Line = pool.get('cashbook.line')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
||||||
|
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
type_cash = self.prep_type('Cash', 'C')
|
||||||
|
category_in = self.prep_category(name='Income', cattype='in')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
|
||||||
|
asset = self.prep_asset_item(
|
||||||
|
company=company,
|
||||||
|
product = self.prep_asset_product(name='Product 1'))
|
||||||
|
self.assertEqual(asset.symbol, 'usd/u')
|
||||||
|
|
||||||
|
book_asset, = Cashbook.create([{
|
||||||
|
'name': 'Depot',
|
||||||
|
'btype': type_depot.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'amount': Decimal('23.50'),
|
||||||
|
'quantity': Decimal('3.0'),
|
||||||
|
'category': category_in.id,
|
||||||
|
'description': 'Initial',
|
||||||
|
}, ])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
Category.write(*[
|
||||||
|
[as_cfg.dividend_category],
|
||||||
|
{
|
||||||
|
'cattype': 'out',
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
||||||
|
lines = Line.create([{
|
||||||
|
'cashbook': book_asset.id,
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'bookingtype': 'out',
|
||||||
|
'description': 'dividend minus',
|
||||||
|
'category': as_cfg.dividend_category.id,
|
||||||
|
'amount': Decimal('4.0'),
|
||||||
|
'quantity': Decimal('0.0'),
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(len(lines), 1)
|
||||||
|
Line.wfcheck(lines)
|
||||||
|
|
||||||
|
self.assertEqual(lines[0].rec_name,
|
||||||
|
'05/02/2022|Exp|-4.00 usd|dividend minus [Dividend]|0.0000 u')
|
||||||
|
|
||||||
|
self.assertEqual(lines[0].asset_gainloss, Decimal('0.0'))
|
||||||
|
self.assertEqual(lines[0].asset_dividend, Decimal('-4.0'))
|
||||||
|
self.assertEqual(lines[0].trade_fee, Decimal('0.0'))
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 19.50 usd | Open | 3.0000 u')
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_yield_dividend_transfer_from_splitbooking_cash_out(self):
|
||||||
|
""" check out-booking, transfer from cash --> asset,
|
||||||
|
dividend on counterpart of splitbooking
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Cashbook = pool.get('cashbook.book')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
Category = pool.get('cashbook.category')
|
||||||
|
Line = pool.get('cashbook.line')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
||||||
|
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
type_cash = self.prep_type('Cash', 'C')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
|
||||||
|
asset = self.prep_asset_item(
|
||||||
|
company=company,
|
||||||
|
product = self.prep_asset_product(name='Product 1'))
|
||||||
|
self.assertEqual(asset.symbol, 'usd/u')
|
||||||
|
category_in = self.prep_category(name='Income', cattype='in')
|
||||||
|
|
||||||
|
book_cash, = Cashbook.create([{
|
||||||
|
'name': 'Cash',
|
||||||
|
'btype': type_cash.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
}])
|
||||||
|
|
||||||
|
book_asset, = Cashbook.create([{
|
||||||
|
'name': 'Depot',
|
||||||
|
'btype': type_depot.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'date': date(2022, 5, 1),
|
||||||
|
'amount': Decimal('23.50'),
|
||||||
|
'quantity': Decimal('3.0'),
|
||||||
|
'category': category_in.id,
|
||||||
|
'description': 'Initial',
|
||||||
|
}, ])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
||||||
|
self.assertEqual(len(book_asset.lines), 1)
|
||||||
|
self.assertEqual(book_cash.rec_name, 'Cash | 0.00 usd | Open')
|
||||||
|
self.assertEqual(len(book_cash.lines), 0)
|
||||||
|
|
||||||
|
Cashbook.write(*[
|
||||||
|
[book_cash],
|
||||||
|
{
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'spin',
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'description': 'buy shares, dividend',
|
||||||
|
'splitlines': [('create', [{
|
||||||
|
'splittype': 'tr',
|
||||||
|
'booktransf': book_asset.id,
|
||||||
|
'description': 'sell shares',
|
||||||
|
'quantity': Decimal('1.0'),
|
||||||
|
'amount': Decimal('10.0'),
|
||||||
|
}, {
|
||||||
|
'splittype': 'cat',
|
||||||
|
'category': as_cfg.dividend_category.id,
|
||||||
|
'description': 'dividend',
|
||||||
|
'amount': Decimal('10.0'),
|
||||||
|
}])],
|
||||||
|
}])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
Line.wfcheck(book_cash.lines)
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 13.50 usd | Open | 2.0000 u')
|
||||||
|
self.assertEqual(len(book_asset.lines), 2)
|
||||||
|
self.assertEqual(book_cash.rec_name, 'Cash | 20.00 usd | Open')
|
||||||
|
self.assertEqual(len(book_cash.lines), 1)
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.lines[0].rec_name,
|
||||||
|
'05/02/2022|to|-10.00 usd|sell shares [Cash | 20.00 usd | Open]|-1.0000 u')
|
||||||
|
self.assertEqual(book_asset.lines[1].rec_name,
|
||||||
|
'05/01/2022|Rev|23.50 usd|Initial [Income]|3.0000 u')
|
||||||
|
self.assertEqual(book_cash.lines[0].rec_name,
|
||||||
|
'05/02/2022|Rev/Sp|20.00 usd|buy shares, dividend [-]')
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.lines[0].asset_gainloss, Decimal('0.0'))
|
||||||
|
self.assertEqual(book_asset.lines[0].asset_dividend, Decimal('10.0'))
|
||||||
|
self.assertEqual(book_asset.lines[0].trade_fee, Decimal('0.0'))
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_yield_dividend_transfer_to_splitbooking_aset(self):
|
||||||
|
""" check out-booking, transfer from asset --> cash,
|
||||||
|
dividend on counterpart of splitbooking
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Cashbook = pool.get('cashbook.book')
|
||||||
|
BType = pool.get('cashbook.type')
|
||||||
|
Category = pool.get('cashbook.category')
|
||||||
|
Line = pool.get('cashbook.line')
|
||||||
|
|
||||||
|
company = self.prep_company()
|
||||||
|
as_cfg = self.prep_yield_config('Fee', 'Dividend', 'Profit-Loss', company)
|
||||||
|
|
||||||
|
type_depot = self.prep_type('Depot', 'D')
|
||||||
|
type_cash = self.prep_type('Cash', 'C')
|
||||||
|
BType.write(*[
|
||||||
|
[type_depot],
|
||||||
|
{
|
||||||
|
'feature': 'asset',
|
||||||
|
}])
|
||||||
|
|
||||||
|
asset = self.prep_asset_item(
|
||||||
|
company=company,
|
||||||
|
product = self.prep_asset_product(name='Product 1'))
|
||||||
|
self.assertEqual(asset.symbol, 'usd/u')
|
||||||
|
category_in = self.prep_category(name='Income', cattype='in')
|
||||||
|
|
||||||
|
book_cash, = Cashbook.create([{
|
||||||
|
'name': 'Cash',
|
||||||
|
'btype': type_cash.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
}])
|
||||||
|
|
||||||
|
book_asset, = Cashbook.create([{
|
||||||
|
'name': 'Depot',
|
||||||
|
'btype': type_depot.id,
|
||||||
|
'company': company.id,
|
||||||
|
'currency': company.currency.id,
|
||||||
|
'number_sequ': self.prep_sequence().id,
|
||||||
|
'asset': asset.id,
|
||||||
|
'quantity_uom': asset.uom.id,
|
||||||
|
'start_date': date(2022, 5, 1),
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'in',
|
||||||
|
'date': date(2022, 5, 1),
|
||||||
|
'amount': Decimal('23.50'),
|
||||||
|
'quantity': Decimal('3.0'),
|
||||||
|
'category': category_in.id,
|
||||||
|
'description': 'Initial',
|
||||||
|
}, ])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 23.50 usd | Open | 3.0000 u')
|
||||||
|
self.assertEqual(len(book_asset.lines), 1)
|
||||||
|
self.assertEqual(book_cash.rec_name, 'Cash | 0.00 usd | Open')
|
||||||
|
self.assertEqual(len(book_cash.lines), 0)
|
||||||
|
|
||||||
|
Cashbook.write(*[
|
||||||
|
[book_asset],
|
||||||
|
{
|
||||||
|
'lines': [('create', [{
|
||||||
|
'bookingtype': 'spin',
|
||||||
|
'date': date(2022, 5, 2),
|
||||||
|
'description': 'buy shares, dividend',
|
||||||
|
'splitlines': [('create', [{
|
||||||
|
'splittype': 'tr',
|
||||||
|
'booktransf': book_cash.id,
|
||||||
|
'description': 'buy shares',
|
||||||
|
'quantity': Decimal('1.0'),
|
||||||
|
'amount': Decimal('10.0'),
|
||||||
|
}, {
|
||||||
|
'splittype': 'cat',
|
||||||
|
'category': as_cfg.dividend_category.id,
|
||||||
|
'description': 'dividend',
|
||||||
|
'amount': Decimal('10.0'),
|
||||||
|
'quantity': Decimal('0.0'),
|
||||||
|
}])],
|
||||||
|
}])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
Line.wfcheck(book_asset.lines)
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.rec_name, 'Depot | 43.50 usd | Open | 4.0000 u')
|
||||||
|
self.assertEqual(len(book_asset.lines), 2)
|
||||||
|
self.assertEqual(book_cash.rec_name, 'Cash | -10.00 usd | Open')
|
||||||
|
self.assertEqual(len(book_cash.lines), 1)
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.lines[0].rec_name,
|
||||||
|
'05/01/2022|Rev|23.50 usd|Initial [Income]|3.0000 u')
|
||||||
|
self.assertEqual(book_asset.lines[1].rec_name,
|
||||||
|
'05/02/2022|Rev/Sp|20.00 usd|buy shares, dividend [-]|1.0000 u')
|
||||||
|
self.assertEqual(book_cash.lines[0].rec_name,
|
||||||
|
'05/02/2022|to|-10.00 usd|buy shares [Depot | 43.50 usd | Open | 4.0000 u]')
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.lines[0].asset_gainloss, Decimal('0.0'))
|
||||||
|
self.assertEqual(book_asset.lines[0].asset_dividend, Decimal('00.0'))
|
||||||
|
self.assertEqual(book_asset.lines[0].trade_fee, Decimal('0.0'))
|
||||||
|
|
||||||
|
self.assertEqual(book_asset.lines[1].asset_gainloss, Decimal('0.0'))
|
||||||
|
self.assertEqual(book_asset.lines[1].asset_dividend, Decimal('10.0'))
|
||||||
|
self.assertEqual(book_asset.lines[1].trade_fee, Decimal('0.0'))
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_yield_gainloss_spout(self):
|
def test_yield_gainloss_spout(self):
|
||||||
""" check out-booking, split with fee and profit (1)
|
""" check out-booking, split with fee and profit (1)
|
||||||
|
|
Loading…
Reference in a new issue