1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO consulting
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from dateutil.relativedelta import relativedelta
24
from osv import fields, osv
25
from tools.translate import _
27
class account_account_activable(osv.osv):
28
_inherit = 'account.account'
31
To create a activity period, 2 new fields are created, and are NOT linked to the
32
'active' field, since the behaviors are too different.
35
'activation_date': fields.date('Active from', required=True),
36
'inactivation_date': fields.date('Inactive from'),
37
'note': fields.char('Note', size=160),
41
'activation_date': lambda *a: (datetime.datetime.today() + relativedelta(months=-3)).strftime('%Y-%m-%d')
44
def _check_date(self, vals):
45
if 'inactivation_date' in vals and vals['inactivation_date'] is not False:
46
if vals['inactivation_date'] <= datetime.date.today().strftime('%Y-%m-%d'):
47
# validate the date (must be > today)
48
raise osv.except_osv(_('Warning !'), _('You cannot set an inactivity date lower than tomorrow!'))
49
elif 'activation_date' in vals and not vals['activation_date'] < vals['inactivation_date']:
50
# validate that activation date
51
raise osv.except_osv(_('Warning !'), _('Activation date must be lower than inactivation date!'))
53
def create(self, cr, uid, vals, context=None):
54
self._check_date(vals)
55
return super(account_account_activable, self).create(cr, uid, vals, context=context)
57
def write(self, cr, uid, ids, vals, context=None):
58
self._check_date(vals)
59
return super(account_account_activable, self).write(cr, uid, ids, vals, context=context)
61
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
64
if context.get('filter_inactive_accounts'):
65
args.append(('activation_date', '<=', datetime.date.today().strftime('%Y-%m-%d')))
67
args.append(('inactivation_date', '>', datetime.date.today().strftime('%Y-%m-%d')))
68
args.append(('inactivation_date', '=', False))
70
return super(account_account_activable, self).search(cr, uid, args, offset, limit,
71
order, context=context, count=count)
75
account_account_activable()
77
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: