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


Python DateSearchFilter.clear_options方法代码示例

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


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

示例1: add_filter_by_attribute

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
    def add_filter_by_attribute(self, attr, title, data_type, valid_values=None,
                                callback=None, use_having=False,
                                multiple_selection=False):
        """Add a filter accordingly to the attributes specified

        :param attr: attribute that will be filtered. This can be either the
          name of the attribute or the attribute itself.
        :param title: the title of the filter that will be visible in the
                      interface
        :param data_type: the attribute type (str, bool, decimal, etc)
        :param callback: the callback function that will be triggered
        :param use_having: use having expression in the query
        """
        if data_type is not bool:
            title += ':'

        if data_type == datetime.date:
            filter = DateSearchFilter(title)
            if valid_values:
                filter.clear_options()
                filter.add_custom_options()
                for opt in valid_values:
                    filter.add_option(opt)
                filter.select(valid_values[0])

        elif (data_type == decimal.Decimal or
              data_type == int or
              data_type == currency):
            filter = NumberSearchFilter(title)
            if data_type != int:
                filter.set_digits(2)
        elif data_type == str:
            if multiple_selection:
                assert valid_values, "need valid_values for multiple_selection"
                filter = MultiSearchFilter(title, valid_values)
            elif valid_values:
                filter = ComboSearchFilter(title, valid_values)
                filter.enable_advanced()
            else:
                filter = StringSearchFilter(title)
                filter.enable_advanced()
        elif data_type == bool:
            filter = BoolSearchFilter(title)
        else:
            raise NotImplementedError(title, data_type)

        filter.set_removable()
        self.add_filter(filter, columns=[attr],
                        callback=callback,
                        use_having=use_having)

        if data_type is not bool:
            label = filter.get_title_label()
            label.set_alignment(1.0, 0.5)
            self.label_group.add_widget(label)
        combo = filter.get_mode_combo()
        if combo:
            self.combo_group.add_widget(combo)

        return filter
开发者ID:Guillon88,项目名称:stoq,代码行数:62,代码来源:searchslave.py

示例2: FinancialReportDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [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

示例3: PaymentFlowHistoryDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
class PaymentFlowHistoryDialog(BasicDialog):
    title = _(u'Payment Flow History Dialog')
    desc = _("Select a date or a range to be visualised in the report:")
    size = (-1, -1)
    model_type = PaymentFlowDay

    def __init__(self, store):
        """A dialog to print the PaymentFlowHistoryReport report.

        :param store: a store
        """
        self.store = store
        BasicDialog.__init__(self, header_text='<b>%s</b>' % self.desc,
                             title=self.title)
        self._setup_widgets()

    #
    # BasicDialog
    #

    def confirm(self):
        state = self._date_filter.get_state()
        from stoqlib.database.queryexecuter import DateQueryState
        if isinstance(state, DateQueryState):
            start, end = state.date, state.date
        else:
            start, end = state.start, state.end

        results = PaymentFlowDay.get_flow_history(self.store, start, end)
        if not results:
            info(_('No payment history found.'))
            return False

        print_report(PaymentFlowHistoryReport, payment_histories=results)
        return True

    #
    # Private
    #

    def _setup_widgets(self):
        self.ok_button.set_label(gtk.STOCK_PRINT)

        self._date_filter = DateSearchFilter(_(u'Date:'))
        # FIXME: add a remove_option method in DateSearchFilter.
        self._date_filter.clear_options()
        self._date_filter.add_custom_options()
        for option in [Today, Yesterday, LastWeek, LastMonth]:
            self._date_filter.add_option(option)
        self._date_filter.select(position=0)

        self.vbox.pack_start(self._date_filter, False, False)
        self._date_filter.show_all()
开发者ID:LeonamSilva,项目名称:stoq,代码行数:55,代码来源:paymentflowhistorydialog.py

示例4: add_filter_by_column

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
    def add_filter_by_column(self, column):
        """Add a filter accordingly to the column specification

        :param column: a SearchColumn instance
        """
        title = column.get_search_label()
        if column.data_type is not bool:
            title += ':'

        if column.data_type == datetime.date:
            filter = DateSearchFilter(title)
            if column.valid_values:
                filter.clear_options()
                filter.add_custom_options()
                for opt in column.valid_values:
                    filter.add_option(opt)
                filter.select(column.valid_values[0])

        elif (column.data_type == decimal.Decimal or
              column.data_type == int or
              column.data_type == currency):
            filter = NumberSearchFilter(title)
            if column.data_type != int:
                filter.set_digits(2)
        elif column.data_type == str:
            if column.valid_values:
                filter = ComboSearchFilter(title, column.valid_values)
            else:
                filter = StringSearchFilter(title)
            filter.enable_advanced()
        elif column.data_type == bool:
            filter = BoolSearchFilter(title)
        else:
            raise NotImplementedError(title, column.data_type)

        filter.set_removable()
        attr = column.search_attribute or column.attribute
        self.add_filter(filter, columns=[attr],
                        callback=column.search_func,
                        use_having=column.use_having)

        if column.data_type is not bool:
            label = filter.get_title_label()
            label.set_alignment(1.0, 0.5)
            self.label_group.add_widget(label)
        combo = filter.get_mode_combo()
        if combo:
            self.combo_group.add_widget(combo)

        return filter
开发者ID:igorferreira,项目名称:stoq,代码行数:52,代码来源:searchslave.py

示例5: DateRangeDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
class DateRangeDialog(BasicDialog):
    """A simple dialog for selecting a date range

    When confirmed, a :class:`date_range` object will be returned
    containig the information about the date range selected
    """

    title = _(u'Select a date range')
    size = (-1, -1)

    def __init__(self, title=None, header_text=None):
        title = title or self.title
        header_text = '<b>%s</b>' % header_text if header_text else ''
        BasicDialog.__init__(self, title=title, header_text=header_text)

        self._setup_widgets()

    #
    #  BasicDialog
    #

    def confirm(self):
        BasicDialog.confirm(self)

        state = self.date_filter.get_state()
        if isinstance(state, DateQueryState):
            start, end = state.date, state.date
        else:
            start, end = state.start, state.end

        self.retval = date_range(start=start, end=end)

    #
    #  Private
    #

    def _setup_widgets(self):
        self.date_filter = DateSearchFilter(_(u'Date:'))
        # FIXME: add a remove_option method in DateSearchFilter.
        self.date_filter.clear_options()
        self.date_filter.add_custom_options()
        for option in [Today, Yesterday, LastWeek, LastMonth]:
            self.date_filter.add_option(option)
        self.date_filter.select(position=0)

        self.vbox.pack_start(self.date_filter, False, False)
        self.date_filter.show_all()
开发者ID:Guillon88,项目名称:stoq,代码行数:49,代码来源:daterangedialog.py

示例6: TransactionPage

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
class TransactionPage(object):
    # shows either a list of:
    #   - transactions
    #   - payments
    def __init__(self, model, app, parent):
        self.model = model
        self.app = app
        self.parent_window = parent
        self._block = False

        self._create_search()
        self._add_date_filter()

        self._setup_search()
        self.refresh()

    def get_toplevel(self):
        return self.parent_window

    def _create_search(self):
        self.search = SearchSlave(self._get_columns(self.model.kind),
                                  store=self.app.store)
        self.search.connect('result-item-activated',
                            self._on_search__item_activated)
        self.search.enable_advanced_search()
        self.search.set_result_view(FinancialSearchResults)
        self.result_view = self.search.result_view
        self.result_view.page = self
        tree_view = self.search.result_view.get_treeview()
        tree_view.set_rules_hint(True)
        tree_view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)

    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)

    def _append_date_query(self, field):
        date = self.date_filter.get_state()
        queries = []
        if isinstance(date, DateQueryState) and date.date is not None:
            queries.append(Date(field) == date.date)
        elif isinstance(date, DateIntervalQueryState):
            queries.append(Date(field) >= date.start)
            queries.append(Date(field) <= date.end)
        return queries

    def _payment_query(self, store):
        executer = self.search.get_query_executer()
        search_spec = executer.search_spec
        queries = self._append_date_query(search_spec.due_date)
        if queries:
            return store.find(search_spec, And(*queries))

        return store.find(search_spec)

    def _transaction_query(self, store):
        queries = [Or(self.model.id == AccountTransaction.account_id,
                      self.model.id == AccountTransaction.source_account_id)]

        queries.extend(self._append_date_query(AccountTransaction.date))
        return store.find(AccountTransactionView, And(*queries))

    def show(self):
        self.search.show()

    def _setup_search(self):
        if self.model.kind == 'account':
            self.search.set_search_spec(AccountTransactionView)
            self.search.set_text_field_columns(['description'])
            self.search.set_query(self._transaction_query)
        elif self.model.kind == 'payable':
            self.search.set_text_field_columns(['description', 'supplier_name'])
            self.search.set_search_spec(OutPaymentView)
            self.search.set_query(self._payment_query)
        elif self.model.kind == 'receivable':
            self.search.set_text_field_columns(['description', 'drawee'])
            self.search.set_search_spec(InPaymentView)
            self.search.set_query(self._payment_query)
        else:
            raise TypeError("unknown model kind: %r" % (self.model.kind, ))

    def refresh(self):
        self.search.result_view.clear()
        if self.model.kind == 'account':
            transactions = AccountTransactionView.get_for_account(self.model, self.app.store)
            self.append_transactions(transactions)
        elif self.model.kind == 'payable':
#.........这里部分代码省略.........
开发者ID:leandrorchaves,项目名称:stoq,代码行数:103,代码来源:financial.py

示例7: TillDailyMovementDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [as 别名]
class TillDailyMovementDialog(BaseEditor):
    """Shows informations related to till operations over a daterange.
    It can also be filtered by branch.
    """

    title = _("Daily Movement")
    hide_footer = True
    size = (950, 450)
    model_type = Settable
    gladefile = "TillDailyMovementDialog"
    proxy_widgets = ['branch', 'in_subtotal', 'in_credit', 'in_total',
                     'out_subtotal', 'out_credit', 'out_total']

    #
    #  Private
    #

    def _setup_widgets(self):
        # Branches combo
        items = api.get_branches_for_filter(self.store)
        self.branch.prefill(items)

        # Daterange filter
        self.date_filter = DateSearchFilter(_(u'Date:'))
        self.date_filter.clear_options()
        self.date_filter.add_custom_options()
        for option in [Today, Yesterday, LastWeek, LastMonth]:
            self.date_filter.add_option(option)
        self.date_filter.select(position=0)
        self.daterange_hbox.pack_start(self.date_filter, False, False, 0)
        self.date_filter.show_all()

        # Setting report lists' columns
        self.sales_list.set_columns(self._get_sales_columns())
        self.inpayments_list.set_columns(self._get_lonely_payments_columns())
        self.purchases_list.set_columns(self._get_purchases_columns())
        self.outpayments_list.set_columns(self._get_lonely_payments_columns())
        self.return_sales_list.set_columns(self._get_return_sales_columns())
        self.supplies_list.set_columns(self._get_till_columns())
        self.removals_list.set_columns(self._get_till_columns())
        self.permethod_list.set_columns(self._get_permethod_columns())
        self.percard_list.set_columns(self._get_percard_columns())

        # Print button is insensitive, until the first report is generated
        self.print_button.set_sensitive(False)

        self._setup_summary_labels()

    def _get_sales_columns(self):
        return [IdentifierColumn('identifier', title=_('Sale #'), sorted=True),
                Column('salesperson', title=_('Sales Person'), data_type=str),
                Column('client', title=_('Client'), data_type=str, expand=True),
                Column('branch', title=_('Branch'), data_type=str, visible=False),
                Column('value', title=_('Value'), data_type=str,
                       justify=Gtk.Justification.RIGHT)]

    def _get_lonely_payments_columns(self):
        return [IdentifierColumn('identifier', title=_('Payment #'), sorted=True),
                Column('method', title=_('Method'), data_type=str),
                Column('description', title=_('Description'), expand=True,
                       data_type=str),
                Column('branch', title=_('Branch'), data_type=str, visible=False),
                Column('value', title=_('Payment Value'), data_type=currency)]

    def _get_purchases_columns(self):
        return [IdentifierColumn('identifier', title=_('Code #'), sorted=True),
                Column('status_str', title=_('Status'), data_type=str),
                Column('responsible_name', title=_('Responsible'), expand=True,
                       data_type=str),
                Column('branch_name', title=_('Branch'), data_type=str),
                Column('notes', title=_('Notes'), data_type=str),
                Column('supplier_name', title=_('Supplier'), data_type=str),
                Column('purchase_total', title=_('Value'), data_type=currency)]

    def _get_return_sales_columns(self):
        return [IdentifierColumn('identifier', title=_('Code #'), sorted=True),
                Column('salesperson', title=_('Sales Person'), data_type=str),
                Column('client', title=_('Client'), expand=True, data_type=str),
                Column('return_date', title=_('Return Date'),
                       data_type=datetime.date),
                Column('branch', title=_('Branch'), data_type=str, visible=False),
                Column('value', title=_('Sale Value'), data_type=currency)]

    def _get_till_columns(self):
        return [IdentifierColumn('identifier', title=_('Entry #'), sorted=True),
                Column('description', title=_('Description'), data_type=str,
                       expand=True),
                Column('branch_name', title=_('Branch'), data_type=str, visible=False),
                Column('value', title=_('Value'), data_type=currency)]

    def _get_permethod_columns(self):
        return [Column('method', title=_('Payment Method'), sorted=True,
                       expand=True),
                Column('in_value', title=_('Income Total'), data_type=currency),
                Column('out_value', title=_('Outgoing Total'),
                       data_type=currency)]

    def _get_percard_columns(self):
        return [Column('provider', title=_('Provider Name'), data_type=str,
                       expand=True),
#.........这里部分代码省略.........
开发者ID:hackedbellini,项目名称:stoq,代码行数:103,代码来源:tilldailymovement.py

示例8: SintegraDialog

# 需要导入模块: from stoqlib.gui.search.searchfilters import DateSearchFilter [as 别名]
# 或者: from stoqlib.gui.search.searchfilters.DateSearchFilter import clear_options [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.clear_options方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。