Skip to content

Commit

Permalink
Merge pull request #33 from Som-Energia/IMP_ooqery_get_total_saving_p…
Browse files Browse the repository at this point in the history
…artner

Millorar rendiment de get_total_saving_partner
  • Loading branch information
susu105 committed Aug 10, 2020
2 parents 82053f2 + 253ee79 commit a33cf04
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions som_generationkwh/investment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from osv import osv, fields
from osv.expression import OOQuery
from .erpwrapper import ErpWrapper
from dateutil.relativedelta import relativedelta
from datetime import datetime, date
Expand Down Expand Up @@ -621,16 +622,25 @@ def get_total_saving_partner(self, cursor, uid, partner_id, start_date, end_date
:param partner_id: In this function, partner_id is the partner of Investment, not the Parnter of Invoice.
"""
GenerationkwhInvoiceLineOwner = self.pool.get('generationkwh.invoice.line.owner')
q = OOQuery(GenerationkwhInvoiceLineOwner, cursor, uid)

total_amount_saving = 0
search_params = [('owner_id.id', '=', partner_id),
('factura_id.invoice_id.date_invoice', '>=', start_date),
('factura_id.invoice_id.date_invoice', '<=', end_date)]

sql = q.select(['saving_gkw_amount','factura_line_id']).where(search_params)
cursor.execute(*sql)
total_amount_saving = 0
gffl_added = set()
list_gkwlines_ids = GenerationkwhInvoiceLineOwner.search(cursor, uid, [('owner_id','=',partner_id),('factura_id.date_invoice','>=',start_date), ('factura_id.date_invoice','<=',end_date)])
for line_id in list_gkwlines_ids:
invoice_obj = GenerationkwhInvoiceLineOwner.read(cursor, uid, line_id, ['saving_gkw_amount', 'factura_line_id'])
if invoice_obj['factura_line_id'] not in gffl_added:
total_amount_saving += invoice_obj['saving_gkw_amount']
gffl_added.add(invoice_obj['factura_line_id'])
result = cursor.dictfetchall()
result = {d['factura_line_id']: d['saving_gkw_amount'] for d in result}

if result:
total_amount_saving = sum(result.values())

return total_amount_saving


def get_irpf_amounts(self, cursor, uid, investment_id, member_id, year=None):
Invoice = self.pool.get('account.invoice')
InvoiceLine = self.pool.get('account.invoice.line')
Expand Down

0 comments on commit a33cf04

Please sign in to comment.