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

« back to all changes in this revision

Viewing changes to stock_schedule/schedule.py

UF-358 [ADD] Initial creation : backup of this day

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
        '''
77
77
        Check if all required data aren't empty
78
78
        '''
79
 
        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':
80
83
            if (not 'weekly_sunday_ok' in data or not data.get('weekly_sunday_ok', False)) and \
81
84
               (not 'weekly_monday_ok' in data or not data.get('weekly_monday_ok', False)) and \
82
85
               (not 'weekly_tuesday_ok' in data or not data.get('weekly_tuesday_ok', False)) and \
121
124
        default['last_run'] = False
122
125
        return super(stock_frequence, self).copy(cr, uid, id, default, context)
123
126
 
124
 
    def create(self, cr, uid, data, context=None):
 
127
    def create(self, cr, uid, data, context={}):
125
128
        '''
126
129
        Check if all required data aren't empty
127
130
        '''
129
132
        
130
133
        return super(stock_frequence, self).create(cr, uid, data, context=context)
131
134
    
132
 
    def write(self, cr, uid, ids, data, context=None):
 
135
    def write(self, cr, uid, ids, data, context={}):
133
136
        '''
134
137
        Check if all required data aren't empty
135
138
        '''
146
149
        
147
150
        return super(stock_frequence, self).write(cr, uid, ids, data, context=context)
148
151
    
149
 
    def _compute_end_date(self, cr, uid, ids, field, arg, context=None):
 
152
    def _compute_end_date(self, cr, uid, ids, field, arg, context={}):
150
153
        '''
151
154
        Compute the end date of the frequence according to the field of the object
152
155
        '''
253
256
                    if start_date < today():
254
257
                        start_date = today()
255
258
                    next_date = start_date + RelativeDate(weekday=(day,frequence.monthly_choose_freq))
256
 
                    while next_date < start_date:
257
 
                        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))
258
261
                    return next_date
259
262
 
260
263
            elif frequence.monthly_repeating_ok:
333
336
 
334
337
        return False
335
338
        
336
 
    def _compute_next_date(self, cr, uid, ids, field, arg, context=None):
 
339
    def _compute_next_date(self, cr, uid, ids, field, arg, context={}):
337
340
        '''
338
341
        Compute the next date matching with the parameter of the frequency
339
342
        '''
364
367
        
365
368
        return res
366
369
    
367
 
    def choose_frequency(self, cr, uid, ids, context=None):
 
370
    def choose_frequency(self, cr, uid, ids, context={}):
368
371
        '''
369
372
        Empty method. Override this method to implement your own features
370
373
        '''
371
374
        return {'type': 'ir.actions.act_window_close'}
372
375
    
373
 
    def name_get(self, cr, uid, ids, context=None):
 
376
    def name_get(self, cr, uid, ids, context={}):
374
377
        '''
375
378
        Returns a description of the frequence
376
379
        '''
382
385
        for freq in self.browse(cr, uid, ids):
383
386
            if freq.name == 'daily':
384
387
                if freq.daily_frequency_ok:
385
 
                    title = _('Every %d day(s)') % (freq.daily_frequency,)
 
388
                    title = _('Every %d day(s)' %freq.daily_frequency)
386
389
            if freq.name == 'weekly':
387
390
                sunday = monday = tuesday = wednesday = thursday = friday = saturday = ''
388
391
                if freq.weekly_sunday_ok:
399
402
                    friday = 'friday '
400
403
                if freq.weekly_saturday_ok:
401
404
                    saturday = 'saturday '
402
 
                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, \
403
406
                                                                 wednesday, thursday, \
404
 
                                                                 friday, saturday)
 
407
                                                                 friday, saturday))
405
408
            if freq.name == 'monthly':
406
409
                if freq.monthly_one_day:
407
410
                    choose_freq = self.get_selection(cr, uid, freq, 'monthly_choose_freq')
408
411
                    choose_day = self.get_selection(cr, uid, freq, 'monthly_choose_day')
409
 
                    title = _('%s %s - Every %s month(s)') % (choose_freq, choose_day, freq.monthly_frequency)
 
412
                    title = _('%s %s - Every %s month(s)' % (choose_freq, choose_day, freq.monthly_frequency))
410
413
                elif freq.monthly_repeating_ok:
411
414
                    title = _('On ')
412
415
                    i = 1
425
428
                        i += 1
426
429
                    # Remove the last comma
427
430
                    title = title[:-2]
428
 
                    title += _(' - Every %s month(s)') % (freq.monthly_frequency,)
 
431
                    title += _(' - Every %s month(s)' % freq.monthly_frequency)
429
432
            if freq.name == 'yearly':
430
433
                if freq.yearly_day_ok:
431
434
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month')
436
439
                        day_f = 'nd'
437
440
                    elif freq.yearly_day in (3, 23):
438
441
                        day_f = 'rd'
439
 
                    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))
440
443
                elif freq.yearly_date_ok:
441
444
                    frequence = self.get_selection(cr, uid, freq, 'yearly_choose_freq')
442
445
                    day = self.get_selection(cr, uid, freq, 'yearly_choose_day')
443
446
                    month = self.get_selection(cr, uid, freq, 'yearly_choose_month_freq')
444
 
                    title = _('All %s %s in %s') % (frequence, day, month)
445
 
                title += _(' - Every %s year(s)') %(freq.yearly_frequency)
 
447
                    title = _('All %s %s in %s' % (frequence, day, month))
 
448
                title += _(' - Every %s year(s)' %(freq.yearly_frequency))
446
449
                
447
450
            res.append((freq.id, title))
448
451