def getQuarterNames(locale=None): """TODO :param locale: the current locale (e.g: en, en_us, it)""" locale = (locale or DEFAULT_LOCALE).replace('-', '_') d = dict([(v.lower(), k) for k, v in dates.get_quarter_names(width='wide', locale=locale).items()]) d.update([(v.lower(), k) for k, v in dates.get_quarter_names(width='abbreviated', locale=locale).items()]) return d
def getQuarterNames(locale=None): """add??? :param locale: ???add. Default value is ``None`` :returns: add??? """ locale = (locale or DEFAULT_LOCALE).replace('-', '_') d = dict([(v.lower(), k) for k, v in dates.get_quarter_names(width='wide', locale=locale).items()]) d.update([(v.lower(), k) for k, v in dates.get_quarter_names(width='abbreviated', locale=locale).items()]) return d
def getQuarterNames(locale=None): """add??? :param locale: ???add. Default value is ``None`` :returns: add??? """ locale = (locale or DEFAULT_LOCALE).replace('-', '_') d = dict([(v.lower(), k) for k, v in dates.get_quarter_names( width='wide', locale=locale).items()]) d.update([(v.lower(), k) for k, v in dates.get_quarter_names(width='abbreviated', locale=locale).items()]) return d
def format_date(self, dt_to, dt_from, options, dt_filter='date'): # previously get_full_date_names options_filter = options[dt_filter].get('filter', '') if isinstance(dt_to, pycompat.string_types): dt_to = datetime.strptime(dt_to, DEFAULT_SERVER_DATE_FORMAT) if dt_from and isinstance(dt_from, pycompat.string_types): dt_from = datetime.strptime(dt_from, DEFAULT_SERVER_DATE_FORMAT) if 'month' in options_filter: return format_date(self.env, dt_to.strftime(DEFAULT_SERVER_DATE_FORMAT), date_format='MMM YYYY') if 'quarter' in options_filter: quarter = (dt_to.month - 1) // 3 + 1 return ('%s %s') % (get_quarter_names( 'abbreviated', locale=self._context.get('lang') or 'en_US')[quarter], dt_to.year) if 'year' in options_filter: if self.env.user.company_id.fiscalyear_last_day == 31 and self.env.user.company_id.fiscalyear_last_month == 12: return dt_to.strftime('%Y') else: return '%s - %s' % ((dt_to.year - 1), dt_to.year) if not dt_from: return _('As of %s') % (format_date( self.env, dt_to.strftime(DEFAULT_SERVER_DATE_FORMAT)), ) return _('From %s <br/> to %s') % (format_date( self.env, dt_from.strftime(DEFAULT_SERVER_DATE_FORMAT) ), format_date(self.env, dt_to.strftime(DEFAULT_SERVER_DATE_FORMAT)))
def get_quarter_names(self, width='wide', context='format'): """Return the quarter names for the specified format In: - ``width`` -- 'wide', 'abbreviated' or 'narrow' - ``context`` -- either 'format' or 'stand-alone' Return: - the quarter names """ return dates.get_quarter_names(width, context, self)
def get_quarter_names(self, width='wide', context='format'): """Return the quarter names for the specified format >>> Locale('en', 'US').get_quarter_names('wide')[1] u'1st quarter' >>> Locale('de', 'DE').get_quarter_names('abbreviated')[1] u'Q1' In: - ``width`` -- 'wide', 'abbreviated' or 'narrow' - ``context`` -- either 'format' or 'stand-alone' Return: - the quarter names """ return dates.get_quarter_names(width, context, self)
def test_get_quarter_names(): assert dates.get_quarter_names('wide', locale='en_US')[1] == u'1st quarter' assert dates.get_quarter_names('abbreviated', locale='de_DE')[1] == u'Q1'
def test_get_quarter_names(): assert dates.get_quarter_names('wide', locale='en_US')[1] == u'1st quarter' assert dates.get_quarter_names('abbreviated', locale='de_DE')[1] == u'Q1' assert dates.get_quarter_names('narrow', locale='de_DE')[1] == u'1'
def _get_dates_period(self, options, date_from, date_to, period_type=None): def match(dt_from, dt_to): if self.has_single_date_filter(options): return (date_to or date_from) == dt_to else: return (dt_from, dt_to) == (date_from, date_to) string = None # If no date_from or not date_to, we are unable to determine a period if not period_type: date = date_to or date_from company_fiscalyear_dates = request.env.user.company_id.compute_fiscalyear_dates( date) if match(company_fiscalyear_dates['date_from'], company_fiscalyear_dates['date_to']): period_type = 'fiscalyear' if company_fiscalyear_dates.get('record'): string = company_fiscalyear_dates['record'].name elif match(*date_utils.get_month(date)): period_type = 'month' elif match(*date_utils.get_quarter(date)): period_type = 'quarter' elif match(*date_utils.get_fiscal_year(date)): period_type = 'year' else: period_type = 'custom' if not string: fy_day = request.env.user.company_id.fiscalyear_last_day fy_month = request.env.user.company_id.fiscalyear_last_month if self.has_single_date_filter(options): string = _('As of %s') % (format_date( request.env, date_to.strftime(DEFAULT_SERVER_DATE_FORMAT))) elif period_type == 'year' or ( period_type == 'fiscalyear' and (date_from, date_to) == date_utils.get_fiscal_year(date_to)): string = date_to.strftime('%Y') elif period_type == 'fiscalyear' and ( date_from, date_to) == date_utils.get_fiscal_year( date_to, day=fy_day, month=fy_month): string = '%s - %s' % (date_to.year - 1, date_to.year) elif period_type == 'month': string = format_date( request.env, date_to.strftime(DEFAULT_SERVER_DATE_FORMAT), date_format='MMM YYYY') elif period_type == 'quarter': quarter_names = get_quarter_names( 'abbreviated', locale=request.env.context.get('lang') or 'en_US') string = u'%s\N{NO-BREAK SPACE}%s' % (quarter_names[ date_utils.get_quarter_number(date_to)], date_to.year) else: dt_from_str = format_date( request.env, date_from.strftime(DEFAULT_SERVER_DATE_FORMAT)) dt_to_str = format_date( request.env, date_to.strftime(DEFAULT_SERVER_DATE_FORMAT)) string = _('From %s \n to %s') % (dt_from_str, dt_to_str) return { 'string': string, 'period_type': period_type, 'date_from': date_from, 'date_to': date_to, }