From 565c593718c410067ce57c910e0eb2132d0c08ed Mon Sep 17 00:00:00 2001 From: Francisco Jose Cubero Sanchez Date: Mon, 25 May 2020 17:32:56 +0200 Subject: [PATCH] chenges in get_stats_investment_generation to fit results --- som_generationkwh/investment.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/som_generationkwh/investment.py b/som_generationkwh/investment.py index f5ca8fc7..fe32f0bc 100644 --- a/som_generationkwh/investment.py +++ b/som_generationkwh/investment.py @@ -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 """ @@ -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