bzr revid: fp@tinyerp.com-20081017082543-k24lrydp6aj2s8e2
This commit is contained in:
Fabien Pinckaers 2008-10-17 10:25:43 +02:00
parent da43d9de51
commit b2c5389d1f
3 changed files with 116 additions and 87 deletions

View File

@ -46,7 +46,7 @@ dates_form = '''<?xml version="1.0"?>
dates_fields = {
'date_from': {'string':"Start date",'type':'date','required':True ,'default': lambda *a: time.strftime('%Y-01-01')},
'date_to': {'string':"End date",'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'display_account':{'string':"Display accounts",'type':'selection','selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]}
'display_account':{'string':"Filter on Accounts",'type':'selection','selection':[('bal_mouvement','With Entries'),('bal_all','All Accounts'),('bal_solde','With Balance Different Than 0')]}
}
@ -61,8 +61,12 @@ period_form = '''<?xml version="1.0"?>
period_fields = {
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'},
'fiscalyear': {
'string':'Fiscal year',
'type':'many2one',
'relation':'account.fiscalyear',
'help':'Keep empty for all open fiscal year'
},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
'display_account':{'string':"Display accounts ",'type':'selection','selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]}
}

View File

@ -35,76 +35,84 @@ from mx.DateTime import *
_aged_trial_form = """<?xml version="1.0"?>
<form string="Aged Trial Balance">
<field name="company_id"/>
<newline/>
<field name="date1"/>
<field name="period_length"/>
<newline/>
<field name="result_selection"/>
<newline/>
<field name="direction_selection"/>
<field name="company_id"/>
<newline/>
<field name="date1"/>
<field name="period_length"/>
<newline/>
<field name="result_selection"/>
<newline/>
<field name="direction_selection"/>
</form>"""
_aged_trial_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'period_length': {'string': 'Period length (days)', 'type': 'integer', 'required': True, 'default': lambda *a:30},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'result_selection':{'string':"Display partner",'type':'selection','selection':[('customer','Debiteur'),('supplier','Creancier'),('all','Tous')]},
'direction_selection':{'string':"Display aged balance of",'type':'selection','selection':[('past','Due amount'),('future','Not due amount')]},
}
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'period_length': {'string': 'Period length (days)', 'type': 'integer', 'required': True, 'default': lambda *a:30},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'result_selection':{
'string':"Filter on Partners",
'type':'selection',
'selection':[('customer','Customer'),('supplier','Supplier'),('all','All')],
'required':True,
'default': lambda *a: 'customer',
},
'direction_selection':{
'string':"Analysis Direction",
'type':'selection',
'selection':[('past','Past'),('future','Future')],
'required':True,
'default': lambda *a: 'past',
},
}
def _calc_dates(self, cr, uid, data, context):
res = {}
period_length = data['form']['period_length']
if period_length<=0:
raise wizard.except_wizard('UserError', 'You must enter a period length that cannot be 0 or below !')
start = datetime.date.fromtimestamp(time.mktime(time.strptime(data['form']['date1'],"%Y-%m-%d")))
start = DateTime(int(start.year),int(start.month),int(start.day))
if data['form']['direction_selection'] == 'past':
for i in range(5)[::-1]:
stop = start - RelativeDateTime(days=period_length)
res[str(i)] = {
'name' : str((5-(i+1))*period_length) + '-' + str((5-i)*period_length),
'stop': start.strftime('%Y-%m-%d'),
'start' : stop.strftime('%Y-%m-%d'),
}
start = stop - RelativeDateTime(days=1)
else:
for i in range(5):
stop = start + RelativeDateTime(days=period_length)
res[str(5-(i+1))] = {
'name' : str((i)*period_length)+'-'+str((i+1)*period_length),
'start': start.strftime('%Y-%m-%d'),
'stop' : stop.strftime('%Y-%m-%d'),
}
start = stop + RelativeDateTime(days=1)
return res
res = {}
period_length = data['form']['period_length']
if period_length<=0:
raise wizard.except_wizard('UserError', 'You must enter a period length that cannot be 0 or below !')
start = datetime.date.fromtimestamp(time.mktime(time.strptime(data['form']['date1'],"%Y-%m-%d")))
start = DateTime(int(start.year),int(start.month),int(start.day))
if data['form']['direction_selection'] == 'past':
for i in range(5)[::-1]:
stop = start - RelativeDateTime(days=period_length)
res[str(i)] = {
'name' : str((5-(i+1))*period_length) + '-' + str((5-i)*period_length),
'stop': start.strftime('%Y-%m-%d'),
'start' : stop.strftime('%Y-%m-%d'),
}
start = stop - RelativeDateTime(days=1)
else:
for i in range(5):
stop = start + RelativeDateTime(days=period_length)
res[str(5-(i+1))] = {
'name' : str((i)*period_length)+'-'+str((i+1)*period_length),
'start': start.strftime('%Y-%m-%d'),
'stop' : stop.strftime('%Y-%m-%d'),
}
start = stop + RelativeDateTime(days=1)
return res
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':_aged_trial_form, 'fields':_aged_trial_fields, 'state':[('end','Cancel'),('print','Print Aged Trial Balance')]},
},
'print': {
'actions': [_calc_dates],
'result': {'type':'print', 'report':'account.aged_trial_balance', 'state':'end'},
},
}
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':_aged_trial_form, 'fields':_aged_trial_fields, 'state':[('end','Cancel'),('print','Print Aged Trial Balance')]},
},
'print': {
'actions': [_calc_dates],
'result': {'type':'print', 'report':'account.aged_trial_balance', 'state':'end'},
},
}
wizard_report('account.aged.trial.balance')

View File

@ -30,32 +30,49 @@ import wizard
import pooler
period_form = '''<?xml version="1.0"?>
<form string="Select period" colspan = "4">
<group colspan = "4" >
<field name="company_id" colspan = "4"/>
<field name="state" required="True"/>
</group>
<newline/>
<group attrs="{'invisible':[('state','=','byperiod')]}" colspan = "4">
<field name="date1"/>
<field name="date2"/>
</group>
<newline/>
<group attrs="{'invisible':[('state','=','bydate')]}" colspan = "4">
<field name="fiscalyear" colspan = "4"/>
<field name="periods" colspan = "4"/>
</group>
<form string="Select period">
<field name="company_id"/>
<field name="result_selection"/>
<field name="soldeinit"/>
<newline/>
<field name="fiscalyear"/>
<label colspan="2" string="(Keep empty for all open fiscal years)" align="0.0"/>
<newline/>
<separator string="Filters" colspan="4"/>
<field name="state" required="True"/>
<newline/>
<group colspan="4">
<group attrs="{'invisible':[('state','=','byperiod')]}" colspan="2">
<separator string="Date Filter" colspan="4"/>
<field name="date1"/>
<newline/>
<field name="date2"/>
</group>
<group attrs="{'invisible':[('state','=','bydate')]}" colspan="2">
<separator string="Filter on Periods" colspan="4"/>
<field name="periods" colspan="4" nolabel="1"/>
</group>
</group>
</form>'''
period_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'state':{'string':"Report Type",'type':'selection','selection':[('bydate','By Date'),('byperiod','By Period')],'default': lambda *a:'byperiod' },
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year','states':{'none':[('readonly',True)],'bydate':[('readonly',True)]}},
'state':{
'string':"Date/Period Filter",
'type':'selection',
'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
'default': lambda *a:'none'
},
'fiscalyear': {
'string':'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
'help': 'Keep empty for all open fiscal year'
},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty','states':{'none':[('readonly',True)],'bydate':[('readonly',True)]}},
'result_selection':{'string':" Partner",'type':'selection','selection':[('customer','Debiteur'),('supplier','Creancier'),('all','Tous')]},
'result_selection':{
'string':"Partner",
'type':'selection',
'selection':[('customer','Receivable Accounts'),('supplier','Payable Accounts'),('all','Receivable and Payable Accounts')],
'required':True
},
'soldeinit':{'string':" Inclure les soldes initiaux",'type':'boolean'},
'date1': {'string':' Start date', 'type':'date', 'required':True,'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End date', 'type':'date', 'required':True,'default': lambda *a: time.strftime('%Y-%m-%d')},