Skip to content

Instantly share code, notes, and snippets.

@godie007
Created December 10, 2018 22:21
Show Gist options
  • Save godie007/4a83f3d58086646de941063282d0c929 to your computer and use it in GitHub Desktop.
Save godie007/4a83f3d58086646de941063282d0c929 to your computer and use it in GitHub Desktop.
SELECT r.ref AS company,
l.id AS identificacion,
r.name,
l.price_total,
l.price_unit,
l.price_subtotal,
l.quantity,
l.discount,
c.name AS contract,
a.date_invoice,
t.name AS product,
p.default_code AS reference,
p.access_control,
CASE
WHEN a.type::text = 'out_invoice'::text THEN l.creditos
ELSE l.creditos * '-1'::integer::numeric
END AS creditos,
a.periodo_from AS date_start,
a.periodo_to AS date_stop,
a.date AS created_at,
a.number AS id_invoice,
a.state
FROM account_invoice a
JOIN res_partner r ON r.id = a.partner_id
JOIN account_invoice_line l ON l.invoice_id = a.id
JOIN product_product p ON p.id = l.product_id
JOIN product_template t ON t.id = p.product_tmpl_id
LEFT JOIN account_analytic_account c ON c.id = l.account_analytic_id
WHERE a.date >= '2018-01-01'::date AND (a.type::text = ANY (ARRAY['out_invoice'::character varying::text, 'out_refund'::character varying::text]))
and r.name like '%2000%'
and c.name = '485'
ORDER BY r.name, p.default_code, a.date_invoice;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment