1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from datetime import datetime, date, timedelta
25
from osv import osv, fields
27
from tools.translate import _
28
logger=netsvc.Logger()
30
class calc_cashflow_opening_balance(osv.osv_memory):
31
_name = 'calc.cashflow.opening.balance'
32
_description = 'Recalculate Cash Flow Opening Balances'
34
'date_start': fields.date('Start Date', required=True),
35
'date_stop': fields.date('End Date', required=True),
36
'company_id': fields.many2one('res.company', 'Company', required=True),
39
def calc_cashflow_opening_balance(self, cr, uid, ids, context=None):
40
balopen_obj = self.pool.get('account.cashflow.opening.balance')
45
data = self.read(cr, uid, ids, [], context=context)[0]
47
raise osv.except_osv(_('Error!'), _('Wizard in incorrect state. Please hit the Cancel button!'))
49
date_start = datetime.strptime(data['date_start'], '%Y-%m-%d').date()
50
date_stop = datetime.strptime(data['date_stop'], '%Y-%m-%d').date()
51
company_id = data['company_id']
53
nbr_days = (date_stop - date_start).days + 1
55
raise osv.except_osv(_('Error!'), _('Invalid Date Range!'))
58
cr.execute("SELECT id FROM account_cashflow_code WHERE type='init' AND company_id = %s", (company_id,))
59
res_init_id = cr.fetchall()
60
if len(res_init_id) != 1:
61
err_str = len(res_init_id) and 'Multiple' or 'No'
62
raise osv.except_osv('Configuration Error',
63
_("%s Cash Flow Codes of type='Initial Balance' defined for your Company !") % err_str)
64
balance_init_id = res_init_id[0][0]
66
for x in range(0, nbr_days):
67
date = (date_start + timedelta(days=x)).isoformat()
68
balopen_obj.calc_opening_balance(cr, uid, date, balance_init_id, company_id)
73
'date_start': lambda *a: time.strftime('%Y-%m-%d'),
74
'date_stop': lambda *a: time.strftime('%Y-%m-%d'),
75
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
78
calc_cashflow_opening_balance()