add sorting
This commit is contained in:
parent
c38737076f
commit
728b2fa6c2
2 changed files with 136 additions and 7 deletions
124
book.py
124
book.py
|
@ -136,41 +136,48 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
string='Dividend', help='Total dividends received',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_dividend_12m = fields.Function(fields.Numeric(
|
||||
string='Dividend 1y',
|
||||
help='Dividends received in the last twelve months',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_fee_total = fields.Function(fields.Numeric(
|
||||
string='Trade Fee', help='Total trade fees payed',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_fee_12m = fields.Function(fields.Numeric(
|
||||
string='Trade Fee 1y',
|
||||
help='Trade fees payed in the last twelve month',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_sales = fields.Function(fields.Numeric(
|
||||
string='Sales', help='Total profit or loss on sale of shares.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_sales_12m = fields.Function(fields.Numeric(
|
||||
string='Sales 1y',
|
||||
help='Total profit or loss on sale of shares in the last twelve month.',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'get_yield_data')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_quantity')
|
||||
yield_balance = fields.Function(fields.Numeric(
|
||||
string='Total Yield',
|
||||
help='Total income: price gain + dividends + sales gains - fees',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states={'invisible': Eval('feature', '') != 'asset'},
|
||||
depends=['currency_digits', 'feature']), 'on_change_with_yield_balance')
|
||||
depends=['currency_digits', 'feature']),
|
||||
'on_change_with_yield_balance', searcher='search_asset_quantity')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -208,6 +215,109 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
}
|
||||
return recname
|
||||
|
||||
@classmethod
|
||||
def work_order_assets(cls, tables, field_name):
|
||||
""" get order-query
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
|
||||
if 'date' in Transaction().context:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_nosearch_with_date',
|
||||
fname=field_name, model=Book2.__name__))
|
||||
return Book2.work_order_balance(tables, field_name)
|
||||
|
||||
@staticmethod
|
||||
def order_current_value(tables):
|
||||
""" order by current_value
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'current_value')
|
||||
|
||||
@staticmethod
|
||||
def order_purchase_amount(tables):
|
||||
""" order by purchase_amount
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'purchase_amount')
|
||||
|
||||
@staticmethod
|
||||
def order_diff_amount(tables):
|
||||
""" order by diff_amount
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'diff_amount')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_balance(tables):
|
||||
""" order by yield_balance
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_balance')
|
||||
|
||||
@staticmethod
|
||||
def order_diff_percent(tables):
|
||||
""" order by diff_percent
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'diff_percent')
|
||||
|
||||
@staticmethod
|
||||
def order_quantity(tables):
|
||||
""" order by quantity
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'quantity')
|
||||
|
||||
@staticmethod
|
||||
def order_quantity_all(tables):
|
||||
""" order by quantity_all
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'quantity_all')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_sales(tables):
|
||||
""" order by yield_sales
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_sales')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_sales_12m(tables):
|
||||
""" order by yield_sales_12m
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_sales_12m')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_dividend_total(tables):
|
||||
""" order by yield_dividend_total
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_dividend_total')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_dividend_12m(tables):
|
||||
""" order by yield_dividend_12m
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_dividend_12m')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_fee_total(tables):
|
||||
""" order by yield_fee_total
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_fee_total')
|
||||
|
||||
@staticmethod
|
||||
def order_yield_fee_12m(tables):
|
||||
""" order by yield_fee_12m
|
||||
"""
|
||||
Book2 = Pool().get('cashbook.book')
|
||||
return Book2.work_order_assets(tables, 'yield_fee_12m')
|
||||
|
||||
@fields.depends('asset', 'quantity_uom')
|
||||
def on_change_asset(self):
|
||||
""" get uom from asset
|
||||
|
|
|
@ -48,6 +48,25 @@ class CbInvTestCase(object):
|
|||
self.assertEqual(book.quantity_digits, 4)
|
||||
self.assertEqual(book.show_performance, True)
|
||||
|
||||
# run sorter
|
||||
books = Book.search(
|
||||
[],
|
||||
order=[
|
||||
('current_value', 'ASC'),
|
||||
('purchase_amount', 'ASC'),
|
||||
('diff_amount', 'ASC'),
|
||||
('yield_balance', 'ASC'),
|
||||
('diff_percent', 'ASC'),
|
||||
('quantity', 'ASC'),
|
||||
('quantity_all', 'ASC'),
|
||||
('yield_sales', 'ASC'),
|
||||
('yield_sales_12m', 'ASC'),
|
||||
('yield_dividend_total', 'ASC'),
|
||||
('yield_dividend_12m', 'ASC'),
|
||||
('yield_fee_total', 'ASC'),
|
||||
('yield_fee_12m', 'ASC'),
|
||||
])
|
||||
|
||||
@with_transaction()
|
||||
def test_assetbook_aggregated_values(self):
|
||||
""" create cashbooks with hierarchy, add lines,
|
||||
|
|
Loading…
Reference in a new issue