1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.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 General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (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 General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import fields
29 from mx import DateTime
31 from tools import config
32 from tools.translate import _
34 class account_journal(osv.osv):
35 _inherit='account.journal'
36 _name='account.journal'
38 'allow_date':fields.boolean('Allows date not in the period'),
41 'allow_date': lambda *a: 1,
45 class account_move_line(osv.osv):
46 _inherit='account.move.line'
47 _name='account.move.line'
49 def check_date(self, cr, uid, vals, context=None, check=True):
52 if 'date' in vals.keys():
53 if 'journal_id' in vals and 'journal_id' not in context:
54 journal_id = vals['journal_id']
55 if 'period_id' in vals and 'period_id' not in context:
56 period_id = vals['period_id']
57 elif 'journal_id' not in context and 'move_id' in vals:
58 m = self.pool.get('account.move').browse(cr, uid, vals['move_id'])
59 journal_id = m.journal_id.id
60 period_id = m.period_id.id
62 journal_id = context['journal_id']
63 period_id = context['period_id']
64 journal = self.pool.get('account.journal').browse(cr,uid,[journal_id])[0]
65 if not journal.allow_date:
66 period=self.pool.get('account.period').browse(cr,uid,[period_id])[0]
68 date = time.strptime(vals['date'][:10], '%Y-%m-%d')
69 if not (date >= time.strptime(period.date_start,'%Y-%m-%d')
70 and date <= time.strptime(period.date_stop,'%Y-%m-%d') ):
72 raise osv.except_osv(_('Error'),_('The date of your account move is not in the defined period !'))
76 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
77 flag=self.check_date(cr, uid, vals, context, check)
78 result = super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)
80 def create(self, cr, uid, vals, context=None, check=True):
81 flag=self.check_date(cr, uid, vals, context, check)
82 result = super(account_move_line, self).create(cr, uid, vals, context, check)
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: