[IMP] account: journals report - more refactoring
bzr revid: qdp-launchpad@tinyerp.com-20100629160516-67e1toe81fjky759
This commit is contained in:
parent
25a7482445
commit
13241bca58
|
@ -65,9 +65,9 @@ module named account_vouchers
|
|||
'wizard/account_open_closed_fiscalyear_view.xml',
|
||||
'wizard/account_move_line_unreconcile_select_view.xml',
|
||||
'wizard/account_vat_view.xml',
|
||||
'wizard/account_print_journal_view.xml',
|
||||
'wizard/account_general_journal_view.xml',
|
||||
'wizard/account_central_journal_view.xml',
|
||||
'wizard/account_report_print_journal_view.xml',
|
||||
'wizard/account_report_general_journal_view.xml',
|
||||
'wizard/account_report_central_journal_view.xml',
|
||||
'wizard/account_subscription_generate_view.xml',
|
||||
'wizard/account_fiscalyear_close_view.xml',
|
||||
'wizard/account_state_open_view.xml',
|
||||
|
|
|
@ -53,16 +53,16 @@ class journal_print(report_sxw.rml_parse):
|
|||
obj_mline = self.pool.get('account.move.line')
|
||||
self.cr.execute('update account_journal_period set state=%s where journal_id=%s and period_id=%s and state=%s', ('printed',journal_id,period_id,'draft'))
|
||||
self.cr.commit()
|
||||
self.cr.execute('select id from account_move_line where period_id=%s and journal_id=%s and state<>\'draft\''+self.query_get_clause+' order by %s', (period_id, journal_id, sort_selection))
|
||||
self.cr.execute('SELECT id FROM account_move_line l WHERE '+self.query_get_clause+' AND period_id=%s AND journal_id=%s ORDER BY %s', (period_id, journal_id, sort_selection))
|
||||
ids = map(lambda x: x[0], self.cr.fetchall())
|
||||
return obj_mline.browse(self.cr, self.uid, ids)
|
||||
|
||||
def _sum_debit(self, period_id, journal_id):
|
||||
self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id=%s'+self.query_get_clause+' and state<>\'draft\'', (period_id, journal_id))
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line l WHERE '+self.query_get_clause+' AND period_id=%s AND journal_id=%s', (period_id, journal_id))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def _sum_credit(self, period_id, journal_id):
|
||||
self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id=%s'+self.query_get_clause+' and state<>\'draft\'', (period_id, journal_id))
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line l WHERE '+self.query_get_clause+' AND period_id=%s AND journal_id=%s', (period_id, journal_id))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def get_start_period(self, form):
|
||||
|
|
|
@ -27,6 +27,15 @@ import pooler
|
|||
# Use period and Journal for selection or resources
|
||||
#
|
||||
class journal_print(report_sxw.rml_parse):
|
||||
|
||||
def set_context(self, objects, data, ids, report_type = None):
|
||||
new_ids = ids
|
||||
if (data['model'] == 'ir.ui.menu'):
|
||||
new_ids = 'active_ids' in data['form'] and data['form']['active_ids'] or []
|
||||
objects = self.pool.get('account.journal.period').browse(self.cr, self.uid, new_ids)
|
||||
self.query_get_clause = data['form']['query_line'] or ''
|
||||
super(journal_print, self).set_context(objects, data, new_ids, report_type)
|
||||
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(journal_print, self).__init__(cr, uid, name, context=context)
|
||||
self.localcontext.update({
|
||||
|
@ -39,29 +48,16 @@ class journal_print(report_sxw.rml_parse):
|
|||
})
|
||||
|
||||
def lines(self, period_id, journal_id, *args):
|
||||
if type(period_id)==type([]):
|
||||
ids_final = []
|
||||
for journal in journal_id:
|
||||
for period in period_id:
|
||||
ids_journal_period = self.pool.get('account.journal.period').search(self.cr, self.uid, [('journal_id','=',journal),('period_id','=',period)])
|
||||
if ids_journal_period:
|
||||
self.cr.execute('select a.code, a.name, sum(debit) as debit, sum(credit) as credit from account_move_line l left join account_account a on (l.account_id=a.id) where l.period_id=%s and l.journal_id=%s and l.state<>\'draft\' group by a.id, a.code, a.name, l.journal_id, l.period_id', (period, journal))
|
||||
res = self.cr.dictfetchall()
|
||||
a = {'journal':self.pool.get('account.journal').browse(self.cr, self.uid, journal),'period':self.pool.get('account.period').browse(self.cr, self.uid, period)}
|
||||
if res:
|
||||
res[0].update(a)
|
||||
ids_final.append(res)
|
||||
return ids_final
|
||||
self.cr.execute('select a.code, a.name, sum(debit) as debit, sum(credit) as credit from account_move_line l left join account_account a on (l.account_id=a.id) where l.period_id=%s and l.journal_id=%s and l.state<>\'draft\' group by a.id, a.code, a.name', (period_id, journal_id))
|
||||
self.cr.execute('SELECT a.code, a.name, SUM(debit) AS debit, SUM(credit) AS credit from account_move_line l LEFT JOIN account_account a ON (l.account_id=a.id) WHERE '+self.query_get_clause+' AND l.period_id=%s AND l.journal_id=%s GROUP BY a.id, a.code, a.name', (period_id, journal_id))
|
||||
res = self.cr.dictfetchall()
|
||||
return res
|
||||
|
||||
def _sum_debit(self, period_id, journal_id):
|
||||
self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id=%s and state<>\'draft\'', (period_id, journal_id))
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line l WHERE '+self.query_get_clause+' AND period_id=%s AND journal_id=%s', (period_id, journal_id))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def _sum_credit(self, period_id, journal_id):
|
||||
self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id=%s and state<>\'draft\'', (period_id, journal_id))
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line l WHERE '+self.query_get_clause+' AND period_id=%s AND journal_id=%s', (period_id, journal_id))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def get_start_date(self, form):
|
||||
|
@ -70,9 +66,5 @@ class journal_print(report_sxw.rml_parse):
|
|||
def get_end_date(self, form):
|
||||
return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_to']).name
|
||||
|
||||
|
||||
report_sxw.report_sxw('report.account.central.journal', 'account.journal.period', 'addons/account/report/central_journal.rml', parser=journal_print, header=False)
|
||||
report_sxw.report_sxw('report.account.central.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_central_journal.rml', parser=journal_print, header=False)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -72,8 +72,7 @@ class journal_print(report_sxw.rml_parse):
|
|||
'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
|
||||
'FROM account_move_line l '
|
||||
'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
|
||||
'WHERE period_id=%s AND journal_id IN %s ' +self.query_get_clause +
|
||||
'AND l.state<>\'draft\' '
|
||||
'WHERE '+self.query_get_clause +' AND period_id=%s AND journal_id IN %s '
|
||||
'GROUP BY j.id, j.code, j.name',
|
||||
(period_id, tuple(self.journal_ids)))
|
||||
res = self.cr.dictfetchall()
|
||||
|
@ -83,9 +82,8 @@ class journal_print(report_sxw.rml_parse):
|
|||
journals = journal_id or self.journal_ids
|
||||
if not journals:
|
||||
return 0.0
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line '
|
||||
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line l '
|
||||
'WHERE '+self.query_get_clause +' AND period_id=%s AND journal_id IN %s ',
|
||||
(period_id, tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
@ -93,9 +91,8 @@ class journal_print(report_sxw.rml_parse):
|
|||
journals = journal_id or self.journal_ids
|
||||
if not journals:
|
||||
return 0.0
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line '
|
||||
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line l '
|
||||
'WHERE '+self.query_get_clause +' AND period_id=%s AND journal_id IN %s ',
|
||||
(period_id, tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
@ -104,10 +101,9 @@ class journal_print(report_sxw.rml_parse):
|
|||
periods = period_id or self.period_ids
|
||||
if not (journals and periods):
|
||||
return 0.0
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line '
|
||||
'WHERE period_id IN %s '
|
||||
'AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line l '
|
||||
'WHERE '+self.query_get_clause +' AND period_id IN %s '
|
||||
'AND journal_id IN %s ',
|
||||
(tuple(periods), tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
@ -116,10 +112,9 @@ class journal_print(report_sxw.rml_parse):
|
|||
journals = journal_id or self.journal_ids
|
||||
if not (periods and journals):
|
||||
return 0.0
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line '
|
||||
'WHERE period_id IN %s '
|
||||
'AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line l '
|
||||
'WHERE '+self.query_get_clause +' AND period_id IN %s '
|
||||
'AND journal_id IN %s ',
|
||||
(tuple(periods), tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
|
|
@ -56,9 +56,12 @@ import account_use_model
|
|||
import account_state_open
|
||||
|
||||
import account_statement_from_invoice
|
||||
import account_print_journal
|
||||
import account_central_journal
|
||||
import account_general_journal
|
||||
|
||||
import account_common_journal_report
|
||||
import account_report_print_journal
|
||||
import account_report_central_journal
|
||||
import account_report_general_journal
|
||||
|
||||
import account_change_currency
|
||||
|
||||
import account_bs_report
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_account_central_journal" model="ir.ui.view">
|
||||
<field name="name">Account central Journal</field>
|
||||
<field name="model">account.central.journal</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Print Central Journal">
|
||||
<group>
|
||||
<separator string="Journals"/><newline/>
|
||||
<field name="journal_ids" nolabel="1"/><newline/>
|
||||
<separator string="Periods"/><newline/>
|
||||
<group>
|
||||
<field name="period_from"/>
|
||||
<field name="period_to"/>
|
||||
</group>
|
||||
</group>
|
||||
<newline/>
|
||||
<group>
|
||||
<separator/><newline/>
|
||||
<group>
|
||||
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||
<button name="check_report" string="Print" type="object" icon="gtk-print"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_central_journal" model="ir.actions.act_window">
|
||||
<field name="name">Account Central Journal</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.central.journal</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Central Journals"
|
||||
parent="account.menu_generic_report"
|
||||
action="action_account_central_journal"
|
||||
id="menu_account_central_journal"
|
||||
icon="STOCK_PRINT"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -21,27 +21,26 @@
|
|||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_general_journal(osv.osv_memory):
|
||||
class account_common_journal_report(osv.osv_memory):
|
||||
_name = 'account.common.journal.report'
|
||||
_description = 'Account Commont Journal Report'
|
||||
_inherit = "account.common.report"
|
||||
_name = 'account.general.journal'
|
||||
_description = 'Account General Journal'
|
||||
|
||||
def _build_context(self, cr, uid, ids, data, context=None):
|
||||
result = super(account_general_journal, self)._build_context(cr, uid, ids, data, context=context)
|
||||
result = super(account_common_journal_report, self)._build_context(cr, uid, ids, data, context=context)
|
||||
if data['form']['filter'] == 'filter_date':
|
||||
cr.execute('SELECT period_id FROM account_move_line WHERE date >= %s AND date <= %s', (data['form']['date_from'], data['form']['date_to']))
|
||||
result['periods'] = map(lambda x: x[0], cr.fetchall())
|
||||
return result
|
||||
|
||||
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
def pre_print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
data['form'].update(self.read(cr, uid, ids, ['sort_selection'])[0])
|
||||
fy_ids = data['form']['fiscalyear_id'] and [data['form']['fiscalyear_id']] or self.pool.get('account.fiscalyear').search(cr, uid, [('state', '=', 'draft')], context=context)
|
||||
period_list = data['form']['periods'] or self.pool.get('account.period').search(cr, uid, [('fiscalyear_id', 'in', fy_ids)], context=context)
|
||||
data['form']['active_ids'] = self.pool.get('account.journal.period').search(cr, uid, [('journal_id', 'in', data['form']['journal_ids']), ('period_id', 'in', period_list)], context=context)
|
||||
data['form']['query_get'] = query_line
|
||||
return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal', 'datas': data, 'nodestroy':True, }
|
||||
data['form']['query_line'] = query_line
|
||||
return data
|
||||
|
||||
account_general_journal()
|
||||
account_common_journal_report()
|
||||
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -24,27 +24,16 @@ from tools.translate import _
|
|||
class account_central_journal(osv.osv_memory):
|
||||
_name = 'account.central.journal'
|
||||
_description = 'Account Central Journal'
|
||||
_inherit = "account.common.report"
|
||||
_inherit = "account.common.journal.report"
|
||||
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
periods = data['form']['periods']
|
||||
data['ids'] = ids
|
||||
obj_jperiod = self.pool.get('account.journal.period')
|
||||
if isinstance(periods, list):
|
||||
ids_final = []
|
||||
for journal in data['form']['journal_ids']:
|
||||
for period in periods:
|
||||
ids_journal_period = obj_jperiod.search(cr,uid, [('journal_id','=',journal),('period_id','=',period)], context=context)
|
||||
if ids_journal_period:
|
||||
ids_final.append(ids_journal_period)
|
||||
if not ids_final:
|
||||
raise osv.except_osv(_('No Data Available'), _('No records found for your selection!'))
|
||||
return {
|
||||
data = self.pre_print_report(cr, uid, ids, data, query_line, context)
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.central.journal.wiz',
|
||||
'report_name': 'account.central.journal',
|
||||
'datas': data,
|
||||
'nodestroy':True,
|
||||
}
|
||||
}
|
||||
|
||||
account_central_journal()
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_account_central_journal" model="ir.ui.view">
|
||||
<field name="name">Account central Journal</field>
|
||||
<field name="model">account.central.journal</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="fiscalyear_id" position="after">
|
||||
<!-- we don't change the view but have to define a view for this specific object otherelse openerp will try to build a fedault one without using the one from the parent object -->
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_central_journal" model="ir.actions.act_window">
|
||||
<field name="name">Account Central Journal</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.central.journal</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_account_central_journal"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Central Journals"
|
||||
parent="account.menu_generic_report"
|
||||
action="action_account_central_journal"
|
||||
id="menu_account_central_journal"
|
||||
icon="STOCK_PRINT"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_general_journal(osv.osv_memory):
|
||||
_inherit = "account.common.journal.report"
|
||||
_name = 'account.general.journal'
|
||||
_description = 'Account General Journal'
|
||||
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
data = self.pre_print_report(cr, uid, ids, data, query_line, context)
|
||||
return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal', 'datas': data, 'nodestroy':True, }
|
||||
|
||||
account_general_journal()
|
||||
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -22,7 +22,7 @@ from osv import osv, fields
|
|||
from tools.translate import _
|
||||
|
||||
class account_print_journal(osv.osv_memory):
|
||||
_inherit = "account.common.report"
|
||||
_inherit = "account.common.journal.report"
|
||||
_name = 'account.print.journal'
|
||||
_description = 'Account Print Journal'
|
||||
|
||||
|
@ -36,20 +36,9 @@ class account_print_journal(osv.osv_memory):
|
|||
'sort_selection': 'date',
|
||||
}
|
||||
|
||||
def _build_context(self, cr, uid, ids, data, context=None):
|
||||
result = super(account_print_joural, self)._build_context(cr, uid, ids, data, context=context)
|
||||
if data['form']['filter'] == 'filter_date':
|
||||
cr.execute('SELECT period_id FROM account_move_line WHERE date >= %s AND date <= %s', (data['form']['date_from'], data['form']['date_to']))
|
||||
result['periods'] = map(lambda x: x[0], cr.fetchall())
|
||||
return result
|
||||
|
||||
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
data['form'].update(self.read(cr, uid, ids, ['sort_selection'])[0])
|
||||
fy_ids = data['form']['fiscalyear_id'] and [data['form']['fiscalyear_id']] or self.pool.get('account.fiscalyear').search(cr, uid, [('state', '=', 'draft')], context=context)
|
||||
period_list = data['form']['periods'] or self.pool.get('account.period').search(cr, uid, [('fiscalyear_id', 'in', fy_ids)], context=context)
|
||||
data['form']['active_ids'] = self.pool.get('account.journal.period').search(cr, uid, [('journal_id', 'in', data['form']['journal_ids']), ('period_id', 'in', period_list)], context=context)
|
||||
data['form']['query_get'] = query_line
|
||||
data = self.pre_print_report(cr, uid, ids, data, query_line, context)
|
||||
return { 'type': 'ir.actions.report.xml', 'report_name': 'account.journal.period.print', 'datas': data, 'nodestroy':True, }
|
||||
|
||||
account_print_journal()
|
Loading…
Reference in New Issue