'Compute rule string according to value type RECUR of iCalendar
:return: string containing recurring rule (empty if no rule)'

@api.multi
def _rrule_serialize(self):

    if (self.interval and (self.interval < 0)):
        raise UserError(_('interval    cannot    be    negative.'))
    if (self.count and (self.count <= 0)):
        raise UserError(_('Event    recurrence    interval    cannot    be    negative.'))
    def get_week_string(freq):
        weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
        if (freq == 'weekly'):
            byday = [field.upper() for field in weekdays if self[field]]
            if byday:
                return (';BYDAY=' + ','.join(byday))
        return ''
    def get_month_string(freq):
        if (freq == 'monthly'):
            if ((self.month_by == 'date') and ((self.day < 1) or (self.day > 31))):
                raise UserError(_('Please    select    a    proper    day    of    the    month.'))
            if ((self.month_by == 'day') and self.byday and self.week_list):
                return ((';BYDAY=' + self.byday) + self.week_list)
            elif (self.month_by == 'date'):
                return (';BYMONTHDAY=' + str(self.day))
        return ''
    def get_end_date():
        end_date_new = ((''.join(re.compile('\\d').findall(self.final_date)) + 'T235959Z') if self.final_date else False)
        return ((((self.end_type == 'count') and (';COUNT=' + str(self.count))) or '') + ((end_date_new and (self.end_type == 'end_date') and (';UNTIL=' + end_date_new)) or ''))
    freq = self.rrule_type
    result = ''
    if freq:
        interval_srting = ((self.interval and (';INTERVAL=' + str(self.interval))) or '')
        result = ((((('FREQ=' + freq.upper()) + get_week_string(freq)) + interval_srting) + get_end_date()) + get_month_string(freq))
    return result
