2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2010-04-07 06:41:53 +00:00
#
2009-10-14 11:15:34 +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-06-16 11:00:21 +00:00
#
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.
2006-12-07 13:41:40 +00:00
#
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.
2006-12-07 13:41:40 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-04-07 06:41:53 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
import time
2010-07-09 04:17:43 +00:00
2010-06-29 13:48:46 +00:00
import pooler
2010-07-10 07:21:03 +00:00
from account_journal_common_default import account_journal_common_default
2006-12-07 13:41:40 +00:00
from report import report_sxw
#
# Use period and Journal for selection or resources
#
2010-07-10 07:21:03 +00:00
class journal_print ( report_sxw . rml_parse , account_journal_common_default ) :
2010-06-28 14:52:36 +00:00
2010-07-09 04:17:43 +00:00
def set_context ( self , objects , data , ids , report_type = None ) :
2010-06-28 14:52:36 +00:00
new_ids = ids
2010-07-09 04:17:43 +00:00
self . query_get_clause = ' '
self . sort_selection = ' date '
2010-06-28 14:52:36 +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:17:43 +00:00
self . query_get_clause = ' AND '
self . query_get_clause + = data [ ' form ' ] [ ' query_line ' ] or ' '
self . sort_selection = data [ ' form ' ] [ ' sort_selection ' ]
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:17:43 +00:00
return super ( journal_print , self ) . set_context ( objects , data , ids , report_type )
2010-06-28 14:52:36 +00:00
2010-07-09 04:17:43 +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 ,
' sum_debit ' : self . _sum_debit ,
2010-06-29 13:48:46 +00:00
' sum_credit ' : self . _sum_credit ,
' get_start_period ' : self . get_start_period ,
' get_end_period ' : self . get_end_period ,
2010-07-12 05:42:20 +00:00
' get_account ' : self . _get_account ,
' get_filter ' : self . _get_filter
2008-07-22 15:11:28 +00:00
} )
2006-12-07 13:41:40 +00:00
2010-07-09 04:17:43 +00:00
def lines ( self , period_id , journal_id = [ ] ) :
2010-04-07 06:41:53 +00:00
obj_jperiod = self . pool . get ( ' account.journal.period ' )
obj_mline = self . pool . get ( ' account.move.line ' )
2010-07-09 04:17:43 +00:00
self . cr . execute ( ' update account_journal_period set state= %s where journal_id IN %s and period_id= %s and state= %s ' , ( ' printed ' , self . journal_ids , period_id , ' draft ' ) )
2008-07-22 15:11:28 +00:00
self . cr . commit ( )
2010-07-09 04:17:43 +00:00
self . cr . execute ( ' SELECT id FROM account_move_line l WHERE period_id= %s AND journal_id IN %s ' + self . query_get_clause + ' ORDER BY ' + self . sort_selection + ' ' , ( period_id , self . journal_ids ) )
2008-07-22 15:11:28 +00:00
ids = map ( lambda x : x [ 0 ] , self . cr . fetchall ( ) )
2010-04-07 06:41:53 +00:00
return obj_mline . browse ( self . cr , self . uid , ids )
2006-12-07 13:41:40 +00:00
2010-07-10 12:38:37 +00:00
# def _sum_debit(self, period_id, journal_id=[]):
# self.cr.execute('SELECT SUM(debit) FROM account_move_line l WHERE period_id=%s AND journal_id IN %s '+ self.query_get_clause +'', (period_id, self.journal_ids))
# 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 l WHERE period_id=%s AND journal_id IN %s '+ self.query_get_clause +'', (period_id, self.journal_ids))
# return self.cr.fetchone()[0] or 0.0
2010-07-09 04:17:43 +00:00
2010-07-10 12:38:37 +00:00
# def get_start_period(self, form):
# if 'period_from' in form and form['period_from']:
# return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_from']).name
# return ''
#
# def get_end_period(self, form):
# if 'period_to' in form and form['period_to']:
# return pooler.get_pool(self.cr.dbname).get('account.period').browse(self.cr,self.uid,form['period_to']).name
# return ''
2010-07-09 04:17:43 +00:00
2010-07-10 12:38:37 +00:00
# def get_account(self, form):
# if form and 'chart_account_id' in form and form['chart_account_id']:
# return pooler.get_pool(self.cr.dbname).get('account.account').browse(self.cr,self.uid,form['chart_account_id']).name
# return ''
2010-04-07 06:41:53 +00:00
report_sxw . report_sxw ( ' report.account.journal.period.print ' , ' account.journal.period ' , ' addons/account/report/account_journal.rml ' , parser = journal_print , header = False )
2008-07-23 14:41:47 +00:00
2010-07-09 04:17:43 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: