diff --git a/scripts/genkwh_investments.py b/scripts/genkwh_investments.py index a8b3c456..bfa8734d 100755 --- a/scripts/genkwh_investments.py +++ b/scripts/genkwh_investments.py @@ -187,13 +187,16 @@ def notify( "notify to members that have an investment going effective on the date" c = erp() if not effectiveon: - effectiveon = datetime.date.today() - investments = c.GenerationkwhInvestment.get_activated_investments_for_a_concret_date( - str(effectiveon)) - if investments: + effectiveon = str(datetime.date.today()) + investment_ids = c.GenerationkwhInvestment.search([ + ('active', '=', True), + ('first_effective_date', '=', effectiveon), + ('emission_id.type', '=', 'genkwh'), + ]) + if investment_ids: step("Sending notification mails for investments: {}".format( - ','.join(str(i) for i in investments))) - c.GenerationkwhInvestment.notifyInvestmentsByMail(investments) + ','.join(str(i) for i in investment_ids))) + c.GenerationkwhInvestment.notifyInvestmentsByMail(investment_ids) else: step("There are not activated investments to notify.") success("Done.") diff --git a/som_generationkwh/investment.py b/som_generationkwh/investment.py index b217e097..9981c2e1 100644 --- a/som_generationkwh/investment.py +++ b/som_generationkwh/investment.py @@ -2037,33 +2037,10 @@ def create_interest_invoice(self, cursor, uid, investment_id, vals, context) return investment_id, error - def get_activated_investments_for_a_concret_date( - self, cursor, uid, effective_on, context=None): - """ - Returns all the investments actived on effective_on for repeating members - (so discards first time investments) - """ - cursor.execute(""" - select - investment.id - from - generationkwh_investment as investment - inner join generationkwh_emission as emission - on emission.id = investment.emission_id - where - investment.active - and emission.type = 'genkwh' - and investment.first_effective_date = %(effective_on)s; - """, dict( - effective_on = isodate(effective_on), - )) - result = [ id for id, in cursor.fetchall() ] - return result - - def notifyInvestmentsByMail(self, cursor, uid, investments, context=None): - for investment in investments: + def notifyInvestmentsByMail(self, cursor, uid, investment_ids, context=None): + for investment_id in investment_ids: self.send_mail(cursor, uid, - investment, + investment_id, 'generationkwh.investment', '_investment_activated_notification_mail', context=context)