minor cleanup plus some docstrings
parent
c8e890edb9
commit
ac49d305d4
|
@ -6,6 +6,7 @@ from openerp import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
class LedgerReportWizard(models.TransientModel):
|
class LedgerReportWizard(models.TransientModel):
|
||||||
|
"""Base ledger report wizard."""
|
||||||
|
|
||||||
_name = "ledger.report.wizard"
|
_name = "ledger.report.wizard"
|
||||||
_description = "Ledger Report Wizard"
|
_description = "Ledger Report Wizard"
|
||||||
|
@ -29,10 +30,11 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
centralize = fields.Boolean(string='Activate centralization',
|
centralize = fields.Boolean(string='Activate centralization',
|
||||||
default=False)
|
default=False)
|
||||||
result_selection = fields.Selection(
|
result_selection = fields.Selection(
|
||||||
[('customer', 'Receivable Accounts'),
|
[
|
||||||
('supplier', 'Payable Accounts'),
|
('customer', 'Receivable Accounts'),
|
||||||
('customer_supplier', 'Receivable and Payable Accounts')
|
('supplier', 'Payable Accounts'),
|
||||||
],
|
('customer_supplier', 'Receivable and Payable Accounts'),
|
||||||
|
],
|
||||||
string="Partner's",
|
string="Partner's",
|
||||||
default='customer')
|
default='customer')
|
||||||
partner_ids = fields.Many2many(
|
partner_ids = fields.Many2many(
|
||||||
|
@ -43,8 +45,22 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
inverse_name='wizard_id')
|
inverse_name='wizard_id')
|
||||||
|
|
||||||
def _query(self):
|
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 = """
|
query = """
|
||||||
WITH view_q as (SELECT
|
WITH view_q as (SELECT
|
||||||
ml.date,
|
ml.date,
|
||||||
acc.id AS account_id,
|
acc.id AS account_id,
|
||||||
ml.debit,
|
ml.debit,
|
||||||
|
@ -58,45 +74,42 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
SUM(debit - credit) OVER w_account - (debit - credit)
|
SUM(debit - credit) OVER w_account - (debit - credit)
|
||||||
AS init_balance,
|
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 res_partner AS part ON (ml.partner_id = part.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)
|
INNER JOIN account_move AS m ON (ml.move_id = m.id)
|
||||||
WINDOW w_account AS (
|
WINDOW w_account AS (PARTITION BY acc.code ORDER BY ml.date, ml.id)
|
||||||
PARTITION BY acc.code ORDER BY ml.date, ml.id)
|
ORDER BY acc.id, ml.date)
|
||||||
ORDER BY acc.id, ml.date)
|
INSERT INTO ledger_report_wizard_line (
|
||||||
INSERT INTO ledger_report_wizard_line
|
date,
|
||||||
(
|
name,
|
||||||
date,
|
journal_id,
|
||||||
name,
|
account_id,
|
||||||
journal_id,
|
partner_id,
|
||||||
account_id,
|
ref,
|
||||||
partner_id,
|
label,
|
||||||
ref,
|
--counterpart
|
||||||
label,
|
debit,
|
||||||
--counterpart
|
credit,
|
||||||
debit,
|
cumul_balance,
|
||||||
credit,
|
wizard_id
|
||||||
cumul_balance,
|
)
|
||||||
wizard_id
|
SELECT
|
||||||
)
|
date,
|
||||||
SELECT
|
name,
|
||||||
date,
|
journal_id,
|
||||||
name,
|
account_id,
|
||||||
journal_id,
|
partner_id,
|
||||||
account_id,
|
ref,
|
||||||
partner_id,
|
' TODO label ' as label,
|
||||||
ref,
|
--counterpart
|
||||||
' TODO label ' as label,
|
debit,
|
||||||
--counterpart
|
credit,
|
||||||
debit,
|
cumul_balance,
|
||||||
credit,
|
%(wizard_id)s as wizard_id
|
||||||
cumul_balance,
|
FROM view_q
|
||||||
|
WHERE date BETWEEN %(date_from)s AND %(date_to)s
|
||||||
%(wizard_id)s as wizard_id
|
|
||||||
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,
|
params = dict(fy_date=self.fy_start_date, wizard_id=self.id,
|
||||||
|
@ -130,10 +143,12 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def button_view(self):
|
def button_view(self):
|
||||||
|
"""Open tree view w/ results."""
|
||||||
return self.process()
|
return self.process()
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def process(self):
|
def process(self):
|
||||||
|
"""Process data and return window action."""
|
||||||
self._query()
|
self._query()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -152,6 +167,7 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
|
|
||||||
@api.onchange('date_range_id')
|
@api.onchange('date_range_id')
|
||||||
def onchange_date_range_id(self):
|
def onchange_date_range_id(self):
|
||||||
|
"""Handle date range change."""
|
||||||
self.date_from = self.date_range_id.date_start
|
self.date_from = self.date_range_id.date_start
|
||||||
self.date_to = self.date_range_id.date_end
|
self.date_to = self.date_range_id.date_end
|
||||||
if self.date_from:
|
if self.date_from:
|
||||||
|
@ -160,6 +176,10 @@ class LedgerReportWizard(models.TransientModel):
|
||||||
|
|
||||||
|
|
||||||
class LedgerReportWizardLine(models.TransientModel):
|
class LedgerReportWizardLine(models.TransientModel):
|
||||||
|
"""A wizard line.
|
||||||
|
|
||||||
|
Lines are populated on the fly when submitting the wizard.
|
||||||
|
"""
|
||||||
_name = 'ledger.report.wizard.line'
|
_name = 'ledger.report.wizard.line'
|
||||||
|
|
||||||
wizard_id = fields.Many2one(comodel_name='ledger.report.wizard')
|
wizard_id = fields.Many2one(comodel_name='ledger.report.wizard')
|
||||||
|
|
Loading…
Reference in New Issue