Ejemplo n.º 1
0
    def _populate_date_filter(self, date_filter):
        # The options we want to show to the users are the following:
        #   'May 2007'
        #   'June 2007'
        #   ...
        #   'September 2008'

        initial_date = self.store.find(SystemTable).min(
            SystemTable.updated).date()

        # Start is the first day of the month
        # End is the last day of the month
        start = initial_date + relativedelta(day=1)
        end = localtoday().date() + relativedelta(day=31)
        intervals = []
        while start < end:
            intervals.append((start, start + relativedelta(day=31)))
            start = start + relativedelta(months=1)

        # When we have the list of intervals, add them to the list and
        # make sure that they are translated
        month_names = get_month_names()
        for start, end in intervals:
            # Translators: Do not translate 'month' and 'year'. You can
            #              change it's positions. In the way it is,
            #              it will product for example 'December 2012'
            name = _('{month} {year}').format(month=month_names[start.month -
                                                                1],
                                              year=start.year)
            date_filter.add_option_fixed_interval(name, start, end, position=0)
Ejemplo n.º 2
0
    def _write_headers(self, sheet, n_columns):
        for x in range(n_columns):
            month_name = get_month_names()[x]
            sheet.write(1, 1 + x, month_name, HEADER_TOP_STYLE)

        sheet.write(1, n_columns + 1, _(u'Average'), HEADER_TOP_STYLE)
        sheet.write(1, n_columns + 2, _(u'Total'), HEADER_TOP_STYLE)
Ejemplo n.º 3
0
    def _populate_date_filter(self, date_filter):
        # The options we want to show to the users are the following:
        #   'May 2007'
        #   'June 2007'
        #   ...
        #   'September 2008'

        initial_date = self.store.find(SystemTable).min(
            SystemTable.updated).date()

        # Start is the first day of the month
        # End is the last day of the month
        start = initial_date + relativedelta(day=1)
        end = localtoday().date() + relativedelta(day=31)
        intervals = []
        while start < end:
            intervals.append((start, start + relativedelta(day=31)))
            start = start + relativedelta(months=1)

        # When we have the list of intervals, add them to the list and
        # make sure that they are translated
        month_names = get_month_names()
        for start, end in intervals:
            # Translators: Do not translate 'month' and 'year'. You can
            #              change it's positions. In the way it is,
            #              it will product for example 'December 2012'
            name = _('{month} {year}').format(
                month=month_names[start.month - 1],
                year=start.year)
            date_filter.add_option_fixed_interval(
                name, start, end, position=0)
Ejemplo n.º 4
0
    def _write_headers(self, sheet, n_columns):
        for x in range(n_columns):
            month_name = get_month_names()[x]
            sheet.write(1, 1 + x, month_name, HEADER_TOP_STYLE)

        sheet.write(1, n_columns + 1, _(u"Average"), HEADER_TOP_STYLE)
        sheet.write(1, n_columns + 2, _(u"Total"), HEADER_TOP_STYLE)
Ejemplo n.º 5
0
    def run(self, args):
        start = args['start']
        end = args['end']

        if (start.month == 1 and start.day == 1 and
            end.month == 12 and end.day == 31):
            description = _("Total revenue, expenses and gross profit for %s") % (start.year, )
        else:
            description = _("Total revenue, expenses and gross profit for all months in a year")

        date_columns = ("extract(year FROM paid_date)||'-'||"
                        "lpad(extract(month FROM paid_date)::char, 2, '0')")
        months = {}
        ns = dict(date_columns=date_columns,
                  start=start.strftime('%Y-%m-%d'),
                  end=end.strftime('%Y-%m-%d'))

        tmpl = string.Template(self.in_payments_query).substitute(ns)
        res = self.execute(tmpl)
        for date, total_in in res:
            year, month = map(int, date.split('-'))
            months.setdefault((year, month), {})['in'] = total_in or 0

        tmpl = string.Template(self.out_payments_query).substitute(ns)
        res = self.execute(tmpl)
        for date, total_out in res:
            year, month = map(int, date.split('-'))
            months.setdefault((year, month), {})['out'] = total_out or 0

        revenues = []
        expenses = []
        profits = []

        items = []
        keys = sorted(months)
        for key in keys:
            values = months[key]
            year, month = key
            month = int(month)
            total_in = values.get('in', 0)
            total_out = values.get('out', 0)

            revenues.append(float(total_in))
            expenses.append(float(total_out))
            profits.append(float(total_in - total_out))

            items.append({'short_title': '%s' % (get_short_month_names()[month - 1], ),
                          'time': '%s, %d' % (get_month_names()[month - 1], year),
                          'revenue': int(total_in),
                          'expense': int(total_out),
                          'profit': int(total_in - total_out),
                          'year': year,
                          'month': month})

        return {'data': [revenues, expenses, profits],
                'description': description,
                'items': items}
Ejemplo n.º 6
0
    def run(self, args):
        start = args['start']
        end = args['end']

        if (start + relativedelta(days=31)) == end:
            month_name = get_month_names()[start.month - 1]
            link = 'chart://show_one/type=YearlyPayments&start=%d-01-01&end=%d-12-31' % (
                start.year, start.year)
            description = _(
                'Revenue, expenses and gross profit for %s <a href="%s">%s</a>'
            ) % (month_name, link, start.year)
        else:
            description = _("Revenue, expenses and gross profit per day")

        ns = dict(start=start.strftime('%Y-%m-%d'),
                  end=end.strftime('%Y-%m-%d'))

        days = {}
        for i in range(1, 32):
            days[i] = {'in': 0, 'out': 0}
        tmpl = string.Template(self.daily_in_payments).substitute(ns)
        for day, total_in in self.store.execute(tmpl).get_all():
            days[day]['in'] = total_in

        tmpl = string.Template(self.daily_out_payments).substitute(ns)
        for day, total_out in self.store.execute(tmpl).get_all():
            days[day]['out'] = total_out

        revenues = []
        expenses = []
        profits = []

        items = []
        for day, values in sorted(days.items()):
            total_in = values.get('in', 0)
            total_out = values.get('out', 0)
            revenues.append(float(total_in))
            expenses.append(float(total_out))
            profits.append(float(total_in - total_out))
            items.append({
                'short_title': day,
                'revenuse': int(total_in),
                'expense': int(total_out),
                'profit': int(total_in - total_out),
            })

        return {
            'data': [revenues, expenses, profits],
            'description': description,
            'items': items
        }
Ejemplo n.º 7
0
    def run(self, args):
        start = args['start']
        end = args['end']

        if (start + relativedelta(days=31)) == end:
            month_name = get_month_names()[start.month - 1]
            link = 'chart://show_one/type=YearlyPayments&start=%d-01-01&end=%d-12-31' % (
                start.year, start.year)
            description = _('Revenue, expenses and gross profit for %s <a href="%s">%s</a>') % (
                month_name, link, start.year)
        else:
            description = _("Revenue, expenses and gross profit per day")

        ns = dict(start=start.strftime('%Y-%m-%d'),
                  end=end.strftime('%Y-%m-%d'))

        days = {}
        for i in range(1, 32):
            days[i] = {'in': 0, 'out': 0}
        tmpl = string.Template(self.daily_in_payments).substitute(ns)
        for day, total_in in self.store.execute(tmpl).get_all():
            days[day]['in'] = total_in

        tmpl = string.Template(self.daily_out_payments).substitute(ns)
        for day, total_out in self.store.execute(tmpl).get_all():
            days[day]['out'] = total_out

        revenues = []
        expenses = []
        profits = []

        items = []
        for day, values in sorted(days.items()):
            total_in = values.get('in', 0)
            total_out = values.get('out', 0)
            revenues.append(float(total_in))
            expenses.append(float(total_out))
            profits.append(float(total_in - total_out))
            items.append({
                'short_title': day,
                'revenuse': int(total_in),
                'expense': int(total_out),
                'profit': int(total_in - total_out),
                })

        return {'data': [revenues, expenses, profits],
                'description': description,
                'items': items}
Ejemplo n.º 8
0
 def _add_date_filter(self):
     self.date_filter = DateSearchFilter(_('Date:'))
     self.date_filter.clear_options()
     self.date_filter.add_option(Any, 0)
     year = datetime.datetime.today().year
     month_names = get_month_names()
     for i, month in enumerate(month_names):
         name = month_names[i]
         option = type(name + 'Option', (MonthOption, ),
                       {'name': _(name),
                        'month': i + 1,
                        'year': year})
         self.date_filter.add_option(option, i + 1)
     self.date_filter.add_custom_options()
     self.date_filter.mode.select_item_by_position(0)
     self.search.add_filter(self.date_filter)
Ejemplo n.º 9
0
    def get_combo_labels(cls):
        values = []
        today = datetime.date.today()
        date = today + relativedelta(day=1)
        year = date.year
        month_names = get_month_names()
        # FIXME: Check database to determine range
        for m in range(6):
            start = date
            end = date + relativedelta(day=31)
            month_name = month_names[start.month - 1]
            if date.year != year:
                month_name += ' ' + str(date.year)
            values.append((month_name, (start, end)))
            date -= relativedelta(months=1)

        start = today - relativedelta(days=30)
        end = today
        values.append((_('Last 30 days'), (start, today)))

        return values
Ejemplo n.º 10
0
    def get_combo_labels(cls):
        values = []
        today = datetime.date.today()
        date = today + relativedelta(day=1)
        year = date.year
        month_names = get_month_names()
        # FIXME: Check database to determine range
        for m in range(6):
            start = date
            end = date + relativedelta(day=31)
            month_name = month_names[start.month - 1]
            if date.year != year:
                month_name += ' ' + str(date.year)
            values.append((month_name, (start, end)))
            date -= relativedelta(months=1)

        start = today - relativedelta(days=30)
        end = today
        values.append((_('Last 30 days'), (start, today)))

        return values
Ejemplo n.º 11
0
    def _startup(self):
        options = {}
        options['monthNames'] = dateutils.get_month_names()
        options['monthNamesShort'] = dateutils.get_short_month_names()
        options['dayNames'] = dateutils.get_day_names()
        options['dayNamesShort'] = dateutils.get_short_day_names()
        options['buttonText'] = {"today": _('today'),
                                 "month": _('month'),
                                 "week": _('week'),
                                 "day": _('day')}
        options['defaultView'] = api.user_settings.get(
            'calendar-view', 'month')

        # FIXME: This should not be tied to the language, rather be
        #        picked up from libc, but it's a bit of work to translate
        #        one into another so just take a shortcut
        options['columnFormat'] = {
            # month column format, eg "Mon", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'month': _('ddd'),
            # week column format: eg, "Mon 9/7", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'week': _('ddd M/d'),
            # day column format : eg "Monday 9/7", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'day': _('dddd M/d'),
        }

        options['timeFormat'] = {
            # for agendaWeek and agendaDay, eg "5:00 - 6:30", see:
            # http://arshaw.com/fullcalendar/docs/text/timeFormat/
            'agenda': _('h:mm{ - h:mm}'),
            # for all other views, eg "7p", see:
            # http://arshaw.com/fullcalendar/docs/text/timeFormat/
            '': _('h(:mm)t'),
        }

        options['titleFormat'] = {
            # month title, eg "September 2009", see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'month': _('MMMM yyyy'),
            # week title, eg "Sep 7 - 13 2009" see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'week': _("MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}"),
            # day time, eg "Tuesday, Sep 8, 2009" see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'day': _('dddd, MMM d, yyyy'),
        }

        if get_weekday_start() == MO:
            firstday = 1
        else:
            firstday = 0

        options['firstDay'] = firstday
        options['isRTL'] = (
            gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL)
        options['data'] = self._show_events
        options['loading_msg'] = _('Loading calendar content, please wait...')
        self.js_function_call('startup', options)
        self._update_title()
Ejemplo n.º 12
0
    def _startup(self):
        options = {}
        options['monthNames'] = dateutils.get_month_names()
        options['monthNamesShort'] = dateutils.get_short_month_names()
        options['dayNames'] = dateutils.get_day_names()
        options['dayNamesShort'] = dateutils.get_short_day_names()
        options['buttonText'] = {
            "today": _('today'),
            "month": _('month'),
            "week": _('week'),
            "day": _('day')
        }
        options['defaultView'] = api.user_settings.get('calendar-view',
                                                       'month')

        # FIXME: This should not be tied to the language, rather be
        #        picked up from libc, but it's a bit of work to translate
        #        one into another so just take a shortcut
        options['columnFormat'] = {
            # month column format, eg "Mon", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'month': _('ddd'),
            # week column format: eg, "Mon 9/7", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'week': _('ddd M/d'),
            # day column format : eg "Monday 9/7", see:
            # http://arshaw.com/fullcalendar/docs/text/columnFormat/
            'day': _('dddd M/d'),
        }

        options['timeFormat'] = {
            # for agendaWeek and agendaDay, eg "5:00 - 6:30", see:
            # http://arshaw.com/fullcalendar/docs/text/timeFormat/
            'agenda': _('h:mm{ - h:mm}'),
            # for all other views, eg "7p", see:
            # http://arshaw.com/fullcalendar/docs/text/timeFormat/
            '': _('h(:mm)t'),
        }

        options['titleFormat'] = {
            # month title, eg "September 2009", see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'month': _('MMMM yyyy'),
            # week title, eg "Sep 7 - 13 2009" see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'week': _("MMM d[ yyyy]{ '&#8212;'[ MMM] d yyyy}"),
            # day time, eg "Tuesday, Sep 8, 2009" see:
            # http://arshaw.com/fullcalendar/docs/text/titleFormat/
            'day': _('dddd, MMM d, yyyy'),
        }

        if get_weekday_start() == MO:
            firstday = 1
        else:
            firstday = 0

        options['firstDay'] = firstday
        options['isRTL'] = (
            gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL)
        options['data'] = self._show_events
        options['loading_msg'] = _('Loading calendar content, please wait...')
        self.js_function_call('startup', options)
        self._update_title()
Ejemplo n.º 13
0
    def run(self, args):
        start = args['start']
        end = args['end']

        if (start.month == 1 and start.day == 1 and end.month == 12
                and end.day == 31):
            description = _("Total revenue, expenses and gross profit for %s"
                            ) % (start.year, )
        else:
            description = _(
                "Total revenue, expenses and gross profit for all months in a year"
            )

        date_columns = "extract(year FROM paid_date)||'-'||lpad(extract(month FROM paid_date)::char, 2, '0')"
        months = {}
        ns = dict(date_columns=date_columns,
                  start=start.strftime('%Y-%m-%d'),
                  end=end.strftime('%Y-%m-%d'))

        tmpl = string.Template(self.in_payments_query).substitute(ns)
        res = self.execute(tmpl)
        for date, total_in in res:
            year, month = map(int, date.split('-'))
            months.setdefault((year, month), {})['in'] = total_in or 0

        tmpl = string.Template(self.out_payments_query).substitute(ns)
        res = self.execute(tmpl)
        for date, total_out in res:
            year, month = map(int, date.split('-'))
            months.setdefault((year, month), {})['out'] = total_out or 0

        revenues = []
        expenses = []
        profits = []

        items = []
        keys = sorted(months)
        for key in keys:
            values = months[key]
            year, month = key
            month = int(month)
            total_in = values.get('in', 0)
            total_out = values.get('out', 0)

            revenues.append(float(total_in))
            expenses.append(float(total_out))
            profits.append(float(total_in - total_out))

            items.append({
                'short_title':
                '%s' % (get_short_month_names()[month - 1], ),
                'time':
                '%s, %d' % (get_month_names()[month - 1], year),
                'revenue':
                int(total_in),
                'expense':
                int(total_out),
                'profit':
                int(total_in - total_out),
                'year':
                year,
                'month':
                month
            })

        return {
            'data': [revenues, expenses, profits],
            'description': description,
            'items': items
        }