Skip to content

Instantly share code, notes, and snippets.

@eLBati
Created November 12, 2011 10:54
Show Gist options
  • Save eLBati/1360379 to your computer and use it in GitHub Desktop.
Save eLBati/1360379 to your computer and use it in GitHub Desktop.
SELECT id
FROM account_move_line l
WHERE
account_id IN
(select id
FROM account_account
WHERE
type='receivable'
AND
active)
AND
reconcile_id IS NOT NULL
AND debit > 0
AND
(SELECT
CASE WHEN l.amount_currency < 0
THEN - l.amount_currency
ELSE l.debit
END - coalesce(sum(rl.amount_currency), 0)
FROM riba_line rl
INNER JOIN riba_order ro ON (rl.order_id = ro.id)
WHERE move_line_id = l.id
AND ro.state != 'cancel'
)
> 0
and l.state <> 'draft'
AND l.period_id IN
(SELECT id
FROM account_period
WHERE fiscalyear_id IN (1)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment