Browse Source

integrate @jbeficent's prototype

pull/196/head
Leonardo Pistone 8 years ago
parent
commit
c642ea89ef
  1. 77
      account_financial_report_qweb/report/general_ledger.py
  2. 22
      account_financial_report_qweb/wizard/general_ledger_wizard.xml
  3. 128
      account_financial_report_qweb/wizard/ledger_report_wizard.py

77
account_financial_report_qweb/report/general_ledger.py

@ -3,13 +3,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api
from openerp import tools
class FinancialReportLine(models.Model):
_inherit = 'financial.report.line'
_name = 'general.ledger.line'
_description = "General Ledger report"
_description = "General Ledger report line"
_auto = False
_order = 'account_id, date'
@ -24,80 +23,6 @@ class FinancialReportLine(models.Model):
label = fields.Char(compute='_get_label', readonly=True, store=False)
def init(self, cr):
report_name = self._name.replace('.', '_')
tools.drop_view_if_exists(cr, report_name)
query = """
CREATE OR REPLACE VIEW %(report_name)s AS (
SELECT
acc.id AS account_id,
acc.code AS account_code,
acc.centralized,
ml.id,
ml.name,
ml.ref,
ml.date,
date_part('year', ml.date) || '-' || date_part('month', ml.date)
AS month,
part.ref AS partner_ref,
part.name AS partner_name,
ml.journal_id,
ml.currency_id,
cur.name AS currency_code,
ml.debit,
ml.credit,
ml.debit - ml.credit AS balance,
ml.amount_currency,
SUM(amount_currency) OVER w_account AS balance_curr,
SUM(debit) OVER w_account AS cumul_debit,
SUM(credit) OVER w_account AS cumul_credit,
SUM(debit - credit) OVER w_account AS cumul_balance,
SUM(amount_currency) OVER w_account AS cumul_balance_curr,
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(amount_currency) OVER w_account - (amount_currency)
AS init_balance_curr,
SUM(debit) OVER w_account_centralized AS debit_centralized,
SUM(credit) OVER w_account_centralized AS credit_centralized,
SUM(debit - credit) OVER w_account_centralized AS balance_centralized,
SUM(amount_currency) OVER w_account_centralized
AS balance_curr_centralized,
SUM(debit) OVER w_account - SUM(debit)
OVER w_account_centralized AS init_debit_centralized,
SUM(credit) OVER w_account - SUM(credit)
OVER w_account_centralized AS init_credit_centralized,
SUM(debit - credit) OVER w_account - SUM(debit - credit)
OVER w_account_centralized AS init_balance_centralized,
SUM(amount_currency) OVER w_account - SUM(amount_currency)
OVER w_account_centralized AS init_balance_curr_centralized,
m.name AS move_name,
m.state AS move_state,
i.number AS invoice_number
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)
LEFT JOIN account_invoice AS i ON (m.id = i.move_id)
LEFT JOIN res_currency AS cur ON (ml.currency_id = cur.id)
WINDOW w_account AS (PARTITION BY acc.code ORDER BY ml.date, ml.id),
w_account_centralized AS (
PARTITION BY acc.code,
date_part('year', ml.date),
date_part('month', ml.date),
ml.journal_id,
ml.partner_id
ORDER BY ml.date, ml.journal_id, ml.id)
)
""" % {'report_name': report_name}
cr.execute(query)
class GeneralLedgerReport(models.TransientModel):

22
account_financial_report_qweb/wizard/general_ledger_wizard.xml

@ -16,6 +16,7 @@
<field name="date_range_id"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="fy_start_date"/>
</group>
<group name="extra_info">
<field name="amount_currency"/>
@ -30,7 +31,7 @@
<label for="account_ids"/>
<field name="account_ids" nolabel="1"/>
<footer>
<button name="check_report" string="Print" type="object" default_focus="1" class="oe_highlight"/>
<button name="button_view" string="View" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
@ -38,6 +39,25 @@
</field>
</record>
<record id="ledger_report_wizard_line_tree_view"
model="ir.ui.view">
<field name="name">General Ledger Line</field>
<field name="model">ledger.report.wizard.line</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="General Ledger">
<field name="date"/>
<field name="account_id"/>
<field name="debit"/>
<field name="credit"/>
<field name="init_debit"/>
<field name="init_credit"/>
<field name="init_balance"/>
<field name="cumul_balance"/>
</tree>
</field>
</record>
<record id="action_ledger_report_wizard" model="ir.actions.act_window">
<field name="name">General Ledger</field>
<field name="type">ir.actions.act_window</field>

128
account_financial_report_qweb/wizard/ledger_report_wizard.py

@ -2,7 +2,7 @@
# Author: Damien Crier
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api
from openerp import models, fields, api, _
class LedgerReportWizard(models.TransientModel):
@ -14,6 +14,7 @@ class LedgerReportWizard(models.TransientModel):
date_range_id = fields.Many2one(comodel_name='date.range', required=True)
date_from = fields.Date()
date_to = fields.Date()
fy_start_date = fields.Date(default='2016-01-01')
target_move = fields.Selection([('posted', 'All Posted Entries'),
('all', 'All Entries')],
string='Target Moves',
@ -38,22 +39,36 @@ class LedgerReportWizard(models.TransientModel):
comodel_name='res.partner',
string='Filter partners',
)
line_ids = fields.One2many(comodel_name='ledger.report.wizard.line',
inverse_name='wizard_id')
@api.multi
def pre_print_report(self, data):
data = {'form': {}}
# will be used to attach the report on the main account
vals = self.read(['amount_currency',
'account_ids',
'journal_ids',
'centralize',
'target_move',
'date_from',
'date_to',
'fiscalyear'])[0]
data['form'].update(vals)
return data
def _query(self):
query = """
WITH view_q as (SELECT
ml.date,
acc.id AS account_id,
ml.debit,
ml.credit,
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)
SELECT * from view_q where date >= %s
"""
params = (self.fy_start_date,)
self.env.cr.execute(query, params)
return self.env.cr.fetchall()
@api.multi
def _print_report(self, data):
@ -80,20 +95,77 @@ class LedgerReportWizard(models.TransientModel):
return result
@api.multi
def check_report(self):
self.ensure_one()
data = {}
data['ids'] = self.env.context.get('active_ids', [])
data['model'] = self.env.context.get('active_model', 'ir.ui.menu')
data['form'] = self.read(['date_from', 'date_to',
'journal_ids', 'target_move'])[0]
used_context = self._build_contexts(data)
data['form']['used_context'] = dict(
used_context,
lang=self.env.context.get('lang', 'en_US'))
return self._print_report(data)
def button_view(self):
return self.process()
@api.multi
def process(self):
ledger_line_obj = self.env['ledger.report.wizard.line']
rows = self._query()
res = []
for row in rows:
data = {
'wizard_id': self.id,
'date': row[0],
'account_id': row[1],
'debit': row[2],
'credit': row[3],
'init_debit': row[4],
'init_credit': row[5],
'init_balance': row[6],
'cumul_balance': row[7]
}
gll = ledger_line_obj.create(data)
res.append(gll.id)
return {
'domain': [('wizard_id', '=', self.id)],
'name': _('Ledger lines'),
'view_type': 'form',
'view_mode': 'tree',
'res_model': 'ledger.report.wizard.line',
'view_id': False,
'context': False,
'type': 'ir.actions.act_window'
}
@api.onchange('date_range_id')
def onchange_date_range_id(self):
self.date_from = self.date_range_id.date_start
self.date_to = self.date_range_id.date_end
class LedgerReportWizardLine(models.TransientModel):
_name = 'ledger.report.wizard.line'
wizard_id = fields.Many2one(comodel_name='ledger.report.wizard')
name = fields.Char()
ref = fields.Char()
date = fields.Date()
month = fields.Char()
partner_name = fields.Char()
partner_ref = fields.Char()
account_id = fields.Many2one('account.account')
account_code = fields.Char()
journal_id = fields.Many2one('account.journal')
init_credit = fields.Float()
init_debit = fields.Float()
debit = fields.Float()
credit = fields.Float()
balance = fields.Float()
cumul_credit = fields.Float()
cumul_debit = fields.Float()
cumul_balance = fields.Float()
init_credit = fields.Float()
init_debit = fields.Float()
init_balance = fields.Float()
move_name = fields.Char()
move_state = fields.Char()
invoice_number = fields.Char()
centralized = fields.Boolean()
Loading…
Cancel
Save