Skip to content

Commit

Permalink
chenges in get_stats_investment_generation to fit results
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoCubero committed May 25, 2020
1 parent 2003440 commit 565c593
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions som_generationkwh/investment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,7 @@ def error(message):
def get_stats_investment_generation(self, cursor, uid, context=None):
"""
Returns a list of dict with investment GenerationKwh statistics:
res: {'account': account code
'socis': Number of 'socis' with Generation
res: {'socis': Number of 'socis' with Generation
'amount': Total investment in Generation without amortizations}
params: No params
"""
Expand All @@ -1997,12 +1996,34 @@ def get_stats_investment_generation(self, cursor, uid, context=None):
if not context:
context = {}

socis_ids = self.search(cursor, uid, [('emission_id.type', '=', 'genkwh'), ('last_effective_date', '=', False)])
if 'today' in context:
today = context['today']
else:
today = date.today().strftime('%Y-%m-%d')

active_inv_ids = self.search(cursor, uid, [
('emission_id.type', '=', 'genkwh'),
('last_effective_date', '>', today)
])

standby_inv_ids = self.search(cursor, uid, [
('emission_id.type', '=', 'genkwh'),
('last_effective_date', '=', None)
])

inv_ids = active_inv_ids + standby_inv_ids

shares_data = self.read(cursor, uid, inv_ids,[
'nshares',
'member_id',
])

socis_ids = [share_data['member_id'] for share_data in shares_data]
n_socis = len(set(socis_ids))
shares_data = self.read(cursor, uid, socis_ids, ['nshares'])
amount = sum([share_data['nshares'] for share_data in shares_data]) * 100

result.append({'amount': amount,
shares = sum([share_data['nshares'] for share_data in shares_data])

result.append({'amount': shares * 100,
'socis': n_socis})
return result

Expand Down

0 comments on commit 565c593

Please sign in to comment.