2009-10-14 11:15:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-11-30 10:24:22 +00:00
|
|
|
#
|
2009-05-04 12:12:54 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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.
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-11-03 19:18:56 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-11-30 10:24:22 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
2010-07-09 13:06:52 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
import time
|
|
|
|
|
2010-07-09 04:18:45 +00:00
|
|
|
import pooler
|
2010-07-14 12:54:18 +00:00
|
|
|
from common_report_header import common_report_header
|
2010-07-09 04:18:45 +00:00
|
|
|
from report import report_sxw
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
# Use period and Journal for selection or resources
|
|
|
|
#
|
2010-07-14 12:54:18 +00:00
|
|
|
class journal_print(report_sxw.rml_parse, common_report_header):
|
2010-07-13 03:39:27 +00:00
|
|
|
|
2010-07-09 04:18:45 +00:00
|
|
|
def __init__(self, cr, uid, name, context=None):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
2009-10-09 11:49:00 +00:00
|
|
|
super(journal_print, self).__init__(cr, uid, name, context=context)
|
2010-07-09 13:06:52 +00:00
|
|
|
self.period_ids = []
|
|
|
|
self.journal_ids = []
|
2008-07-22 15:11:28 +00:00
|
|
|
self.localcontext.update( {
|
|
|
|
'time': time,
|
|
|
|
'lines': self.lines,
|
|
|
|
'periods': self.periods,
|
|
|
|
'sum_debit_period': self._sum_debit_period,
|
|
|
|
'sum_credit_period': self._sum_credit_period,
|
|
|
|
'sum_debit': self._sum_debit,
|
2010-06-25 12:23:59 +00:00
|
|
|
'sum_credit': self._sum_credit,
|
2010-07-14 12:04:20 +00:00
|
|
|
'get_fiscalyear': self._get_fiscalyear,
|
|
|
|
'get_account': self._get_account,
|
|
|
|
'get_start_period': self.get_start_period,
|
|
|
|
'get_end_period': self.get_end_period,
|
2010-07-15 07:22:06 +00:00
|
|
|
'get_sortby': self._get_sortby,
|
2010-07-20 11:51:13 +00:00
|
|
|
'get_filter': self._get_filter,
|
2010-07-16 11:07:48 +00:00
|
|
|
'get_journal': self._get_journal,
|
2010-07-19 10:25:32 +00:00
|
|
|
'get_start_date':self._get_start_date,
|
2010-07-20 11:51:13 +00:00
|
|
|
'get_end_date':self._get_end_date,
|
2010-07-28 07:07:05 +00:00
|
|
|
'display_currency':self._display_currency
|
2008-07-22 15:11:28 +00:00
|
|
|
})
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-07-13 03:39:27 +00:00
|
|
|
def set_context(self, objects, data, ids, report_type=None): # Improve move to common default?
|
2010-06-29 13:09:45 +00:00
|
|
|
new_ids = ids
|
2010-07-09 04:18:45 +00:00
|
|
|
self.query_get_clause = ''
|
2010-06-29 13:09:45 +00:00
|
|
|
if (data['model'] == 'ir.ui.menu'):
|
|
|
|
new_ids = 'active_ids' in data['form'] and data['form']['active_ids'] or []
|
2010-07-09 04:18:45 +00:00
|
|
|
self.query_get_clause = 'AND '
|
|
|
|
self.query_get_clause += data['form']['query_line'] or ''
|
|
|
|
objects = self.pool.get('account.journal.period').browse(self.cr, self.uid, new_ids)
|
2010-07-09 13:06:52 +00:00
|
|
|
if new_ids:
|
|
|
|
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)
|
2010-07-09 04:18:45 +00:00
|
|
|
return super(journal_print, self).set_context(objects, data, ids, report_type)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
# returns a list of period objs
|
|
|
|
def periods(self, journal_period_objs):
|
|
|
|
dic = {}
|
|
|
|
def filter_unique(o):
|
|
|
|
key = o.period_id.id
|
|
|
|
res = key in dic
|
|
|
|
if not res:
|
|
|
|
dic[key] = True
|
|
|
|
return not res
|
|
|
|
filtered_objs = filter(filter_unique, journal_period_objs)
|
|
|
|
return map(lambda x: x.period_id, filtered_objs)
|
2008-10-23 10:30:52 +00:00
|
|
|
|
|
|
|
def lines(self, period_id, journal_id=[]):
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.journal_ids:
|
|
|
|
return []
|
2010-07-28 11:01:33 +00:00
|
|
|
self.cr.execute('SELECT j.code, j.name, l.amount_currency,c.code AS currency_code,l.currency_id , '
|
2010-06-10 13:34:19 +00:00
|
|
|
'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) '
|
2010-07-15 07:22:06 +00:00
|
|
|
'LEFT JOIN res_currency c on (l.currency_id=c.id)'
|
2010-07-09 04:18:45 +00:00
|
|
|
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +''
|
2010-07-28 11:01:33 +00:00
|
|
|
'GROUP BY j.id, j.code, j.name, l.amount_currency,c.code,l.currency_id ',
|
2010-06-10 13:34:19 +00:00
|
|
|
(period_id, tuple(self.journal_ids)))
|
2010-07-28 11:01:33 +00:00
|
|
|
|
2010-07-13 03:39:27 +00:00
|
|
|
return self.cr.dictfetchall()
|
2010-07-15 07:22:06 +00:00
|
|
|
def _set_get_account_currency_code(self, account_id):
|
|
|
|
self.cr.execute("SELECT c.code as code "\
|
|
|
|
"FROM res_currency c,account_account as ac "\
|
|
|
|
"WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id))
|
|
|
|
result = self.cr.fetchone()
|
|
|
|
if result:
|
|
|
|
self.account_currency = result[0]
|
|
|
|
else:
|
|
|
|
self.account_currency = False
|
2010-07-09 04:18:45 +00:00
|
|
|
|
2010-07-20 06:19:44 +00:00
|
|
|
def _get_account(self, data):
|
|
|
|
if data['model']=='account.journal.period':
|
|
|
|
return self.pool.get('account.journal.period').browse(self.cr, self.uid, data['id']).company_id.name
|
2010-07-20 11:51:13 +00:00
|
|
|
return super(journal_print ,self)._get_account(data)
|
2010-07-20 06:19:44 +00:00
|
|
|
|
|
|
|
def _get_fiscalyear(self, data):
|
|
|
|
if data['model']=='account.journal.period':
|
|
|
|
return self.pool.get('account.journal.period').browse(self.cr, self.uid, data['id']).fiscalyear_id.name
|
2010-07-20 11:51:13 +00:00
|
|
|
return super(journal_print ,self)._get_fiscalyear(data)
|
|
|
|
|
2010-07-28 07:07:05 +00:00
|
|
|
def _display_currency(self, data):
|
2010-07-20 06:57:32 +00:00
|
|
|
if data['model']=='account.journal.period':
|
2010-07-27 09:00:53 +00:00
|
|
|
return True
|
2010-07-20 11:51:13 +00:00
|
|
|
return data['form']['amount_currency']
|
2010-07-26 09:06:55 +00:00
|
|
|
|
2010-07-15 13:48:51 +00:00
|
|
|
report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print, header='internal')
|
2010-07-13 03:39:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|