bring back in inner filter in year start

It is @luc-demeyer and @jbeficient that proposed this approach: in inner
WHERE clause on the start of the fiscal year makes sure that initial and
running balances are correct. This means that depending of the account
type, totals are computed from the start of the fiscal year or from the
beginning of time. This was initially suggested in

https://github.com/oca-sorrento/account-financial-reporting/pull/2

The WHERE clause on date_from and date_to is different and it is
outside because it affects which line are shown but not the initial and
running balance.
pull/196/head
Leonardo Pistone 2016-06-06 16:09:13 +02:00
parent eadf4be770
commit 42337ed3e3
1 changed files with 8 additions and 8 deletions

View File

@ -12,15 +12,16 @@ WITH view_q as (
SUM(credit) OVER w_account - credit AS init_credit, SUM(credit) OVER w_account - credit AS init_credit,
SUM(debit - credit) OVER w_account - (debit - credit) AS init_balance, SUM(debit - credit) OVER w_account - (debit - credit) AS init_balance,
SUM(debit - credit) OVER w_account AS cumul_balance SUM(debit - credit) OVER w_account AS cumul_balance
FROM FROM account_account AS acc
account_account AS acc
LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id) LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id)
INNER JOIN account_move AS m ON (ml.move_id = m.id) INNER JOIN account_move AS m ON (ml.move_id = m.id)
WINDOW w_account AS ( INNER JOIN account_account_type aat ON (acc.user_type_id = aat.id)
PARTITION BY acc.code WHERE ml.date >= %(fy_date)s OR aat.include_initial_balance IS TRUE
ORDER BY ml.date, ml.id WINDOW w_account AS (
) PARTITION BY acc.code
ORDER BY acc.id, ml.date ORDER BY ml.date, ml.id
)
ORDER BY acc.id, ml.date
) )
INSERT INTO ledger_report_wizard_line ( INSERT INTO ledger_report_wizard_line (
date, date,
@ -51,4 +52,3 @@ SELECT
%(wizard_id)s as wizard_id %(wizard_id)s as wizard_id
FROM view_q FROM view_q
WHERE date BETWEEN %(date_from)s AND %(date_to)s; WHERE date BETWEEN %(date_from)s AND %(date_to)s;
-- WHERE date >= %(fy_date)s