diff --git a/addons/account/wizard/account_chart.py b/addons/account/wizard/account_chart.py
index 3d5f308f7bd..84683d17b30 100644
--- a/addons/account/wizard/account_chart.py
+++ b/addons/account/wizard/account_chart.py
@@ -18,7 +18,7 @@
# along with this program. If not, see .
#
##############################################################################
-
+import time
from osv import fields, osv
from tools.translate import _
@@ -29,16 +29,55 @@ class account_chart(osv.osv_memory):
_name = "account.chart"
_description = "Account chart"
_columns = {
- 'fiscalyear': fields.many2one('account.fiscalyear', \
+ 'fiscalyear': fields.many2one('account.fiscalyear', \
'Fiscal year', \
help = 'Keep empty for all open fiscal years'),
- 'target_move': fields.selection([('all', 'All Entries'),
+ 'period_from': fields.many2one('account.period', 'Start period'),
+ 'period_to': fields.many2one('account.period', 'End period'),
+ 'target_move': fields.selection([('all', 'All Entries'),
('posted', 'All Posted Entries')], 'Target Moves', required = True),
}
def _get_fiscalyear(self, cr, uid, context=None):
"""Return default Fiscalyear value"""
- return self.pool.get('account.fiscalyear').find(cr, uid)
+ now = time.strftime('%Y-%m-%d')
+ fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 )
+ return fiscalyears and fiscalyears[0] or False
+
+ def _build_periods(self, cr, uid, period_from, period_to):
+ period_obj = self.pool.get('account.period')
+ period_date_start = period_obj.read(cr, uid, period_from, ['date_start'])['date_start']
+ period_date_stop = period_obj.read(cr, uid, period_to, ['date_stop'])['date_stop']
+ if period_date_start > period_date_stop:
+ raise osv.except_osv(_('Error'),_('Start period should be smaller then End period'))
+ return period_obj.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)])
+
+ def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
+ res = {}
+ res['value'] = {'period_from': False, 'period_to': False}
+ if fiscalyear_id:
+ start_period = end_period = False
+ cr.execute('''
+ SELECT * FROM (SELECT p.id
+ FROM account_period p
+ LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
+ WHERE f.id = %s
+ ORDER BY p.date_start ASC
+ LIMIT 1) AS period_start
+ UNION
+ SELECT * FROM (SELECT p.id
+ FROM account_period p
+ LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
+ WHERE f.id = %s
+ AND p.date_start < NOW()
+ ORDER BY p.date_stop DESC
+ LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
+ periods = [i[0] for i in cr.fetchall()]
+ if periods and len(periods) > 1:
+ start_period = periods[0]
+ end_period = periods[1]
+ res['value'] = {'period_from': start_period, 'period_to': end_period}
+ return res
def account_chart_open_window(self, cr, uid, ids, context=None):
"""
@@ -56,7 +95,10 @@ class account_chart(osv.osv_memory):
result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
result = act_obj.read(cr, uid, [id], context=context)[0]
- result['context'] = str({'fiscalyear': data['fiscalyear'], \
+ result['periods'] = []
+ if data['period_from'] and data['period_to']:
+ result['periods'] = self._build_periods(cr, uid, data['period_from'], data['period_to'])
+ result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \
'state': data['target_move']})
if data['fiscalyear']:
result['name'] += ':' + self.pool.get('account.fiscalyear').read(cr, uid, [data['fiscalyear']], context=context)[0]['code']
diff --git a/addons/account/wizard/account_chart_view.xml b/addons/account/wizard/account_chart_view.xml
index 62f5c225a81..eb662058f32 100644
--- a/addons/account/wizard/account_chart_view.xml
+++ b/addons/account/wizard/account_chart_view.xml
@@ -7,16 +7,18 @@
form