-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
7 deletions.
There are no files selected for viewing
21 changes: 14 additions & 7 deletions
21
som_generationkwh/sql/aeat193_from_gkwh_invoices_query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |