Skip to content

Commit

Permalink
query update
Browse files Browse the repository at this point in the history
  • Loading branch information
susu105 committed Jan 22, 2021
1 parent c142e04 commit 0c3e47c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions som_generationkwh/sql/aeat193_from_gkwh_invoices_query.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
SELECT gkwh_owner.owner_id AS partner_id, par.vat as vat, SUM(gkwh_owner.saving_gkw_amount) as amount
FROM generationkwh_invoice_line_owner gkwh_owner
INNER JOIN giscedata_facturacio_factura f ON f.id=gkwh_owner.factura_id
INNER JOIN account_invoice i ON i.id=f.invoice_id
INNER JOIN res_partner par ON par.id = gkwh_owner.owner_id
WHERE i.date_invoice BETWEEN %(start)s AND %(end)s
GROUP BY gkwh_owner.owner_id, par.vat
SELECT owner_id AS partner_id, owner_vat AS vat, SUM(savings) AS amount
FROM (SELECT gkwh_owner.factura_line_id AS factura_line_id,
max(gkwh_owner.saving_gkw_amount) AS savings,
max(gkwh_owner.id) AS gkwh_id,
max(gkwh_owner.owner_id) AS owner_id,
max(par.vat) AS owner_vat
FROM generationkwh_invoice_line_owner gkwh_owner
INNER JOIN giscedata_facturacio_factura f ON f.id=gkwh_owner.factura_id
INNER JOIN account_invoice i ON i.id=f.invoice_id
INNER JOIN res_partner par ON par.id = gkwh_owner.owner_id
WHERE i.date_invoice BETWEEN %(start)s AND %(end)s
GROUP BY gkwh_owner.factura_line_id ORDER BY gkwh_owner.factura_line_id DESC) AS parcial
GROUP BY owner_id, owner_id, owner_vat
ORDER BY owner_id;

0 comments on commit 0c3e47c

Please sign in to comment.