Browse Source

minor cleanup plus some docstrings

pull/196/head
Simone Orsi 8 years ago
committed by Leonardo Pistone
parent
commit
51288edf0d
  1. 38
      account_financial_report_qweb/wizard/ledger_report_wizard.py

38
account_financial_report_qweb/wizard/ledger_report_wizard.py

@ -6,6 +6,7 @@ from openerp import models, fields, api, _
class LedgerReportWizard(models.TransientModel):
"""Base ledger report wizard."""
_name = "ledger.report.wizard"
_description = "Ledger Report Wizard"
@ -29,9 +30,10 @@ class LedgerReportWizard(models.TransientModel):
centralize = fields.Boolean(string='Activate centralization',
default=False)
result_selection = fields.Selection(
[('customer', 'Receivable Accounts'),
[
('customer', 'Receivable Accounts'),
('supplier', 'Payable Accounts'),
('customer_supplier', 'Receivable and Payable Accounts')
('customer_supplier', 'Receivable and Payable Accounts'),
],
string="Partner's",
default='customer')
@ -43,6 +45,20 @@ class LedgerReportWizard(models.TransientModel):
inverse_name='wizard_id')
def _query(self):
"""Execute query.
Short summary:
Prepare all lines for report
by calculating debit/credit amounts
plus the cumulative one.
Narrow the search by using PG windows.
Insert all the rows in `ledger_report_wizard_line`
at once, so that we have real model objects
and we can filter/group them in the tree view.
"""
query = """
WITH view_q as (SELECT
ml.date,
@ -63,11 +79,9 @@ class LedgerReportWizard(models.TransientModel):
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)
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
(
INSERT INTO ledger_report_wizard_line (
date,
name,
journal_id,
@ -93,10 +107,9 @@ class LedgerReportWizard(models.TransientModel):
debit,
credit,
cumul_balance,
%(wizard_id)s as wizard_id
from view_q
where date between %(date_from)s and %(date_to)s
FROM view_q
WHERE date BETWEEN %(date_from)s AND %(date_to)s
"""
params = dict(fy_date=self.fy_start_date, wizard_id=self.id,
@ -130,10 +143,12 @@ class LedgerReportWizard(models.TransientModel):
@api.multi
def button_view(self):
"""Open tree view w/ results."""
return self.process()
@api.multi
def process(self):
"""Process data and return window action."""
self._query()
return {
@ -152,6 +167,7 @@ class LedgerReportWizard(models.TransientModel):
@api.onchange('date_range_id')
def onchange_date_range_id(self):
"""Handle date range change."""
self.date_from = self.date_range_id.date_start
self.date_to = self.date_range_id.date_end
if self.date_from:
@ -160,6 +176,10 @@ class LedgerReportWizard(models.TransientModel):
class LedgerReportWizardLine(models.TransientModel):
"""A wizard line.
Lines are populated on the fly when submitting the wizard.
"""
_name = 'ledger.report.wizard.line'
wizard_id = fields.Many2one(comodel_name='ledger.report.wizard')

Loading…
Cancel
Save