51
51
_name = 'stock.frequence'
52
52
_description = 'Stock scheduler'
54
def get_selection(self, cr, uid, o, field, context=None):
54
def get_selection(self, cr, uid, o, field):
56
56
Returns the field.selection label
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)])
66
63
return self.pool.get('ir.translation').read(cr, uid, tr_ids, ['value'])[0]['value']
80
77
Check if all required data aren't empty
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)
127
def create(self, cr, uid, data, context=None):
127
def create(self, cr, uid, data, context={}):
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=None):
135
def write(self, cr, uid, ids, data, context={}):
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=None):
152
def _compute_end_date(self, cr, uid, ids, field, arg, context={}):
154
154
Compute the end date of the frequence according to the field of the object
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))
263
263
elif frequence.monthly_repeating_ok:
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={}):
341
341
Compute the next date matching with the parameter of the frequency
370
def choose_frequency(self, cr, uid, ids, context=None):
370
def choose_frequency(self, cr, uid, ids, context={}):
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=None):
376
def name_get(self, cr, uid, ids, context={}):
378
378
Returns a description of the frequence
383
380
res = super(stock_frequence, self).name_get(cr, uid, ids, context=context)
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, \
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:
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')
439
436
if freq.yearly_day in (1, 21, 31):
443
440
elif freq.yearly_day in (3, 23):
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))
453
450
res.append((freq.id, title))