~akretion-team/account-financial-tools/account-financial-tools-account-writeoff-autodelete

« back to all changes in this revision

Viewing changes to account_journal_always_check_date/account_journal.py

  • Committer: Omar (Pexego)
  • Author(s): Alexis de Lattre
  • Date: 2013-12-13 01:43:08 UTC
  • mfrom: (0.2.3 must-have-check-date-70)
  • Revision ID: omar@pexego.es-20131213014308-yzzcrazexfkb7j17
[ADD] account_journal_always_check_date: activates the 'Check Date' option on all existing account journals, enable the 'Check Date' option on new account journals and prevent users from deactivating the 'Check Date' option (via a constraint)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Account Journal Always Check Date module for OpenERP
 
5
#    Copyright (C) 2013 Akretion (http://www.akretion.com)
 
6
#    @author Alexis de Lattre <alexis.delattre@akretion.com>
 
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
from openerp.osv import orm
 
24
from openerp.tools.translate import _
 
25
 
 
26
 
 
27
class account_journal(orm.Model):
 
28
    _inherit = 'account.journal'
 
29
 
 
30
    def init(self, cr):
 
31
        '''Activate 'Check Date in Period' on all existing journals'''
 
32
        cr.execute(
 
33
            "UPDATE account_journal SET allow_date=true "
 
34
            "WHERE allow_date <> true")
 
35
        return True
 
36
 
 
37
    _defaults = {
 
38
        'allow_date': True,
 
39
        }
 
40
 
 
41
    def _allow_date_always_active(self, cr, uid, ids):
 
42
        for journal in self.browse(cr, uid, ids):
 
43
            if not journal.allow_date:
 
44
                raise orm.except_orm(
 
45
                    _('Error:'),
 
46
                    _("The option 'Check Date in Period' must be active "
 
47
                    "on journal '%s'.")
 
48
                    % journal.name)
 
49
        return True
 
50
 
 
51
    _constraints = [
 
52
        (_allow_date_always_active, "Error msg in raise", ['allow_date']),
 
53
    ]