[IMP] account: general journal report improvements - Made it work with common wizard
bzr revid: qdp-launchpad@tinyerp.com-20100629130945-wsyrnwm336aftl19
This commit is contained in:
parent
e5451856b0
commit
e529443c4b
|
@ -40,17 +40,16 @@ class journal_print(report_sxw.rml_parse):
|
|||
})
|
||||
|
||||
def set_context(self, objects, data, ids, report_type=None):
|
||||
super(journal_print, self).set_context(objects, data, ids, report_type)
|
||||
if (data['model'] == 'account.journal.period'):
|
||||
self.cr.execute('SELECT period_id, journal_id '
|
||||
'FROM account_journal_period '
|
||||
'WHERE id IN %s',
|
||||
(tuple(ids),))
|
||||
else:
|
||||
self.cr.execute('SELECT period_id, journal_id '
|
||||
'FROM account_journal_period ')
|
||||
new_ids = ids
|
||||
if (data['model'] == 'ir.ui.menu'):
|
||||
new_ids = 'active_ids' in data['form'] and data['form']['active_ids'] or []
|
||||
self.cr.execute('SELECT period_id, journal_id FROM account_journal_period WHERE id IN %s', (tuple(new_ids),))
|
||||
res = self.cr.fetchall()
|
||||
self.period_ids, self.journal_ids = zip(*res)
|
||||
self.query_get_clause = data['form']['query_line'] or ''
|
||||
objects = self.pool.get('account.journal.period').browse(self.cr, self.uid, new_ids)
|
||||
super(journal_print, self).set_context(objects, data, ids, report_type)
|
||||
|
||||
|
||||
# returns a list of period objs
|
||||
def periods(self, journal_period_objs):
|
||||
|
@ -65,41 +64,13 @@ class journal_print(report_sxw.rml_parse):
|
|||
return map(lambda x: x.period_id, filtered_objs)
|
||||
|
||||
def lines(self, period_id, journal_id=[]):
|
||||
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:
|
||||
ids_final.append(ids_journal_period[0])
|
||||
data_jour_period = self.pool.get('account.journal.period').browse(self.cr, self.uid, ids_final)
|
||||
lines_data = []
|
||||
periods = []
|
||||
for data in data_jour_period:
|
||||
if not data.period_id.id in periods:
|
||||
periods.append(data.period_id.id)
|
||||
for period in periods:
|
||||
period_data = self.pool.get('account.period').browse(self.cr, self.uid, period)
|
||||
self.cr.execute(
|
||||
'SELECT j.code, j.name, '
|
||||
'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 '
|
||||
'AND l.state<>\'draft\' '
|
||||
'GROUP BY j.id, j.code, j.name', (period, tuple(journal_id)))
|
||||
res = self.cr.dictfetchall()
|
||||
res[0].update({'period_name':period_data.name})
|
||||
res[0].update({'pid':period})
|
||||
lines_data.append(res)
|
||||
return lines_data
|
||||
if not self.journal_ids:
|
||||
return []
|
||||
self.cr.execute('SELECT j.code, j.name, '
|
||||
'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 '
|
||||
'WHERE period_id=%s AND journal_id IN %s ' +self.query_get_clause +
|
||||
'AND l.state<>\'draft\' '
|
||||
'GROUP BY j.id, j.code, j.name',
|
||||
(period_id, tuple(self.journal_ids)))
|
||||
|
@ -111,7 +82,7 @@ class journal_print(report_sxw.rml_parse):
|
|||
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 '
|
||||
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
(period_id, tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
@ -121,7 +92,7 @@ class journal_print(report_sxw.rml_parse):
|
|||
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 '
|
||||
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
(period_id, tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
@ -133,7 +104,7 @@ class journal_print(report_sxw.rml_parse):
|
|||
return 0.0
|
||||
self.cr.execute('SELECT SUM(debit) FROM account_move_line '
|
||||
'WHERE period_id IN %s '
|
||||
'AND journal_id IN %s '
|
||||
'AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
(tuple(periods), tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
@ -145,12 +116,9 @@ class journal_print(report_sxw.rml_parse):
|
|||
return 0.0
|
||||
self.cr.execute('SELECT SUM(credit) FROM account_move_line '
|
||||
'WHERE period_id IN %s '
|
||||
'AND journal_id IN %s '
|
||||
'AND journal_id IN %s '+self.query_get_clause +
|
||||
'AND state<>\'draft\'',
|
||||
(tuple(periods), tuple(journals)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print, header=False)
|
||||
report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml', parser=journal_print, header=False)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -27,40 +27,21 @@ class account_general_journal(osv.osv_memory):
|
|||
_description = 'Account General Journal'
|
||||
|
||||
def _build_context(self, cr, uid, ids, data, context=None):
|
||||
period_obj = self.pool.get('account.period')
|
||||
result = super(account_general_journal, self)._build_context(cr, uid, ids, data, context=context)
|
||||
if not data['form']['period_from'] or not data['form']['period_to']:
|
||||
raise osv.except_osv(_('Error'),_('Select Start period and End period'))
|
||||
elif (data['form']['period_from'] > data['form']['period_to']):
|
||||
raise osv.except_osv(_('Error'),_('Start period should be smaller then End period'))
|
||||
period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start']
|
||||
period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop']
|
||||
cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop))
|
||||
result.update({'periods': map(lambda x: x[0], cr.fetchall())})
|
||||
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):
|
||||
if context is None:
|
||||
context = {}
|
||||
obj_jperiod = self.pool.get('account.journal.period')
|
||||
period_id = data['form']['periods']
|
||||
journal_id = data['form']['journal_ids']
|
||||
if type(period_id)==type([]):
|
||||
ids_final = []
|
||||
for journal in journal_id:
|
||||
for period in period_id:
|
||||
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!'))
|
||||
data['ids'] = []
|
||||
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
|
||||
if data['model'] == 'ir.ui.menu':
|
||||
return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal.wiz', 'datas': data, 'nodestroy':True, }
|
||||
else:
|
||||
return {'type': 'ir.actions.report.xml', 'report_name': 'account.general.journal', 'datas': data, 'nodestroy':True, }
|
||||
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:
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -1,28 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_account_general_journal" model="ir.ui.view">
|
||||
<field name="name">Account Genral Journal</field>
|
||||
<record id="account_report_general_journal_view" model="ir.ui.view">
|
||||
<field name="name">Account General Journal</field>
|
||||
<field name="model">account.general.journal</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="account_common_report_view" />
|
||||
<field name="arch" type="xml">
|
||||
<form string="Print General Journal">
|
||||
<group height="320" width="560">
|
||||
<separator string="Journals" colspan="4"/>
|
||||
<field name="journal_ids" nolabel="1" colspan="4"/>
|
||||
<separator string="Periods" colspan="4"/>
|
||||
<group colspan="4">
|
||||
<field name="period_from"/>
|
||||
<field name="period_to"/>
|
||||
</group>
|
||||
<group>
|
||||
<separator colspan="4"/>
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="check_report" string="Print" colspan="1" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
<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>
|
||||
|
||||
|
@ -33,14 +20,14 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="account_report_general_journal_view"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="General Journals"
|
||||
parent="account.menu_generic_report"
|
||||
action="action_account_general_journal"
|
||||
id="menu_account_general_journal"
|
||||
icon="STOCK_PRINT"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
<menuitem
|
||||
name="General Journals"
|
||||
parent="account.menu_generic_report"
|
||||
action="action_account_general_journal"
|
||||
id="menu_account_general_journal"
|
||||
icon="STOCK_PRINT"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue