1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO consulting
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from dateutil.relativedelta import relativedelta
24
from osv import fields, osv
26
class account_fiscalyear_closing_level(osv.osv):
27
_inherit = "account.fiscalyear"
29
def create_period(self,cr, uid, ids, context=None, interval=1):
30
for fy in self.browse(cr, uid, ids, context=context):
31
ds = datetime.datetime.strptime(fy.date_start, '%Y-%m-%d')
32
while ds.strftime('%Y-%m-%d')<fy.date_stop:
33
de = ds + relativedelta(months=interval, days=-1)
35
if de.strftime('%Y-%m-%d')>fy.date_stop:
36
de = datetime.datetime.strptime(fy.date_stop, '%Y-%m-%d')
38
self.pool.get('account.period').create(cr, uid, {
39
'name': ds.strftime('%b %Y'),
40
'code': ds.strftime('%b %Y'),
41
'date_start': ds.strftime('%Y-%m-%d'),
42
'date_stop': de.strftime('%Y-%m-%d'),
43
'fiscalyear_id': fy.id,
46
ds = ds + relativedelta(months=interval)
48
ds = datetime.datetime.strptime(fy.date_stop, '%Y-%m-%d')
49
for period_nb in (13, 14, 15):
50
self.pool.get('account.period').create(cr, uid, {
51
'name': 'Period %d' % (period_nb),
52
'code': 'Period %d' % (period_nb),
53
'date_start': '%d-12-01' % (ds.year),
54
'date_stop': '%d-12-31' % (ds.year),
55
'fiscalyear_id': fy.id,
60
account_fiscalyear_closing_level()
62
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: