Skip to content

Instantly share code, notes, and snippets.

@ofelix03
Created September 3, 2021 20:42
Show Gist options
  • Select an option

  • Save ofelix03/14e53348ce1833f9a0bab7489b2bdb29 to your computer and use it in GitHub Desktop.

Select an option

Save ofelix03/14e53348ce1833f9a0bab7489b2bdb29 to your computer and use it in GitHub Desktop.
Example: Table joins with WHERE clause
SELECT ie.name "invoice_number",
pj.name "payment_journal",
apr.amount "reconciliation_amount"
FROM account_move_line iel, --- invoice entry line
account_move ie, --- invoice entry
account_partial_reconcile apr, --- partial payment
account_move_line pel, --- payment entry line
account_move pe, --- payment entry
account_journal pj --- journal
WHERE
--- table joins
iel.move_id = ie.id
AND apr.debit_move_id = iel.id
AND apr.credit_move_id = pel.id
AND pel.move_id = pe.id
AND pj.id = pel.journal_id
--- row filters
AND ie.move_type = 'out_invoice'
AND iel.analytic_account_id = 2443
AND ie.name = 'INV/2021/2344'
ORDER BY ie.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment