move ledger query to a file for easier testing
parent
d8a2d2cc83
commit
a5ffeee748
|
@ -0,0 +1,55 @@
|
|||
WITH view_q as (
|
||||
SELECT
|
||||
ml.date,
|
||||
acc.id AS account_id,
|
||||
ml.debit,
|
||||
ml.credit,
|
||||
ml.name as name,
|
||||
ml.ref,
|
||||
ml.journal_id,
|
||||
ml.partner_id,
|
||||
SUM(debit) OVER w_account - debit AS init_debit,
|
||||
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 AS cumul_balance
|
||||
FROM
|
||||
account_account AS acc
|
||||
LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id)
|
||||
--INNER JOIN res_partner AS part ON (ml.partner_id = part.id)
|
||||
INNER JOIN account_move AS m ON (ml.move_id = m.id)
|
||||
WINDOW w_account AS (
|
||||
PARTITION BY acc.code
|
||||
ORDER BY ml.date, ml.id
|
||||
)
|
||||
ORDER BY acc.id, ml.date
|
||||
)
|
||||
INSERT INTO ledger_report_wizard_line (
|
||||
date,
|
||||
name,
|
||||
journal_id,
|
||||
account_id,
|
||||
partner_id,
|
||||
ref,
|
||||
label,
|
||||
--counterpart
|
||||
debit,
|
||||
credit,
|
||||
cumul_balance,
|
||||
wizard_id
|
||||
)
|
||||
SELECT
|
||||
date,
|
||||
name,
|
||||
journal_id,
|
||||
account_id,
|
||||
partner_id,
|
||||
ref,
|
||||
' TODO label ' as label,
|
||||
--counterpart
|
||||
debit,
|
||||
credit,
|
||||
cumul_balance,
|
||||
%(wizard_id)s as wizard_id
|
||||
FROM view_q
|
||||
WHERE date BETWEEN %(date_from)s AND %(date_to)s;
|
||||
-- WHERE date >= %(fy_date)s
|
|
@ -3,6 +3,7 @@
|
|||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from operator import itemgetter
|
||||
from pkg_resources import resource_string
|
||||
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
|
@ -80,59 +81,7 @@ class LedgerReportWizard(models.TransientModel):
|
|||
and we can filter/group them in the tree view.
|
||||
|
||||
"""
|
||||
query = """
|
||||
WITH view_q as (SELECT
|
||||
ml.date,
|
||||
acc.id AS account_id,
|
||||
ml.debit,
|
||||
ml.credit,
|
||||
ml.name as name,
|
||||
ml.ref,
|
||||
ml.journal_id,
|
||||
ml.partner_id,
|
||||
SUM(debit) OVER w_account - debit AS init_debit,
|
||||
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 AS cumul_balance
|
||||
FROM
|
||||
account_account AS acc
|
||||
LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id)
|
||||
--INNER JOIN res_partner AS part ON (ml.partner_id = part.id)
|
||||
INNER JOIN account_move AS m ON (ml.move_id = m.id)
|
||||
WINDOW w_account AS (PARTITION BY acc.code ORDER BY ml.date, ml.id)
|
||||
ORDER BY acc.id, ml.date)
|
||||
INSERT INTO ledger_report_wizard_line (
|
||||
date,
|
||||
name,
|
||||
journal_id,
|
||||
account_id,
|
||||
partner_id,
|
||||
ref,
|
||||
label,
|
||||
--counterpart
|
||||
debit,
|
||||
credit,
|
||||
cumul_balance,
|
||||
wizard_id
|
||||
)
|
||||
SELECT
|
||||
date,
|
||||
name,
|
||||
journal_id,
|
||||
account_id,
|
||||
partner_id,
|
||||
ref,
|
||||
' TODO label ' as label,
|
||||
--counterpart
|
||||
debit,
|
||||
credit,
|
||||
cumul_balance,
|
||||
%(wizard_id)s as wizard_id
|
||||
FROM view_q
|
||||
WHERE date BETWEEN %(date_from)s AND %(date_to)s
|
||||
"""
|
||||
|
||||
query = resource_string(__name__, 'ledger.sql')
|
||||
params = dict(fy_date=self.fy_start_date, wizard_id=self.id,
|
||||
date_from=self.date_from, date_to=self.date_to)
|
||||
self.env.cr.execute(query, params)
|
||||
|
|
Loading…
Reference in New Issue