363.11.114
by Olivier DOSSMANN
UF-675 [FIX] Regression on register creation. Fix this bug |
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
##############################################################################
|
|
4 |
#
|
|
5 |
# OpenERP, Open Source Management Solution
|
|
6 |
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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.
|
|
17 |
#
|
|
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/>.
|
|
20 |
#
|
|
21 |
##############################################################################
|
|
22 |
||
23 |
import datetime |
|
24 |
from dateutil.relativedelta import relativedelta |
|
25 |
from osv import fields, osv |
|
26 |
||
556.3.2
by Matthieu Dietrich
UF-768: [FIX] periods had issues |
27 |
class account_fiscalyear(osv.osv): |
28 |
_name = "account.fiscalyear" |
|
363.11.114
by Olivier DOSSMANN
UF-675 [FIX] Regression on register creation. Fix this bug |
29 |
_inherit = "account.fiscalyear" |
30 |
||
31 |
def create_period(self,cr, uid, ids, context=None, interval=1): |
|
32 |
for fy in self.browse(cr, uid, ids, context=context): |
|
33 |
ds = datetime.datetime.strptime(fy.date_start, '%Y-%m-%d') |
|
34 |
i = 0 |
|
35 |
while ds.strftime('%Y-%m-%d')<fy.date_stop: |
|
36 |
i += 1 |
|
37 |
de = ds + relativedelta(months=interval, days=-1) |
|
38 |
||
39 |
if de.strftime('%Y-%m-%d')>fy.date_stop: |
|
40 |
de = datetime.datetime.strptime(fy.date_stop, '%Y-%m-%d') |
|
41 |
||
42 |
self.pool.get('account.period').create(cr, uid, { |
|
43 |
'name': ds.strftime('%b %Y'), |
|
44 |
'code': ds.strftime('%b %Y'), |
|
45 |
'date_start': ds.strftime('%Y-%m-%d'), |
|
46 |
'date_stop': de.strftime('%Y-%m-%d'), |
|
47 |
'fiscalyear_id': fy.id, |
|
48 |
'special': False, |
|
49 |
'number': i, |
|
50 |
})
|
|
51 |
ds = ds + relativedelta(months=interval) |
|
52 |
||
53 |
ds = datetime.datetime.strptime(fy.date_stop, '%Y-%m-%d') |
|
54 |
for period_nb in (13, 14, 15): |
|
55 |
self.pool.get('account.period').create(cr, uid, { |
|
56 |
'name': 'Period %d' % (period_nb), |
|
57 |
'code': 'Period %d' % (period_nb), |
|
58 |
'date_start': '%d-12-01' % (ds.year), |
|
59 |
'date_stop': '%d-12-31' % (ds.year), |
|
60 |
'fiscalyear_id': fy.id, |
|
61 |
'special': True, |
|
62 |
'number': period_nb, |
|
63 |
})
|
|
64 |
return True |
|
65 |
||
556.3.2
by Matthieu Dietrich
UF-768: [FIX] periods had issues |
66 |
account_fiscalyear() |
363.11.114
by Olivier DOSSMANN
UF-675 [FIX] Regression on register creation. Fix this bug |
67 |
|
68 |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|