@ -30,10 +30,11 @@
import time
from osv import fields , osv
from lxml import etree
from tools.translate import _
from datetime import datetime
from openerp.osv import fields , orm
from openerp.tools.translate import _
def previous_year_date ( date , nb_prev = 1 ) :
if not date :
@ -44,7 +45,8 @@ def previous_year_date(date, nb_prev=1):
day = parsed_date . day )
return previous_date
class AccountBalanceCommonWizard ( osv . osv_memory ) :
class AccountBalanceCommonWizard ( orm . TransientModel ) :
""" Will launch trial balance report and pass required args """
_inherit = " account.common.account.report "
@ -63,7 +65,7 @@ class AccountBalanceCommonWizard(osv.osv_memory):
M2O_DYNAMIC_FIELDS = [ f % index for f in [ " comp %s _fiscalyear_id " ,
" comp %s _period_from " ,
" comp %s _period_to " , ]
" comp %s _period_to " ]
for index in range ( COMPARISON_LEVEL ) ]
SIMPLE_DYNAMIC_FIELDS = [ f % index for f in [ " comp %s _filter " ,
" comp %s _date_from " ,
@ -83,17 +85,21 @@ class AccountBalanceCommonWizard(osv.osv_memory):
' filter ' : fields . selection ( [ ( ' filter_no ' , ' No Filters ' ) ,
( ' filter_date ' , ' Date ' ) ,
( ' filter_period ' , ' Periods ' ) ,
( ' filter_opening ' , ' Opening Only ' ) ] , " Filter by " , required = True , help = ' Filter by date : no opening balance will be displayed. (opening balance can only be calculated based on period to be correct). ' ) ,
( ' filter_opening ' , ' Opening Only ' ) ] ,
" Filter by " ,
required = True ,
help = ' Filter by date : no opening balance will be displayed. '
' (opening balance can only be calculated based on period to be correct). ' ) ,
}
for index in range ( COMPARISON_LEVEL ) :
_columns . update (
{ " comp %s _filter " % ( index , ) : fields . selection ( COMPARE_SELECTION , string = ' Compare By ' , required = True ) ,
" comp %s _fiscalyear_id " % ( index , ) : fields . many2one ( ' account.fiscalyear ' , ' Fiscal Year ' ) ,
" comp %s _period_from " % ( index , ) : fields . many2one ( ' account.period ' , ' Start Period ' ) ,
" comp %s _period_to " % ( index , ) : fields . many2one ( ' account.period ' , ' End Period ' ) ,
" comp %s _date_from " % ( index , ) : fields . date ( " Start Date " ) ,
" comp %s _date_to " % ( index , ) : fields . date ( " End Date " ) , } )
{ " comp %s _filter " % index : fields . selection ( COMPARE_SELECTION , string = ' Compare By ' , required = True ) ,
" comp %s _fiscalyear_id " % index : fields . many2one ( ' account.fiscalyear ' , ' Fiscal Year ' ) ,
" comp %s _period_from " % index : fields . many2one ( ' account.period ' , ' Start Period ' ) ,
" comp %s _period_to " % index : fields . many2one ( ' account.period ' , ' End Period ' ) ,
" comp %s _date_from " % index : fields . date ( " Start Date " ) ,
" comp %s _date_to " % index : fields . date ( " End Date " ) } )
_defaults = {
' account_ids ' : _get_account_ids ,
@ -141,9 +147,13 @@ class AccountBalanceCommonWizard(osv.osv_memory):
if placeholder :
placeholder = placeholder [ 0 ]
for index in range ( self . COMPARISON_LEVEL ) :
page = etree . Element ( ' page ' , { ' name ' : " comp %s " % ( index , ) , ' string ' : _ ( " Comparison %s " ) % ( index + 1 , ) } )
page = etree . Element (
' page ' ,
{ ' name ' : " comp %s " % index ,
' string ' : _ ( " Comparison %s " ) % ( index + 1 , ) } )
group = etree . Element ( ' group ' )
page . append ( group )
def modifiers_and_append ( elem ) :
orm . setup_modifiers ( elem )
group . append ( elem )
@ -159,7 +169,6 @@ class AccountBalanceCommonWizard(osv.osv_memory):
" { ' required ' : [( ' comp %(index)s _filter ' , ' in ' ,( ' filter_year ' , ' filter_opening ' ))], " \
" ' invisible ' : [( ' comp %(index)s _filter ' , ' not in ' ,( ' filter_year ' , ' filter_opening ' ))]} " % { ' index ' : index } } ) )
dates_attrs = " { ' required ' : [( ' comp %(index)s _filter ' , ' = ' , ' filter_date ' )], " \
" ' invisible ' : [( ' comp %(index)s _filter ' , ' != ' , ' filter_date ' )]} " % { ' index ' : index }
modifiers_and_append ( etree . Element (
@ -258,15 +267,28 @@ class AccountBalanceCommonWizard(osv.osv_memory):
date_to_field = " comp %s _date_to " % ( index , )
if comp_filter == ' filter_no ' :
res [ ' value ' ] = { fy_id_field : False , period_from_field : False , period_to_field : False , date_from_field : False , date_to_field : False }
res [ ' value ' ] = {
fy_id_field : False ,
period_from_field : False ,
period_to_field : False ,
date_from_field : False ,
date_to_field : False
}
if comp_filter in ( ' filter_year ' , ' filter_opening ' ) :
res [ ' value ' ] = { fy_id_field : last_fiscalyear_id , period_from_field : False , period_to_field : False , date_from_field : False , date_to_field : False }
res [ ' value ' ] = {
fy_id_field : last_fiscalyear_id ,
period_from_field : False ,
period_to_field : False ,
date_from_field : False ,
date_to_field : False
}
if comp_filter == ' filter_date ' :
dates = { }
if main_filter == ' filter_date ' :
dates = {
' date_start ' : previous_year_date ( start_date , index + 1 ) . strftime ( ' % Y- % m- %d ' ) ,
' date_stop ' : previous_year_date ( stop_date , index + 1 ) . strftime ( ' % Y- % m- %d ' ) , }
' date_stop ' : previous_year_date ( stop_date , index + 1 ) . strftime ( ' % Y- % m- %d ' ) ,
}
elif last_fiscalyear_id :
dates = fy_obj . read ( cr , uid , last_fiscalyear_id , [ ' date_start ' , ' date_stop ' ] , context = context )
@ -323,5 +345,3 @@ class AccountBalanceCommonWizard(osv.osv_memory):
vals [ ' max_comparison ' ] = self . COMPARISON_LEVEL
data [ ' form ' ] . update ( vals )
return data
AccountBalanceCommonWizard ( )