Created
November 12, 2011 10:54
-
-
Save eLBati/1360379 to your computer and use it in GitHub Desktop.
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
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