Skip to content

Commit

Permalink
Move get_stats_investment_generation and remove select
Browse files Browse the repository at this point in the history
  • Loading branch information
MariteSomEnergia committed May 25, 2020
1 parent 3a98225 commit 75499ba
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions som_generationkwh/investment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,29 @@ def error(message):

return invoice_id, errors

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
'amount': Total investment in Generation without amortizations}
params: No params
"""

result = []

if not context:
context = {}

socis_ids = self.search(cursor, uid, [('emission_id.type', '=', 'genkwh'), ('last_effective_date', '=', False)])
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,
'socis': n_socis})
return result

class InvestmentProvider(ErpWrapper):

def items(self, member=None, start=None, end=None):
Expand Down

0 comments on commit 75499ba

Please sign in to comment.