[IMP] account: Account balance report change with osv memory (ref: SBH)
bzr revid: mra@mra-laptop-20100625131849-e7v7urns302aaoia
This commit is contained in:
@@ -56,8 +56,8 @@ class account_balance(report_sxw.rml_parse):
|
||||
return True
|
||||
def get_fiscalyear(self, form):
|
||||
res=[]
|
||||
if form.has_key('fiscalyear'):
|
||||
fisc_id = form['fiscalyear']
|
||||
if form.has_key('fiscalyear_id'):
|
||||
fisc_id = form['fiscalyear_id']
|
||||
if not (fisc_id):
|
||||
return ''
|
||||
self.cr.execute("select name from account_fiscalyear where id = %s" , (int(fisc_id),))
|
||||
@@ -84,7 +84,7 @@ class account_balance(report_sxw.rml_parse):
|
||||
else:
|
||||
result+=r.name+", "
|
||||
|
||||
return str(result and result[:-1]) or ''
|
||||
return str(result and result[:-1]) or 'ALL'
|
||||
|
||||
|
||||
def lines(self, form, ids={}, done=None, level=1):
|
||||
@@ -100,14 +100,27 @@ class account_balance(report_sxw.rml_parse):
|
||||
res={}
|
||||
result_acc=[]
|
||||
ctx = self.context.copy()
|
||||
ctx['state'] = form['context'].get('state','all')
|
||||
ctx['fiscalyear'] = form['fiscalyear']
|
||||
if form['state']=='byperiod' :
|
||||
|
||||
ctx['fiscalyear'] = form['fiscalyear_id']
|
||||
if form['filter'] == 'filter_period':
|
||||
periods = form['periods']
|
||||
if not periods:
|
||||
sql = """
|
||||
Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s
|
||||
"""
|
||||
sqlargs = (form['fiscalyear'],)
|
||||
else:
|
||||
sql = """
|
||||
Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s
|
||||
"""
|
||||
sqlargs = (tuple(periods),)
|
||||
self.cr.execute(sql, sqlargs)
|
||||
res = self.cr.dictfetchall()
|
||||
ctx['periods'] = form['periods']
|
||||
elif form['state']== 'bydate':
|
||||
elif form['filter'] == 'filter_date':
|
||||
ctx['date_from'] = form['date_from']
|
||||
ctx['date_to'] = form['date_to']
|
||||
elif form['state'] == 'all' :
|
||||
elif form['filter'] == 'filter_no' :
|
||||
ctx['periods'] = form['periods']
|
||||
ctx['date_from'] = form['date_from']
|
||||
ctx['date_to'] = form['date_to']
|
||||
@@ -115,6 +128,7 @@ class account_balance(report_sxw.rml_parse):
|
||||
# def cmp_code(x, y):
|
||||
# return cmp(x.code, y.code)
|
||||
# accounts.sort(cmp_code)
|
||||
|
||||
child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)
|
||||
if child_ids:
|
||||
ids = child_ids
|
||||
|
||||
@@ -24,115 +24,42 @@ from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_balance_report(osv.osv_memory):
|
||||
"""
|
||||
This wizard will provide the account balance report by periods, between any two dates.
|
||||
"""
|
||||
|
||||
_inherit = "account.common.report"
|
||||
_name = 'account.balance.report'
|
||||
_description = 'Account Balance Report'
|
||||
_columns = {
|
||||
'Account_list': fields.many2one('account.account', 'Chart account',
|
||||
required=True, domain = [('parent_id','=',False)]),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'display_account': fields.selection([('bal_mouvement','With movements'),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'display_account': fields.selection([('bal_mouvement','With movements'),
|
||||
('bal_all','All'),
|
||||
('bal_solde','With balance is not equal to 0'),
|
||||
],'Display accounts'),
|
||||
'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Keep empty for all open fiscal year'),
|
||||
'state': fields.selection([('bydate','By Date'),
|
||||
('byperiod','By Period'),
|
||||
('all','By Date and Period'),
|
||||
('none','No Filter')
|
||||
],'Date/Period Filter'),
|
||||
'periods': fields.many2many('account.period', 'period_account_balance_rel',
|
||||
'report_id', 'period_id', 'Periods',
|
||||
help='Keep empty for all open fiscal year'),
|
||||
'date_from': fields.date('Start date', required=True),
|
||||
'date_to': fields.date('End date', required=True),
|
||||
}
|
||||
}
|
||||
|
||||
def _get_company(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users')
|
||||
company_obj = self.pool.get('res.company')
|
||||
user = user_obj.browse(cr, uid, uid, context=context)
|
||||
if user.company_id:
|
||||
return user.company_id.id
|
||||
|
||||
def default_get(self, cr, uid, fields, context):
|
||||
""" To get default values for the object.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param fields: List of fields for which we want default values
|
||||
@param context: A standard dictionary
|
||||
@return: A dictionary which of fields with values.
|
||||
"""
|
||||
res = {}
|
||||
if 'journal_ids' in fields:
|
||||
res['journal_ids'] = []
|
||||
return res
|
||||
else:
|
||||
return company_obj.search(cr, uid, [('parent_id', '=', False)])[0]
|
||||
result = super(account_balance_report, self).default_get(cr, uid, fields, context)
|
||||
result.update({'company_id':self.pool.get('account.account').read(cr, uid, result['chart_account_id'], context=context)['company_id']})
|
||||
return result
|
||||
|
||||
_defaults={
|
||||
'state' : 'none',
|
||||
'date_from' : time.strftime('%Y-01-01'),
|
||||
'date_to' : time.strftime('%Y-%m-%d'),
|
||||
'company_id' : _get_company,
|
||||
'fiscalyear' : False,
|
||||
'display_account': 'bal_all',
|
||||
}
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
|
||||
def next_view(self, cr, uid, ids, context=None):
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
if context is None:
|
||||
context = {}
|
||||
data = self.read(cr, uid, ids, [])[0]
|
||||
context.update({'Account_list': data['Account_list']})
|
||||
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_balance_report_view')])
|
||||
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'account.balance.report',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'context': context
|
||||
}
|
||||
|
||||
def check_state(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
data={}
|
||||
data['ids'] = context['active_ids']
|
||||
data['form'] = self.read(cr, uid, ids, ['date_from', 'company_id', 'state', 'periods', 'date_to', 'display_account', 'fiscalyear'])[0]
|
||||
data['form']['Account_list'] = context.get('Account_list',[])
|
||||
data['form']['context'] = context
|
||||
if data['form']['Account_list']:
|
||||
data['model'] = 'ir.ui.menu'
|
||||
else:
|
||||
data['model'] = 'account.account'
|
||||
|
||||
if data['form']['state'] == 'bydate' :
|
||||
return self._check_date(cr, uid, data, context)
|
||||
elif data['form']['state'] == 'byperiod':
|
||||
if not data['form']['periods']:
|
||||
raise osv.except_osv(_('Warning'),_('Please Enter Periods ! '))
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.account.balance',
|
||||
'datas': data,
|
||||
'nodestroy':True,
|
||||
}
|
||||
|
||||
def _check_date(self, cr, uid, data, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
sql = """
|
||||
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
|
||||
cr.execute(sql, (data['form']['date_from'],))
|
||||
res = cr.dictfetchall()
|
||||
if res:
|
||||
|
||||
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
|
||||
raise osv.except_osv(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
|
||||
else:
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.account.balance',
|
||||
'datas': data,
|
||||
'nodestroy':True,
|
||||
}
|
||||
else:
|
||||
raise osv.except_osv(_('UserError'),_('Date not in a defined fiscal year'))
|
||||
|
||||
account_balance_report()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
if data['model']=='ir.ui.menu':
|
||||
data['ids']=data['form']['chart_account_id']
|
||||
data['form'].update(self.read(cr, uid, ids, ['display_account', 'company_id',])[0])
|
||||
data['form']['query_get'] = query_line
|
||||
return { 'type': 'ir.actions.report.xml', 'report_name': 'account.account.balance', 'datas': data, 'nodestroy':True, }
|
||||
account_balance_report()
|
||||
@@ -1,93 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<data>
|
||||
|
||||
<record id="account_balance_report_view" model="ir.ui.view">
|
||||
<field name="name">Select period</field>
|
||||
<field name="model">account.balance.report</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select period">
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="display_account" required = "True"/>
|
||||
<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 attrs="{'invisible':[('state','=','none')]}" colspan="4">
|
||||
<group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
|
||||
<separator string="Date Filter" colspan="4"/>
|
||||
<field name="date_from"/>
|
||||
<field name="date_to"/>
|
||||
</group>
|
||||
<group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
|
||||
<separator string="Filter on Periods" colspan="4"/>
|
||||
<field name="periods" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<newline/>
|
||||
<group colspan="4" col="6">
|
||||
<label string ="" colspan="2"/>
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="check_state" string="Print" type="object" icon="gtk-print" default_focus="1"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="account_report_balance_view" model="ir.ui.view">
|
||||
<field name="name">Account Balance</field>
|
||||
<field name="model">account.balance.report</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Print Account Balance" >
|
||||
<!-- <group width="600" height="350">-->
|
||||
<group colspan="4" col="4">
|
||||
<field name="chart_account_id" colspan="2" widget='selection'/>
|
||||
<field name="fiscalyear_id"/>
|
||||
<field name="filter"/>
|
||||
<field name="company_id"/>
|
||||
<field name="display_account"/>
|
||||
</group>
|
||||
<notebook tabpos="up" colspan="4">
|
||||
<page string="Periods" attrs="{'invisible':[('filter','!=','filter_period')]}">
|
||||
<field name="period_from"/>
|
||||
<field name="period_to"/>
|
||||
</page>
|
||||
<page string="Date" attrs="{'invisible':[('filter','!=','filter_date')]}">
|
||||
<field name="date_from"/>
|
||||
<field name="date_to"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<group colspan="4" col="4" >
|
||||
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
|
||||
<button icon="gtk-print" name="check_report" string="Print" type="object"/>
|
||||
</group>
|
||||
<!-- </group>-->
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_account_balance_menu" model="ir.actions.act_window">
|
||||
<field name="name">Account Balance</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.balance.report</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="account_report_balance_view"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_balance_report" model="ir.actions.act_window">
|
||||
<field name="name">Account Balance</field>
|
||||
<field name="res_model">account.balance.report</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="account_balance_report_view"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
<menuitem
|
||||
icon="STOCK_PRINT"
|
||||
name="Account Balance"
|
||||
parent="account.menu_generic_report"
|
||||
action="action_account_balance_menu"
|
||||
id="menu_general_Balance_report"
|
||||
/>
|
||||
|
||||
<record model="ir.values" id="action_account_balance_report_values">
|
||||
<record model="ir.values" id="action_account_balance_report_values1">
|
||||
<field name="model_id" ref="account.model_account_account" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Account Balance</field>
|
||||
<field name="key2">client_print_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_account_balance_report'))" />
|
||||
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_account_balance_menu'))" />
|
||||
<field name="key">action</field>
|
||||
<field name="model">account.account</field>
|
||||
</record>
|
||||
|
||||
<record id="account_balance_report_account_view" model="ir.ui.view">
|
||||
<field name="name">Account Balance</field>
|
||||
<field name="model">account.balance.report</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Chart">
|
||||
<field name="Account_list"/>
|
||||
<separator colspan="4"/>
|
||||
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
|
||||
<button name="next_view" string="Next" type="object" icon="gtk-go-forward" default_focus="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_balance_account_report" model="ir.actions.act_window">
|
||||
<field name="name">Select Account</field>
|
||||
<field name="res_model">account.balance.report</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="account_balance_report_account_view"/>
|
||||
<field name="context">{'record_id':active_id}</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem icon="STOCK_PRINT"
|
||||
name="Account Balance"
|
||||
action="action_account_balance_account_report"
|
||||
id="menu_account_balance_report"
|
||||
parent="account.menu_generic_report"/>
|
||||
|
||||
</data>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user