~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to stock_schedule/schedule.py

UF-359 [ADD] Account override module integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    _name = 'stock.frequence'
52
52
    _description = 'Stock scheduler'
53
53
    
54
 
    def get_selection(self, cr, uid, o, field, context=None):
 
54
    def get_selection(self, cr, uid, o, field):
55
55
        """
56
56
        Returns the field.selection label
57
57
        """
58
 
        if not context:
59
 
            context = {}
60
 
 
61
58
        sel = self.pool.get(o._name).fields_get(cr, uid, [field])
62
59
        res = dict(sel[field]['selection']).get(getattr(o,field),getattr(o,field))
63
60
        name = '%s,%s' % (o._name, field)
64
 
        tr_ids = self.pool.get('ir.translation').search(cr, uid, [('type', '=', 'selection'), ('name', '=', name),('src', '=', res), ('lang', '=', context.get('lang'))])
 
61
        tr_ids = self.pool.get('ir.translation').search(cr, uid, [('type', '=', 'selection'), ('name', '=', name),('src', '=', res)])
65
62
        if tr_ids:
66
63
            return self.pool.get('ir.translation').read(cr, uid, tr_ids, ['value'])[0]['value']
67
64
        else:
79
76
        '''
80
77
        Check if all required data aren't empty
81
78
        '''
82
 
        if data['name'] == 'weekly':
 
79
        if data['name'] == 'daily':
 
80
            if  not data.get('daily_frequency_ok', False):
 
81
                raise osv.except_osv(_('Error'), _('You should make a choice for the Daily configuration'))
 
82
        elif data['name'] == 'weekly':
83
83
            if (not 'weekly_sunday_ok' in data or not data.get('weekly_sunday_ok', False)) and \
84
84
               (not 'weekly_monday_ok' in data or not data.get('weekly_monday_ok', False)) and \
85
85
               (not 'weekly_tuesday_ok' in data or not data.get('weekly_tuesday_ok', False)) and \
124
124
        default['last_run'] = False
125
125
        return super(stock_frequence, self).copy(cr, uid, id, default, context)
126
126
 
127
 
    def create(self, cr, uid, data, context=None):
 
127
    def create(self, cr, uid, data, context={}):
128
128
        '''
129
129
        Check if all required data aren't empty
130
130
        '''
132
132
        
133
133
        return super(stock_frequence, self).create(cr, uid, data, context=context)
134
134
    
135
 
    def write(self, cr, uid, ids, data, context=None):
 
135
    def write(self, cr, uid, ids, data, context={}):
136
136
        '''
137
137
        Check if all required data aren't empty
138
138
        '''
149
149
        
150
150
        return super(stock_frequence, self).write(cr, uid, ids, data, context=context)
151
151
    
152
 
    def _compute_end_date(self, cr, uid, ids, field, arg, context=None):
 
152
    def _compute_end_date(self, cr, uid, ids, field, arg, context={}):
153
153
        '''
154
154
        Compute the end date of the frequence according to the field of the object
155
155
        '''
256
256
                    if start_date < today():
257
257
                        start_date = today()
258
258
                    next_date = start_date + RelativeDate(weekday=(day,frequence.monthly_choose_freq))
259
 
                    while next_date < start_date:
260
 
                        next_date = next_date + RelativeDate(months=1, weekday=(day,frequence.monthly_choose_freq))
 
259
                    if next_date < start_date:
 
260
                        next_date = start_date + RelativeDate(months=1, weekday=(day,frequence.monthly_choose_freq))
261
261
                    return next_date
262
262
 
263
263
            elif frequence.monthly_repeating_ok:
336
336
 
337
337
        return False
338
338
        
339
 
    def _compute_next_date(self, cr, uid, ids, field, arg, context=None):
 
339
    def _compute_next_date(self, cr, uid, ids, field, arg, context={}):
340
340
        '''
341
341
        Compute the next date matching with the parameter of the frequency
342
342
        '''
367
367
        
368
368
        return res
369
369
    
370
 
    def choose_frequency(self, cr, uid, ids, context=None):
 
370
    def choose_frequency(self, cr, uid, ids, context={}):
371
371
        '''
372
372
        Empty method. Override this method to implement your own features
373
373
        '''
374
374
        return {'type': 'ir.actions.act_window_close'}
375
375
    
376
 
    def name_get(self, cr, uid, ids, context=None):
 
376
    def name_get(self, cr, uid, ids, context={}):
377
377
        '''
378
378
        Returns a description of the frequence
379
379
        '''
380
 
        if not context:
381
 
            context = {}
382
 
 
383
380
        res = super(stock_frequence, self).name_get(cr, uid, ids, context=context)
384
381
        
385
382
        # TODO: Modif of name_get method to return a comprehensive name for frequence
388
385
        for freq in self.browse(cr, uid, ids):
389
386
            if freq.name == 'daily':
390
387
                if freq.daily_frequency_ok:
391
 
                    title = _('Every %d day(s)') % (freq.daily_frequency,)
 
388
                    title = _('Every %d day(s)' %freq.daily_frequency)
392
389
            if freq.name == 'weekly':
393
390
                sunday = monday = tuesday = wednesday = thursday = friday = saturday = ''
394
391
                if freq.weekly_sunday_ok:
405
402
                    friday = 'friday '
406
403
                if freq.weekly_saturday_ok:
407
404
                    saturday = 'saturday '
408
 
                title = _('Every %d week(s) on %s%s%s%s%s%s%s') %(freq.weekly_frequency, sunday, monday, tuesday, \
 
405
                title = _('Every %d week(s) on %s%s%s%s%s%s%s' %(freq.weekly_frequency, sunday, monday, tuesday, \
409
406
                                                                 wednesday, thursday, \
410
 
                                                                 friday, saturday)
 
407
                                                                 friday, saturday))
411
408
            if freq.name == 'monthly':
412
409
                if freq.monthly_one_day:
413
 
                    choose_freq = self.get_selection(cr, uid, freq, 'monthly_choose_freq', context=context)
414
 
                    choose_day = self.get_selection(cr, uid, freq, 'monthly_choose_day', context=context)
415
 
                    title = _('%s %s - Every %s month(s)') % (choose_freq, choose_day, freq.monthly_frequency)
 
410
                    choose_freq = self.get_selection(cr, uid, freq, 'monthly_choose_freq')
 
411
                    choose_day = self.get_selection(cr, uid, freq, 'monthly_choose_day')
 
412
                    title = _('%s %s - Every %s month(s)' % (choose_freq, choose_day, freq.monthly_frequency))
416
413
                elif freq.monthly_repeating_ok:
417
414
                    title = _('On ')
418
415
                    i = 1
431
428
                        i += 1
432
429
                    # Remove the last comma
433
430
                    title = title[:-2]
434
 
                    title += _(' - Every %s month(s)') % (freq.monthly_frequency,)
 
431
                    title += _(' - Every %s month(s)' % freq.monthly_frequency)
435
432
            if freq.name == 'yearly':
436
433
                if freq.yearly_day_ok:
437
 
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month', context=context)
 
434
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month')
438
435
                    day_f = 'th'
439
436
                    if freq.yearly_day in (1, 21, 31):
440
437
                        day_f = 'st'
442
439
                        day_f = 'nd'
443
440
                    elif freq.yearly_day in (3, 23):
444
441
                        day_f = 'rd'
445
 
                    title = _('All %s, the %s%s') %(month, freq.yearly_day, day_f)
 
442
                    title = _('All %s, the %s%s' %(month, freq.yearly_day, day_f))
446
443
                elif freq.yearly_date_ok:
447
 
                    frequence = self.get_selection(cr, uid, freq, 'yearly_choose_freq', context=context)
448
 
                    day = self.get_selection(cr, uid, freq, 'yearly_choose_day', context=context)
449
 
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month_freq', context=context)
450
 
                    title = _('All %s %s in %s') % (frequence, day, month)
451
 
                title += _(' - Every %s year(s)') %(freq.yearly_frequency)
 
444
                    frequence = self.get_selection(cr, uid, freq, 'yearly_choose_freq')
 
445
                    day = self.get_selection(cr, uid, freq, 'yearly_choose_day')
 
446
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month_freq')
 
447
                    title = _('All %s %s in %s' % (frequence, day, month))
 
448
                title += _(' - Every %s year(s)' %(freq.yearly_frequency))
452
449
                
453
450
            res.append((freq.id, title))
454
451