~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to account_activable/account_activable.py

  • Committer: Quentin THEURET
  • Date: 2014-03-05 16:51:14 UTC
  • mto: (2004.1.33 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 2016.
  • Revision ID: qt@tempo-consulting.fr-20140305165114-m3n5p978sisi4n3f
REF-27 [FIX] Fix import of tools.translate

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        'activation_date': lambda *a: (datetime.datetime.today() + relativedelta(months=-3)).strftime('%Y-%m-%d')
42
42
    }
43
43
    
44
 
    def _check_date(self, vals):
 
44
    def _check_date(self, vals, context=None):
 
45
        if context is None:
 
46
            context = {}
 
47
 
45
48
        if 'inactivation_date' in vals and vals['inactivation_date'] is not False:
46
 
            if vals['inactivation_date'] <= datetime.date.today().strftime('%Y-%m-%d'):
 
49
            if vals['inactivation_date'] <= datetime.date.today().strftime('%Y-%m-%d') and not context.get('sync_update_execution', False):
47
50
                 # validate the date (must be > today)
48
51
                 raise osv.except_osv(_('Warning !'), _('You cannot set an inactivity date lower than tomorrow!'))
49
52
            elif 'activation_date' in vals and not vals['activation_date'] < vals['inactivation_date']:
51
54
                raise osv.except_osv(_('Warning !'), _('Activation date must be lower than inactivation date!'))
52
55
    
53
56
    def create(self, cr, uid, vals, context=None):
54
 
        self._check_date(vals)
 
57
        self._check_date(vals, context=context)
55
58
        return super(account_account_activable, self).create(cr, uid, vals, context=context)
56
59
    
57
60
    def write(self, cr, uid, ids, vals, context=None):
58
 
        self._check_date(vals)
 
61
        self._check_date(vals, context=context)
59
62
        return super(account_account_activable, self).write(cr, uid, ids, vals, context=context)
60
63
 
61
64
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
 
65
        """
 
66
        Filtering regarding context
 
67
        """
62
68
        if not context:
63
69
            context = {}
64
70
        if context.get('filter_inactive_accounts'):
66
72
            args.append('|')
67
73
            args.append(('inactivation_date', '>', datetime.date.today().strftime('%Y-%m-%d')))
68
74
            args.append(('inactivation_date', '=', False))
69
 
            
70
 
        return super(account_account_activable, self).search(cr, uid, args, offset, limit,
71
 
                order, context=context, count=count)
72
 
            
73
 
            
74
 
    
 
75
        return super(account_account_activable, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
 
76
 
75
77
account_account_activable()
76
78
 
77
79
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: