51
51
_name = 'stock.frequence'
52
52
_description = 'Stock scheduler'
54
def get_selection(self, cr, uid, o, field):
54
def get_selection(self, cr, uid, o, field, context=None):
56
56
Returns the field.selection label
58
61
sel = self.pool.get(o._name).fields_get(cr, uid, [field])
59
62
res = dict(sel[field]['selection']).get(getattr(o,field),getattr(o,field))
60
63
name = '%s,%s' % (o._name, field)
61
tr_ids = self.pool.get('ir.translation').search(cr, uid, [('type', '=', 'selection'), ('name', '=', name),('src', '=', res)])
64
tr_ids = self.pool.get('ir.translation').search(cr, uid, [('type', '=', 'selection'), ('name', '=', name),('src', '=', res), ('lang', '=', context.get('lang'))])
63
66
return self.pool.get('ir.translation').read(cr, uid, tr_ids, ['value'])[0]['value']
77
80
Check if all required data aren't empty
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':
82
if 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)
127
def create(self, cr, uid, data, context={}):
127
def create(self, cr, uid, data, context=None):
129
129
Check if all required data aren't empty
133
133
return super(stock_frequence, self).create(cr, uid, data, context=context)
135
def write(self, cr, uid, ids, data, context={}):
135
def write(self, cr, uid, ids, data, context=None):
137
137
Check if all required data aren't empty
150
150
return super(stock_frequence, self).write(cr, uid, ids, data, context=context)
152
def _compute_end_date(self, cr, uid, ids, field, arg, context={}):
152
def _compute_end_date(self, cr, uid, ids, field, arg, context=None):
154
154
Compute the end date of the frequence according to the field of the object
339
def _compute_next_date(self, cr, uid, ids, field, arg, context={}):
339
def _compute_next_date(self, cr, uid, ids, field, arg, context=None):
341
341
Compute the next date matching with the parameter of the frequency
370
def choose_frequency(self, cr, uid, ids, context={}):
370
def choose_frequency(self, cr, uid, ids, context=None):
372
372
Empty method. Override this method to implement your own features
374
374
return {'type': 'ir.actions.act_window_close'}
376
def name_get(self, cr, uid, ids, context={}):
376
def name_get(self, cr, uid, ids, context=None):
378
378
Returns a description of the frequence
380
383
res = super(stock_frequence, self).name_get(cr, uid, ids, context=context)
382
385
# TODO: Modif of name_get method to return a comprehensive name for frequence
385
388
for freq in self.browse(cr, uid, ids):
386
389
if freq.name == 'daily':
387
390
if freq.daily_frequency_ok:
388
title = _('Every %d day(s)' %freq.daily_frequency)
391
title = _('Every %d day(s)') % (freq.daily_frequency,)
389
392
if freq.name == 'weekly':
390
393
sunday = monday = tuesday = wednesday = thursday = friday = saturday = ''
391
394
if freq.weekly_sunday_ok:
402
405
friday = 'friday '
403
406
if freq.weekly_saturday_ok:
404
407
saturday = 'saturday '
405
title = _('Every %d week(s) on %s%s%s%s%s%s%s' %(freq.weekly_frequency, sunday, monday, tuesday, \
408
title = _('Every %d week(s) on %s%s%s%s%s%s%s') %(freq.weekly_frequency, sunday, monday, tuesday, \
406
409
wednesday, thursday, \
408
411
if freq.name == 'monthly':
409
412
if freq.monthly_one_day:
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))
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)
413
416
elif freq.monthly_repeating_ok:
429
432
# Remove the last comma
430
433
title = title[:-2]
431
title += _(' - Every %s month(s)' % freq.monthly_frequency)
434
title += _(' - Every %s month(s)') % (freq.monthly_frequency,)
432
435
if freq.name == 'yearly':
433
436
if freq.yearly_day_ok:
434
month = self.get_selection(cr, uid, freq, 'yearly_choose_month')
437
month = self.get_selection(cr, uid, freq, 'yearly_choose_month', context=context)
436
439
if freq.yearly_day in (1, 21, 31):
440
443
elif freq.yearly_day in (3, 23):
442
title = _('All %s, the %s%s' %(month, freq.yearly_day, day_f))
445
title = _('All %s, the %s%s') %(month, freq.yearly_day, day_f)
443
446
elif freq.yearly_date_ok:
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))
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)
450
453
res.append((freq.id, title))