2010-03-30 12:47:02 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
|
|
|
|
#
|
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
2010-10-15 13:35:22 +00:00
|
|
|
|
|
2010-03-30 12:47:02 +00:00
|
|
|
|
from osv import fields, osv
|
|
|
|
|
|
|
|
|
|
class account_chart(osv.osv_memory):
|
|
|
|
|
"""
|
2010-08-30 07:06:28 +00:00
|
|
|
|
For Chart of Accounts
|
2010-05-24 06:26:13 +00:00
|
|
|
|
"""
|
2010-03-30 12:47:02 +00:00
|
|
|
|
_name = "account.chart"
|
2010-08-27 06:49:02 +00:00
|
|
|
|
_description = "Account chart"
|
2010-03-30 12:47:02 +00:00
|
|
|
|
_columns = {
|
2010-09-14 13:57:02 +00:00
|
|
|
|
'fiscalyear': fields.many2one('account.fiscalyear', \
|
2010-04-29 07:19:10 +00:00
|
|
|
|
'Fiscal year', \
|
|
|
|
|
help = 'Keep empty for all open fiscal years'),
|
2010-09-14 13:57:02 +00:00
|
|
|
|
'period_from': fields.many2one('account.period', 'Start period'),
|
|
|
|
|
'period_to': fields.many2one('account.period', 'End period'),
|
2010-12-10 10:31:12 +00:00
|
|
|
|
'target_move': fields.selection([('posted', 'All Posted Entries'),
|
|
|
|
|
('all', 'All Entries'),
|
|
|
|
|
], 'Target Moves', required = True),
|
2010-07-13 14:30:27 +00:00
|
|
|
|
}
|
2010-04-29 07:19:10 +00:00
|
|
|
|
|
2010-09-14 13:57:02 +00:00
|
|
|
|
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
|
|
|
|
|
res = {}
|
2010-09-17 10:30:30 +00:00
|
|
|
|
res['value'] = {}
|
2010-09-14 13:57:02 +00:00
|
|
|
|
if fiscalyear_id:
|
|
|
|
|
start_period = end_period = False
|
|
|
|
|
cr.execute('''
|
2010-09-17 10:30:30 +00:00
|
|
|
|
SELECT * FROM (SELECT p.id
|
|
|
|
|
FROM account_period p
|
|
|
|
|
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
|
|
|
|
|
WHERE f.id = %s
|
2010-09-14 13:57:02 +00:00
|
|
|
|
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
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
2010-08-27 06:49:02 +00:00
|
|
|
|
def account_chart_open_window(self, cr, uid, ids, context=None):
|
2010-04-29 07:19:10 +00:00
|
|
|
|
"""
|
|
|
|
|
Opens chart of Accounts
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of account chart’s IDs
|
|
|
|
|
@return: dictionary of Open account chart window on given fiscalyear and all Entries or posted entries
|
|
|
|
|
"""
|
|
|
|
|
mod_obj = self.pool.get('ir.model.data')
|
|
|
|
|
act_obj = self.pool.get('ir.actions.act_window')
|
2010-10-15 13:35:22 +00:00
|
|
|
|
period_obj = self.pool.get('account.period')
|
|
|
|
|
fy_obj = self.pool.get('account.fiscalyear')
|
2010-08-27 06:49:02 +00:00
|
|
|
|
if context is None:
|
|
|
|
|
context = {}
|
2010-04-29 07:19:10 +00:00
|
|
|
|
data = self.read(cr, uid, ids, [], context=context)[0]
|
2010-10-28 08:35:00 +00:00
|
|
|
|
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_account_tree')
|
|
|
|
|
id = result and result[1] or False
|
2010-04-29 07:19:10 +00:00
|
|
|
|
result = act_obj.read(cr, uid, [id], context=context)[0]
|
2011-03-16 13:07:34 +00:00
|
|
|
|
fiscalyear = data.get('fiscalyear', False) and data['fiscalyear'][0] or False
|
2010-10-15 13:35:22 +00:00
|
|
|
|
result['periods'] = []
|
2010-09-14 13:57:02 +00:00
|
|
|
|
if data['period_from'] and data['period_to']:
|
2011-03-16 13:07:34 +00:00
|
|
|
|
period_from = data.get('period_from', False) and data['period_from'][0] or False
|
|
|
|
|
period_to = data.get('period_to', False) and data['period_to'][0] or False
|
|
|
|
|
result['periods'] = period_obj.build_ctx_periods(cr, uid, period_from, period_to)
|
|
|
|
|
result['context'] = str({'fiscalyear': fiscalyear, 'periods': result['periods'], \
|
2010-04-29 07:19:10 +00:00
|
|
|
|
'state': data['target_move']})
|
|
|
|
|
if data['fiscalyear']:
|
2011-03-16 13:07:34 +00:00
|
|
|
|
result['name'] += ':' + fy_obj.read(cr, uid, [fiscalyear], context=context)[0]['code']
|
2010-04-29 07:19:10 +00:00
|
|
|
|
return result
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
|
|
|
|
_defaults = {
|
2010-12-10 10:31:12 +00:00
|
|
|
|
'target_move': 'posted'
|
2010-08-19 11:51:57 +00:00
|
|
|
|
}
|
2010-08-27 06:49:02 +00:00
|
|
|
|
|
2010-03-30 12:47:02 +00:00
|
|
|
|
account_chart()
|
2010-04-29 06:35:55 +00:00
|
|
|
|
|
2010-10-18 20:32:38 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|