@ -3,7 +3,7 @@
# Module Writen to OpenERP, Open Source Management Solution
# Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved
# All Rights Reserved
############### Credits######################################################
# Credits######################################################
# Coded by: Humberto Arocha humberto@openerp.com.ve
# Coded by: Humberto Arocha humberto@openerp.com.ve
# Angelica Barrios angelicaisabelb@gmail.com
# Angelica Barrios angelicaisabelb@gmail.com
# Jordi Esteve <jesteve@zikzakmedia.com>
# Jordi Esteve <jesteve@zikzakmedia.com>
@ -26,111 +26,117 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
##############################################################################
from osv import osv , fields
from osv import osv , fields
import pooler
import pooler
import time
import time
from tools.translate import _
from tools.translate import _
class account_financial_report ( osv . osv ) :
class account_financial_report ( osv . osv ) :
_name = " afr "
_name = " afr "
_columns = {
_columns = {
' name ' : fields . char ( ' Name ' , size = 128 , required = True ) ,
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True ) ,
' name ' : fields . char ( ' Name ' , size = 128 , required = True ) ,
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True ) ,
' currency_id ' : fields . many2one ( ' res.currency ' , ' Currency ' , help = " Currency at which this report will be expressed. If not selected will be used the one set in the company " ) ,
' currency_id ' : fields . many2one ( ' res.currency ' , ' Currency ' , help = " Currency at which this report will be expressed. If not selected will be used the one set in the company " ) ,
' inf_type ' : fields . selection ( [ ( ' BS ' , ' Balance Sheet ' ) , ( ' IS ' , ' Income Statement ' ) ] , ' Type ' , required = True ) ,
' columns ' : fields . selection ( [ ( ' one ' , ' End. Balance ' ) , ( ' two ' , ' Debit | Credit ' ) , ( ' four ' , ' Initial | Debit | Credit | YTD ' ) , ( ' five ' , ' Initial | Debit | Credit | Period | YTD ' ) , ( ' qtr ' , " 4 QTR ' s | YTD " ) , ( ' thirteen ' , ' 12 Months | YTD ' ) ] , ' Columns ' , required = True ) ,
' display_account ' : fields . selection ( [ ( ' all ' , ' All Accounts ' ) , ( ' bal ' , ' With Balance ' ) , ( ' mov ' , ' With movements ' ) , ( ' bal_mov ' , ' With Balance / Movements ' ) ] , ' Display accounts ' ) ,
' display_account_level ' : fields . integer ( ' Up to level ' , help = ' Display accounts up to this level (0 to show all) ' ) ,
' account_ids ' : fields . many2many ( ' account.account ' , ' afr_account_rel ' , ' afr_id ' , ' account_id ' , ' Root accounts ' , required = True ) ,
' fiscalyear_id ' : fields . many2one ( ' account.fiscalyear ' , ' Fiscal year ' , help = ' Fiscal Year for this report ' , required = True ) ,
' period_ids ' : fields . many2many ( ' account.period ' , ' afr_period_rel ' , ' afr_id ' , ' period_id ' , ' Periods ' , help = ' All periods in the fiscal year if empty ' ) ,
' inf_type ' : fields . selection ( [ ( ' BS ' , ' Balance Sheet ' ) , ( ' IS ' , ' Income Statement ' ) ] , ' Type ' , required = True ) ,
' columns ' : fields . selection ( [ ( ' one ' , ' End. Balance ' ) , ( ' two ' , ' Debit | Credit ' ) , ( ' four ' , ' Initial | Debit | Credit | YTD ' ) , ( ' five ' , ' Initial | Debit | Credit | Period | YTD ' ) , ( ' qtr ' , " 4 QTR ' s | YTD " ) , ( ' thirteen ' , ' 12 Months | YTD ' ) ] , ' Columns ' , required = True ) ,
' display_account ' : fields . selection ( [ ( ' all ' , ' All Accounts ' ) , ( ' bal ' , ' With Balance ' ) , ( ' mov ' , ' With movements ' ) , ( ' bal_mov ' , ' With Balance / Movements ' ) ] , ' Display accounts ' ) ,
' display_account_level ' : fields . integer ( ' Up to level ' , help = ' Display accounts up to this level (0 to show all) ' ) ,
' account_ids ' : fields . many2many ( ' account.account ' , ' afr_account_rel ' , ' afr_id ' , ' account_id ' , ' Root accounts ' , required = True ) ,
' fiscalyear_id ' : fields . many2one ( ' account.fiscalyear ' , ' Fiscal year ' , help = ' Fiscal Year for this report ' , required = True ) ,
' period_ids ' : fields . many2many ( ' account.period ' , ' afr_period_rel ' , ' afr_id ' , ' period_id ' , ' Periods ' , help = ' All periods in the fiscal year if empty ' ) ,
' analytic_ledger ' : fields . boolean ( ' Analytic Ledger ' , help = " Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and ' Initial | Debit | Credit | YTD ' are selected " ) ,
' analytic_ledger ' : fields . boolean ( ' Analytic Ledger ' , help = " Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and ' Initial | Debit | Credit | YTD ' are selected " ) ,
' tot_check ' : fields . boolean ( ' Summarize? ' , help = ' Checking will add a new line at the end of the Report which will Summarize Columns in Report ' ) ,
' tot_check ' : fields . boolean ( ' Summarize? ' , help = ' Checking will add a new line at the end of the Report which will Summarize Columns in Report ' ) ,
' lab_str ' : fields . char ( ' Description ' , help = ' Description for the Summary ' , size = 128 ) ,
' lab_str ' : fields . char ( ' Description ' , help = ' Description for the Summary ' , size = 128 ) ,
#~ Deprecated fields
#~ Deprecated fields
' filter ' : fields . selection ( [ ( ' bydate ' , ' By Date ' ) , ( ' byperiod ' , ' By Period ' ) , ( ' all ' , ' By Date and Period ' ) , ( ' none ' , ' No Filter ' ) ] , ' Date/Period Filter ' ) ,
' filter ' : fields . selection ( [ ( ' bydate ' , ' By Date ' ) , ( ' byperiod ' , ' By Period ' ) , ( ' all ' , ' By Date and Period ' ) , ( ' none ' , ' No Filter ' ) ] , ' Date/Period Filter ' ) ,
' date_to ' : fields . date ( ' End date ' ) ,
' date_to ' : fields . date ( ' End date ' ) ,
' date_from ' : fields . date ( ' Start date ' ) ,
' date_from ' : fields . date ( ' Start date ' ) ,
}
}
_defaults = {
_defaults = {
' display_account_level ' : lambda * a : 0 ,
' display_account_level ' : lambda * a : 0 ,
' inf_type ' : lambda * a : ' BS ' ,
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' account.invoice ' , context = c ) ,
' inf_type ' : lambda * a : ' BS ' ,
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' account.invoice ' , context = c ) ,
' fiscalyear_id ' : lambda self , cr , uid , c : self . pool . get ( ' account.fiscalyear ' ) . find ( cr , uid ) ,
' fiscalyear_id ' : lambda self , cr , uid , c : self . pool . get ( ' account.fiscalyear ' ) . find ( cr , uid ) ,
' display_account ' : lambda * a : ' bal_mov ' ,
' columns ' : lambda * a : ' five ' ,
' display_account ' : lambda * a : ' bal_mov ' ,
' columns ' : lambda * a : ' five ' ,
' date_from ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) ,
' date_from ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) ,
' date_to ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) ,
' date_to ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) ,
' filter ' : lambda * a : ' byperiod ' ,
' filter ' : lambda * a : ' byperiod ' ,
}
}
def copy ( self , cr , uid , id , defaults , context = None ) :
def copy ( self , cr , uid , id , defaults , context = None ) :
if context is None :
if context is None :
context = { }
context = { }
previous_name = self . browse ( cr , uid , id , context = context ) . name
previous_name = self . browse ( cr , uid , id , context = context ) . name
new_name = _ ( ' Copy of %s ' ) % previous_name
lst = self . search ( cr , uid , [ ( ' name ' , ' like ' , new_name ) ] , context = context )
new_name = _ ( ' Copy of %s ' ) % previous_name
lst = self . search ( cr , uid , [ (
' name ' , ' like ' , new_name ) ] , context = context )
if lst :
if lst :
new_name = ' %s ( %s ) ' % ( new_name , len ( lst ) + 1 )
new_name = ' %s ( %s ) ' % ( new_name , len ( lst ) + 1 )
defaults [ ' name ' ] = new_name
defaults [ ' name ' ] = new_name
return super ( account_financial_report , self ) . copy ( cr , uid , id , defaults , context = context )
return super ( account_financial_report , self ) . copy ( cr , uid , id , defaults , context = context )
def onchange_inf_type ( self , cr , uid , ids , inf_type , context = None ) :
def onchange_inf_type ( self , cr , uid , ids , inf_type , context = None ) :
if context is None :
if context is None :
context = { }
context = { }
res = { ' value ' : { } }
res = { ' value ' : { } }
if inf_type != ' BS ' :
if inf_type != ' BS ' :
res [ ' value ' ] . update ( { ' analytic_ledger ' : False } )
res [ ' value ' ] . update ( { ' analytic_ledger ' : False } )
return res
return res
def onchange_columns ( self , cr , uid , ids , columns , fiscalyear_id , period_ids , context = None ) :
def onchange_columns ( self , cr , uid , ids , columns , fiscalyear_id , period_ids , context = None ) :
if context is None :
if context is None :
context = { }
context = { }
res = { ' value ' : { } }
res = { ' value ' : { } }
if columns != ' four ' :
if columns != ' four ' :
res [ ' value ' ] . update ( { ' analytic_ledger ' : False } )
res [ ' value ' ] . update ( { ' analytic_ledger ' : False } )
if columns in ( ' qtr ' , ' thirteen ' ) :
if columns in ( ' qtr ' , ' thirteen ' ) :
p_obj = self . pool . get ( " account.period " )
p_obj = self . pool . get ( " account.period " )
period_ids = p_obj . search ( cr , uid , [ ( ' fiscalyear_id ' , ' = ' , fiscalyear_id ) , ( ' special ' , ' = ' , False ) ] , context = context )
res [ ' value ' ] . update ( { ' period_ids ' : period_ids } )
period_ids = p_obj . search ( cr , uid , [ ( ' fiscalyear_id ' , ' = ' , fiscalyear_id ) , (
' special ' , ' = ' , False ) ] , context = context )
res [ ' value ' ] . update ( { ' period_ids ' : period_ids } )
else :
else :
res [ ' value ' ] . update ( { ' period_ids ' : [ ] } )
res [ ' value ' ] . update ( { ' period_ids ' : [ ] } )
return res
return res
def onchange_analytic_ledger ( self , cr , uid , ids , company_id , analytic_ledger , context = None ) :
def onchange_analytic_ledger ( self , cr , uid , ids , company_id , analytic_ledger , context = None ) :
if context is None :
if context is None :
context = { }
context = { }
context [ ' company_id ' ] = company_id
res = { ' value ' : { } }
cur_id = self . pool . get ( ' res.company ' ) . browse ( cr , uid , company_id , context = context ) . currency_id . id
res [ ' value ' ] . update ( { ' currency_id ' : cur_id } )
context [ ' company_id ' ] = company_id
res = { ' value ' : { } }
cur_id = self . pool . get ( ' res.company ' ) . browse (
cr , uid , company_id , context = context ) . currency_id . id
res [ ' value ' ] . update ( { ' currency_id ' : cur_id } )
return res
return res
def onchange_company_id ( self , cr , uid , ids , company_id , context = None ) :
def onchange_company_id ( self , cr , uid , ids , company_id , context = None ) :
if context is None :
if context is None :
context = { }
context = { }
context [ ' company_id ' ] = company_id
res = { ' value ' : { } }
context [ ' company_id ' ] = company_id
res = { ' value ' : { } }
if not company_id :
if not company_id :
return res
return res
cur_id = self . pool . get ( ' res.company ' ) . browse ( cr , uid , company_id , context = context ) . currency_id . id
fy_id = self . pool . get ( ' account.fiscalyear ' ) . find ( cr , uid , context = context )
res [ ' value ' ] . update ( { ' fiscalyear_id ' : fy_id } )
res [ ' value ' ] . update ( { ' currency_id ' : cur_id } )
res [ ' value ' ] . update ( { ' account_ids ' : [ ] } )
res [ ' value ' ] . update ( { ' period_ids ' : [ ] } )
cur_id = self . pool . get ( ' res.company ' ) . browse (
cr , uid , company_id , context = context ) . currency_id . id
fy_id = self . pool . get ( ' account.fiscalyear ' ) . find (
cr , uid , context = context )
res [ ' value ' ] . update ( { ' fiscalyear_id ' : fy_id } )
res [ ' value ' ] . update ( { ' currency_id ' : cur_id } )
res [ ' value ' ] . update ( { ' account_ids ' : [ ] } )
res [ ' value ' ] . update ( { ' period_ids ' : [ ] } )
return res
return res