[IMP] update pot files
[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-2008 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
33 class account_journal(osv.osv):
34     _inherit='account.journal'
35     _name='account.journal'
36     _columns = {
37         'allow_date':fields.boolean('Allows date not in the period'),
38     }
39     _defaults = {
40         'allow_date': lambda *a: 1,
41         }
42 account_journal()
43
44 class account_move_line(osv.osv):
45     _inherit='account.move.line'
46     _name='account.move.line'
47
48     def check_date(self, cr, uid, vals, context=None, check=True):
49         if 'date' in vals.keys():
50             if 'journal_id' in vals and 'journal_id' not in context:
51                 journal_id = vals['journal_id']
52             if 'period_id' in vals and 'period_id' not in context:
53                 period_id = vals['period_id']
54             elif 'journal_id' not in context and 'move_id' in vals:
55                 m = self.pool.get('account.move').browse(cr, uid, vals['move_id'])
56                 journal_id = m.journal_id.id
57                 period_id = m.period_id.id
58             else:
59                 journal_id = context['journal_id']
60                 period_id = context['period_id']
61             journal=self.pool.get('account.journal').browse(cr,uid,[journal_id])[0]
62             if not journal.allow_date:
63                 period=self.pool.get('account.period').browse(cr,uid,[period_id])[0]
64                 if not time.strptime(vals['date'],'%Y-%m-%d')>=time.strptime(period.date_start,'%Y-%m-%d') and time.strptime(vals['date'],'%Y-%m-%d')<=time.strptime(period.date_stop,'%Y-%m-%d'):
65                     raise osv.except_osv('Error','The date of your account move is not in the defined period !')
66         else:
67             return True
68
69     def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
70         flag=self.check_date(cr, uid, vals, context, check)
71         result = super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)
72         return result
73     def create(self, cr, uid, vals, context=None, check=True):
74         flag=self.check_date(cr, uid, vals, context, check)
75         result = super(account_move_line, self).create(cr, uid, vals, context, check)
76         return result
77 account_move_line()
78
79 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
80