[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / account_date_check / account_date_check.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
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 General Public License for more details.
17 #
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/>.
20 #
21 ##############################################################################
22
23 from osv import fields
24 from osv import osv
25 import time
26 import netsvc
27
28 import ir
29 from mx import DateTime
30 import pooler
31 from tools import config
32 from tools.translate import _
33
34 class account_journal(osv.osv):
35     _inherit='account.journal'
36     _name='account.journal'
37     _columns = {
38         'allow_date':fields.boolean('Allows date not in the period'),
39     }
40     _defaults = {
41         'allow_date': lambda *a: 1,
42         }
43 account_journal()
44
45 class account_move_line(osv.osv):
46     _inherit='account.move.line'
47     _name='account.move.line'
48
49     def check_date(self, cr, uid, vals, context=None, check=True):
50         if not context:
51             context = {}
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
61             else:
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]
67
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') ):
71
72                     raise osv.except_osv(_('Error'),_('The date of your account move is not in the defined period !'))
73         else:
74             return True
75
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)
79         return result
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)
83         return result
84 account_move_line()
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
87