From 20ec7ca862fb63daffd459174ba686118c8f71f7 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Mon, 6 Jun 2016 14:38:52 +0200 Subject: [PATCH] move ledger query to a file for easier testing --- .../wizard/ledger.sql | 55 +++++++++++++++++++ .../wizard/ledger_report_wizard.py | 55 +------------------ 2 files changed, 57 insertions(+), 53 deletions(-) create mode 100644 account_financial_report_qweb/wizard/ledger.sql diff --git a/account_financial_report_qweb/wizard/ledger.sql b/account_financial_report_qweb/wizard/ledger.sql new file mode 100644 index 00000000..a3b937be --- /dev/null +++ b/account_financial_report_qweb/wizard/ledger.sql @@ -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 diff --git a/account_financial_report_qweb/wizard/ledger_report_wizard.py b/account_financial_report_qweb/wizard/ledger_report_wizard.py index 5ec45900..dfa5f5a4 100644 --- a/account_financial_report_qweb/wizard/ledger_report_wizard.py +++ b/account_financial_report_qweb/wizard/ledger_report_wizard.py @@ -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)