diff --git a/line.py b/line.py index 80987c7..b8c1c99 100644 --- a/line.py +++ b/line.py @@ -289,8 +289,8 @@ class Line(SecondUomMixin, metaclass=PoolMeta): # transfer = fee is positive tab_mv_spline_fee.amount, Case( - (tab_line.bookingtype == 'spin', tab_spline_fee.amount), - (tab_line.bookingtype == 'spout', tab_spline_fee.amount * Decimal('-1.0')), + (tab_line.bookingtype == 'spin', tab_spline_fee.amount * Decimal('-1.0')), + (tab_line.bookingtype == 'spout', tab_spline_fee.amount), ), Decimal('0.0'), )).as_('fee'), diff --git a/tests/test_yield.py b/tests/test_yield.py index 28c2de9..0f41fe9 100644 --- a/tests/test_yield.py +++ b/tests/test_yield.py @@ -280,10 +280,10 @@ class YieldTestCase(ModuleTestCase): # 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].trade_fee, Decimal('1.5')) self.assertEqual(book_asset.lines[5].asset_dividend, Decimal('0.0')) - lines = Line.search([('trade_fee', '=', Decimal('-1.5'))]) + 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') @@ -294,7 +294,7 @@ class YieldTestCase(ModuleTestCase): '05/01/2022|Rev/Sp|7.00 usd|Dividend [-]|0.0000 u') @with_transaction() - def test_yield_category_fee_in_out(self): + def test_yield_fee_category_in_out(self): """ check out-booking, category in/out """ pool = Pool() @@ -361,8 +361,8 @@ class YieldTestCase(ModuleTestCase): self.assertEqual(book_asset.rec_name, 'Depot | 19.50 usd | Open | 3.0000 u') @with_transaction() - def test_yield_transfer_from_splitbooking_fee_in_out(self): - """ check out-booking, transfer to/from asset-cashbook, + def test_yield_fee_transfer_from_splitbooking_cash_out(self): + """ check out-booking, transfer from cash --> asset, fee on counterpart of splitbooking """ pool = Pool() @@ -460,6 +460,107 @@ class YieldTestCase(ModuleTestCase): self.assertEqual(book_asset.lines[0].asset_dividend, Decimal('0.0')) self.assertEqual(book_asset.lines[0].trade_fee, Decimal('3.0')) + @with_transaction() + def test_yield_fee_transfer_from_splitbooking_asset_out(self): + """ check out-booking, transfer from asset --> cash, + fee 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') + + 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': as_cfg.dividend_category.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': 'spout', + 'date': date(2022, 5, 2), + 'description': 'sell shares, fee', + 'splitlines': [('create', [{ + 'splittype': 'tr', + 'booktransf': book_cash.id, + 'description': 'sell shares', + 'quantity': Decimal('1.0'), + 'amount': Decimal('20.0'), + }, { + 'splittype': 'cat', + 'category': as_cfg.fee_category.id, + 'description': 'trade fee', + 'amount': Decimal('3.0'), + 'quantity': Decimal('0.0'), + }])], + }])], + }]) + + Line.wfcheck(book_asset.lines) + + self.assertEqual(book_asset.rec_name, 'Depot | 0.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/01/2022|Rev|23.50 usd|Initial [Dividend]|3.0000 u') + self.assertEqual(book_asset.lines[1].rec_name, + '05/02/2022|Exp/Sp|-23.00 usd|sell shares, fee [-]|-1.0000 u') + self.assertEqual(book_cash.lines[0].rec_name, + '05/02/2022|from|20.00 usd|sell shares [Depot | 0.50 usd | Open | 2.0000 u]') + + self.assertEqual(book_asset.lines[1].asset_gainloss, 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')) + @with_transaction() def test_yield_gainloss_spout(self): """ check out-booking, split with fee and profit (1) @@ -572,7 +673,7 @@ class YieldTestCase(ModuleTestCase): self.assertEqual(lines[0].asset_gainloss, Decimal('9.4')) self.assertEqual(lines[0].asset_dividend, Decimal('0.0')) - self.assertEqual(lines[0].trade_fee, Decimal('-2.5')) + self.assertEqual(lines[0].trade_fee, Decimal('2.5')) self.assertEqual(book_asset.rec_name, 'Depot | 0.00 usd | Open | 0.0000 u') # negative amount on profit/loss-account means success