当前位置: 首页>>代码示例>>Python>>正文


Python DateSearchFilter.set_use_date_entries方法代码示例

本文整理汇总了Python中stoqlib.gui.search.searchfilters.DateSearchFilter.set_use_date_entries方法的典型用法代码示例。如果您正苦于以下问题:Python DateSearchFilter.set_use_date_entries方法的具体用法?Python DateSearchFilter.set_use_date_entries怎么用?Python DateSearchFilter.set_use_date_entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stoqlib.gui.search.searchfilters.DateSearchFilter的用法示例。


在下文中一共展示了DateSearchFilter.set_use_date_entries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FinancialReportDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import set_use_date_entries [as 别名]
class FinancialReportDialog(BasicDialog):
    title = _("Financial Report Dialog")

    def __init__(self, store):
        self.store = store

        self.date_filter = DateSearchFilter(_("Year:"))
        self.date_filter.clear_options()
        self._populate_date_filter(self.date_filter)
        self.date_filter.select()
        self.date_filter.set_use_date_entries(False)

        BasicDialog.__init__(self, title=self.title)
        self.main_label.set_justify(gtk.JUSTIFY_CENTER)

        self.ok_button.set_label(_("Generate"))
        self.add(self.date_filter)
        self.date_filter.show()

    def confirm(self):
        start = self.date_filter.get_start_date()
        if start is None:
            warning(_("There are no transactions yet"))
            return

        f = FinancialIntervalReport(self.store, start.year)
        if not f.run():
            return
        temporary = tempfile.NamedTemporaryFile(
            # Translators: This will be part of a filename
            prefix=_("stoq-yearly-report"),
            suffix=".xls",
            delete=False,
        )
        f.write(temporary)
        sse = SpreadSheetExporter()
        sse.export_temporary(temporary)

        self.close()
        self.temporary = temporary

    #
    # Private
    #

    def _populate_date_filter(self, date_filter):
        transaction = self.store.find(AccountTransaction).order_by(AccountTransaction.date).first()
        if transaction is None:
            return

        for i in range(transaction.date.year, localtoday().year + 1):
            year = datetime.datetime(i, 1, 1)
            date_filter.add_option_fixed_interval(_("Year %d") % (i,), year, year.replace(month=12, day=31), position=0)

    def _date_filter_query(self, search_spec, column):
        executer = QueryExecuter(self.store)
        executer.set_filter_columns(self.date_filter, [column])
        executer.set_search_spec(search_spec)
        return executer.search([self.date_filter.get_state()])
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:61,代码来源:financialreportdialog.py

示例2: SintegraDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import set_use_date_entries [as 别名]
class SintegraDialog(BasicDialog):
    title = _('Fiscal Printer History')

    def __init__(self, store):
        BasicDialog.__init__(self, title=self.title)
        self.justify_label(gtk.JUSTIFY_CENTER)

        self.store = store
        self.ok_button.set_label(_("Generate"))

        self.date_filter = DateSearchFilter(_('Month:'))
        self.date_filter.set_use_date_entries(False)
        self.date_filter.clear_options()
        self._populate_date_filter(self.date_filter)
        self.date_filter.select()

        self.add(self.date_filter)
        self.date_filter.show()

    def confirm(self):
        start = self.date_filter.get_start_date()
        end = self.date_filter.get_end_date()
        filename = save(_("Save Sintegra file"),
                        self.get_toplevel(),
                        "sintegra-%s.txt" % (start.strftime('%Y-%m'), ))
        if not filename:
            return

        try:
            generator = StoqlibSintegraGenerator(self.store, start, end)
            generator.write(filename)
        except SintegraError as e:
            warning(str(e))
            return

        self.close()

    #
    # Private
    #

    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)

    def _date_filter_query(self, search_table, column):
        executer = QueryExecuter(self.store)
        executer.set_filter_columns(self.date_filter, [column])
        executer.set_table(search_table)
        return executer.search([self.date_filter.get_state()])
开发者ID:tmaxter,项目名称:stoq,代码行数:80,代码来源:sintegradialog.py


注:本文中的stoqlib.gui.search.searchfilters.DateSearchFilter.set_use_date_entries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。