Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- linea.account_id,
- array_agg(linea.id) AS linea_ids,
- sum(linea.debit) AS debe,
- sum(linea.credit) AS haber
- FROM
- account_voucher voucher
- LEFT JOIN account_move_line linea ON linea.move_id = voucher.move_id
- OR linea.id IN (SELECT move_line_id FROM account_voucher_line WHERE voucher_id = voucher.id AND amount > 0)
- OR linea.id IN (SELECT aml.id FROM account_voucher_descuento_recargo descuento LEFT JOIN account_invoice ON descuento.comprobante_id = account_invoice.id LEFT JOIN account_move_line aml ON aml.move_id = account_invoice.move_id WHERE descuento.voucher_id = voucher.id)
- LEFT JOIN account_account cuenta ON linea.account_id = cuenta.id
- WHERE
- cuenta.type in ('receivable', 'payable')
- AND voucher.id = %s
- AND linea.id NOT IN (%s)
- GROUP BY linea.account_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement