add: query for gain/loss
This commit is contained in:
parent
3243ccc471
commit
a1ede23740
1 changed files with 56 additions and 6 deletions
62
line.py
62
line.py
|
@ -123,12 +123,62 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
|||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'get_yield_data', searcher='search_asset_dividend')
|
||||
# ~ asset_gainloss = fields.Function(fields.Numeric(string='Profit/Loss',
|
||||
# ~ readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
# ~ states = {
|
||||
# ~ 'invisible': Eval('feature', '') != 'asset',
|
||||
# ~ }, depends=['currency_digits', 'feature']),
|
||||
# ~ 'get_yield_data')
|
||||
asset_gainloss = fields.Function(fields.Numeric(string='Profit/Loss',
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
states = {
|
||||
'invisible': Eval('feature', '') != 'asset',
|
||||
}, depends=['currency_digits', 'feature']),
|
||||
'get_gainloss_data')
|
||||
|
||||
@classmethod
|
||||
def get_gainloss_data_sql(cls):
|
||||
""" query for gain/loss on sell of shares
|
||||
"""
|
||||
pool = Pool()
|
||||
AssetSetting = pool.get('cashbook.assetconf')
|
||||
SplitLine = pool.get('cashbook.split')
|
||||
tab_line = cls.__table__()
|
||||
tab_mv_counterpart1 = cls.__table__()
|
||||
tab_mv_counterpart2 = cls.__table__()
|
||||
tab_mv_spline = SplitLine.__table__()
|
||||
|
||||
cfg1 = AssetSetting.get_singleton()
|
||||
|
||||
tab_assetline = cls.search([
|
||||
('cashbook.btype.feature', '=', 'asset'),
|
||||
], query=True)
|
||||
|
||||
query = tab_line.join(tab_assetline,
|
||||
condition=(tab_assetline.id==tab_line.id),
|
||||
).join(tab_mv_counterpart1,
|
||||
# [MV] transfer booking, select counterpart [1] - a split-booking
|
||||
condition=tab_line.bookingtype.in_(['mvin', 'mvout']) & \
|
||||
((tab_line.reference == tab_mv_counterpart1.id) | \
|
||||
(tab_line.id == tab_mv_counterpart1.reference)) & \
|
||||
(tab_mv_counterpart1.bookingtype.in_(['spin', 'spout'])),
|
||||
type_ = 'LEFT OUTER',
|
||||
).join(tab_mv_spline,
|
||||
# [MV] fee-line is linked to split-booking-line of counterpart [1]
|
||||
condition=(tab_mv_spline.line == tab_mv_counterpart1.id) & \
|
||||
(tab_mv_spline.splittype == 'tr') & \
|
||||
(tab_mv_spline.booktransf != None) & \
|
||||
(tab_mv_spline.booktransf == getattr(cfg1.gainloss_book, 'id', None)),
|
||||
type_ = 'LEFT OUTER',
|
||||
).join(tab_mv_counterpart2,
|
||||
condition=tab_line.bookingtype.in_(['mvin', 'mvout']) & \
|
||||
((tab_mv_counterpart2.reference == tab_line.id) | \
|
||||
(tab_mv_counterpart2.id == tab_line.reference))
|
||||
).select(
|
||||
tab_line.id,
|
||||
Coalesce(
|
||||
tab_mv_counterpart2.credit - tab_mv_counterpart2.debit,
|
||||
Case(
|
||||
(tab_line.bookingtype == 'spin', tab_mv_spline.amount),
|
||||
(tab_line.bookingtype == 'spout', tab_mv_spline.amount * Decimal('-1.0')),
|
||||
),
|
||||
).as_('gainloss'),
|
||||
)
|
||||
return (tab_line, query)
|
||||
|
||||
@classmethod
|
||||
def get_yield_data_sql(cls):
|
||||
|
|
Loading…
Reference in a new issue