• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python searchslave.SearchSlave类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stoqlib.gui.search.searchslave.SearchSlave的典型用法代码示例。如果您正苦于以下问题:Python SearchSlave类的具体用法?Python SearchSlave怎么用?Python SearchSlave使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: __init__

    def __init__(
        self, store, columns=None, editor_class=None, klist_objects=None, visual_mode=False, restore_name=None
    ):
        """ Creates a new AdditionListSlave object

        :param store:         a store
        :param columns:       column definitions
        :type columns:        sequence of :class:`kiwi.ui.widgets.list.Columns`
        :param editor_class:  the window that is going to be open when user
                              clicks on add_button or edit_button.
        :type: editor_class:  a :class:`stoqlib.gui.editors.BaseEditor` subclass
        :param klist_objects: initial objects to insert into the list
        :param visual_mode:   if we are working on visual mode, that means,
                              not possible to edit the model on this object
        type visual_mode:     bool
        :param restore_name:  the name used to save and restore the columns
                              on a cache system (e.g. pickle)
        :type restore_name:   basestring
        """
        columns = columns or self.get_columns()
        SearchSlave.__init__(self, columns=columns, restore_name=restore_name, store=store)
        if not self.columns:
            raise StoqlibError("columns must be specified")
        self.visual_mode = visual_mode
        self.store = store
        self.set_editor(editor_class)
        self._can_edit = True
        self._callback_id = None
        if self.visual_mode:
            self.hide_add_button()
            self.hide_edit_button()
            self.hide_del_button()
        items = klist_objects or self.get_items()
        self._setup_klist(items)
        self._update_sensitivity()
开发者ID:rosalin,项目名称:stoq,代码行数:35,代码来源:lists.py


示例2: _setup_search

    def _setup_search(self):
        self.columns = self.get_columns()
        SearchDialogSetupSearchEvent.emit(self)
        if self.save_columns:
            restore_name = self.__class__.__name__
        else:
            restore_name = None
        self.search = SearchSlave(
            self.columns,
            tree=self.tree,
            restore_name=restore_name,
            store=self.store,
            search_spec=self.search_spec,
            fast_iter=self.fast_iter,
            result_view_class=self.result_view_class
        )
        if self.advanced_search:
            self.search.enable_advanced_search()
        self.attach_slave('main', self.search)
        self.header.hide()

        self.results = self.search.result_view
        self.results.set_selection_mode(self.selection_mode)
        self.results.connect('cell-edited', self._on_results__cell_edited)
        self.results.connect('selection-changed',
                             self._on_results__selection_changed)
        self.results.connect('row-activated', self._on_results__row_activated)
开发者ID:hackedbellini,项目名称:stoq,代码行数:27,代码来源:searchdialog.py


示例3: _create_search

 def _create_search(self):
     if self.search_spec is None:
         return
     self.search = SearchSlave(self.get_columns(),
                               store=self.store,
                               restore_name=self.__class__.__name__,
                               search_spec=self.search_spec)
开发者ID:LeonamSilva,项目名称:stoq,代码行数:7,代码来源:shellapp.py


示例4: _create_search

 def _create_search(self):
     if self.search_spec is None:
         return
     self.columns = self.get_columns()
     ApplicationSetupSearchEvent.emit(self)
     self.search = SearchSlave(
         self.columns, store=self.store, restore_name=self.__class__.__name__, search_spec=self.search_spec
     )
开发者ID:amaurihamasu,项目名称:stoq,代码行数:8,代码来源:shellapp.py


示例5: _create_search

 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)
开发者ID:leandrorchaves,项目名称:stoq,代码行数:12,代码来源:financial.py


示例6: _create_search

 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
     self.result_view.set_cell_data_func(self._on_result_view__cell_data_func)
     tree_view = self.search.result_view.get_treeview()
     tree_view.set_rules_hint(True)
     tree_view.set_grid_lines(Gtk.TreeViewGridLines.BOTH)
开发者ID:hackedbellini,项目名称:stoq,代码行数:13,代码来源:financial.py


示例7: _create_search

 def _create_search(self):
     self.search = SearchSlave(self._get_columns(),
                               restore_name=self.__class__.__name__,
                               store=self.store,
                               search_spec=PurchaseOrderView)
     self.search.enable_advanced_search()
     self.attach_slave('searchbar_holder', self.search)
     executer = self.search.get_query_executer()
     executer.add_query_callback(self.get_extra_query)
     self._create_filters()
     self.search.results.connect('selection-changed',
                                 self._on_results__selection_changed)
     self.search.results.connect('row-activated',
                                 self._on_results__row_activated)
     self.search.focus_search_entry()
开发者ID:pkaislan,项目名称:stoq,代码行数:15,代码来源:receivingwizard.py


示例8: _setup_search

    def _setup_search(self):
        self.search = SearchSlave(
            self.get_columns(),
            tree=self.tree,
            restore_name=self.__class__.__name__,
            store=self.store,
            search_spec=self.search_spec,
        )
        if self.advanced_search:
            self.search.enable_advanced_search()
        self.attach_slave("main", self.search)
        self.header.hide()

        self.results = self.search.result_view
        self.results.set_selection_mode(self.selection_mode)
        self.results.connect("cell-edited", self._on_results__cell_edited)
        self.results.connect("selection-changed", self._on_results__selection_changed)
        self.results.connect("row-activated", self._on_results__row_activated)
开发者ID:rg3915,项目名称:stoq,代码行数:18,代码来源:searchdialog.py


示例9: _setup_search

    def _setup_search(self):
        self.search = SearchSlave(
            self.get_columns(),
            tree=self.tree,
            restore_name=self.__class__.__name__,
        )
        self.search.set_query_executer(self.executer)
        if self.advanced_search:
            self.search.enable_advanced_search()
        self.attach_slave('main', self.search)
        self.header.hide()

        self.results = self.search.result_view
        self.results.set_selection_mode(self.selection_mode)
        self.results.connect('cell-edited', self._on_results__cell_edited)
        self.results.connect('selection-changed',
                             self._on_results__selection_changed)
        self.results.connect('row-activated', self._on_results__row_activated)
开发者ID:tmaxter,项目名称:stoq,代码行数:18,代码来源:searchdialog.py


示例10: _setup_slaves

    def _setup_slaves(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  search_spec=QuotationView,
                                  store=self.store)
        self.attach_slave('search_group_holder', self.search)

        self.search.set_text_field_columns(['supplier_name', 'identifier_str'])
        filter = self.search.get_primary_filter()
        filter.set_label(_(u'Supplier:'))
        self.search.focus_search_entry()
        self.search.results.connect('selection-changed',
                                    self._on_searchlist__selection_changed)
        self.search.results.connect('row-activated',
                                    self._on_searchlist__row_activated)

        date_filter = DateSearchFilter(_('Date:'))
        self.search.add_filter(date_filter, columns=['open_date', 'deadline'])

        self.edit_button.set_sensitive(False)
        self.remove_button.set_sensitive(False)
开发者ID:pkaislan,项目名称:stoq,代码行数:21,代码来源:purchasequotewizard.py


示例11: ReceivingSelectionStep

class ReceivingSelectionStep(BaseWizardStep):
    gladefile = 'PurchaseSelectionStep'

    def __init__(self, wizard, store):
        self._next_step = None
        BaseWizardStep.__init__(self, store, wizard)
        self.setup_slaves()

    def _create_search(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  store=self.store,
                                  search_spec=PurchaseReceivingView)
        self.search.enable_advanced_search()
        self.attach_slave('searchbar_holder', self.search)
        executer = self.search.get_query_executer()
        executer.add_query_callback(self.get_extra_query)
        self._create_filters()
        self.search.result_view.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
        self.search.result_view.connect('selection-changed',
                                        self._on_results__selection_changed)
        self.search.result_view.connect('row-activated',
                                        self._on_results__row_activated)
        self.search.focus_search_entry()

    def _create_filters(self):
        self.search.set_text_field_columns(['supplier_name', 'purchase_identifier'])

    def get_extra_query(self, states):
        query = And(Eq(PurchaseReceivingView.purchase_group, None),
                    Eq(PurchaseReceivingView.receiving_invoice, None))

        # Dont let the user receive purchases from other branches when working
        # in synchronized mode
        if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and not
                api.can_see_all_branches()):
            branch = api.get_current_branch(self.store)
            query = And(query, PurchaseReceivingView.branch_id == branch.id)
        return query

    def _get_columns(self):
        return [IdentifierColumn('identifier', _('Receiving #'), width=140),
                IdentifierColumn('purchase_identifier', _('Purchase #'), width=110),
                SearchColumn('packing_number', title=_('Packing Number'),
                             data_type=str, visible=False),
                SearchColumn('receival_date', _('Receival date'), expand=True,
                             data_type=datetime.date, sorted=True, width=110),
                SearchColumn('supplier_name', _('Supplier'), data_type=str,
                             expand=True),
                SearchColumn('responsible_name', _('Responsible'),
                             data_type=str, visible=False, expand=True),
                SearchColumn('purchase_responsible_name', _('Purchaser'),
                             data_type=str, visible=False, expand=True),
                SearchColumn('invoice_number', _('Invoice #'), data_type=int,
                             width=80),
                Column('subtotal', title=_('Products total'),
                       data_type=currency, width=150)]

    def _update_view(self):
        selected_rows = self.search.result_view.get_selected_rows()
        can_continue = len(set((v.supplier_id, v.branch_id) for v in selected_rows)) == 1
        self.wizard.refresh_next(can_continue)
        self.details_button.set_sensitive(len(selected_rows) == 1)

    #
    # WizardStep hooks
    #

    def post_init(self):
        self._update_view()
        self.force_validation()

    def next_step(self):
        self.search.save_columns()
        selected_rows = self.search.result_view.get_selected_rows()

        return ProductsCostCheckStep(self.wizard, self, self.store, selected_rows)

    def has_previous_step(self):
        return False

    def setup_slaves(self):
        self._create_search()

    #
    # Kiwi callbacks
    #

    def _on_results__selection_changed(self, results, purchase_order_view):
        self.force_validation()
        self._update_view()

    def _on_results__row_activated(self, results, receiving_order_view):
        run_dialog(ReceivingOrderDetailsDialog, self.wizard, self.store,
                   model=receiving_order_view.order)

    def on_details_button__clicked(self, *args):
        selected = self.search.results.get_selected_rows()[0]
        if not selected:
            raise ValueError('You should have one order selected '
#.........这里部分代码省略.........
开发者ID:hackedbellini,项目名称:stoq,代码行数:101,代码来源:reconciliationwizard.py


示例12: PurchaseSelectionStep

class PurchaseSelectionStep(BaseWizardStep):
    gladefile = 'PurchaseSelectionStep'

    def __init__(self, wizard, store):
        self._next_step = None
        BaseWizardStep.__init__(self, store, wizard)
        self.setup_slaves()

    def _create_search(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  store=self.store,
                                  search_spec=PurchaseOrderView)
        self.search.enable_advanced_search()
        self.attach_slave('searchbar_holder', self.search)
        executer = self.search.get_query_executer()
        executer.add_query_callback(self.get_extra_query)
        self._create_filters()
        self.search.result_view.set_selection_mode(gtk.SELECTION_MULTIPLE)
        self.search.result_view.connect('selection-changed',
                                        self._on_results__selection_changed)
        self.search.result_view.connect('row-activated',
                                        self._on_results__row_activated)
        self.search.focus_search_entry()

    def _create_filters(self):
        self.search.set_text_field_columns(['supplier_name', 'identifier_str'])

    def get_extra_query(self, states):
        query = PurchaseOrderView.status == PurchaseOrder.ORDER_CONFIRMED

        # Dont let the user receive purchases from other branches when working
        # in synchronized mode
        if api.sysparam.get_bool('SYNCHRONIZED_MODE'):
            branch = api.get_current_branch(self.store)
            query = And(query,
                        PurchaseOrderView.branch_id == branch.id)
        return query

    def _get_columns(self):
        return [IdentifierColumn('identifier', sorted=True),
                SearchColumn('open_date', title=_('Date Started'),
                             data_type=datetime.date, width=100),
                SearchColumn('expected_receival_date', data_type=datetime.date,
                             title=_('Expected Receival'), visible=False),
                SearchColumn('supplier_name', title=_('Supplier'),
                             data_type=str, searchable=True, width=130,
                             expand=True),
                SearchColumn('ordered_quantity', title=_('Qty Ordered'),
                             data_type=Decimal, width=110,
                             format_func=format_quantity),
                SearchColumn('received_quantity', title=_('Qty Received'),
                             data_type=Decimal, width=145,
                             format_func=format_quantity),
                SearchColumn('total', title=_('Order Total'),
                             data_type=currency, width=120)]

    def _update_view(self):
        selected_rows = self.search.result_view.get_selected_rows()
        can_continue = len(set((v.supplier_id, v.branch_id) for v in selected_rows)) == 1
        self.wizard.refresh_next(can_continue)
        self.details_button.set_sensitive(len(selected_rows) == 1)

    #
    # WizardStep hooks
    #

    def post_init(self):
        self._update_view()
        self.force_validation()

    def next_step(self):
        self.search.save_columns()
        selected_rows = self.search.result_view.get_selected_rows()

        return ReceivingOrderItemStep(self.store, self.wizard, self,
                                      selected_rows)

    def has_previous_step(self):
        return False

    def setup_slaves(self):
        self._create_search()

    #
    # Kiwi callbacks
    #

    def _on_results__selection_changed(self, results, purchase_order_view):
        self.force_validation()
        self._update_view()

    def _on_results__row_activated(self, results, purchase_order_view):
        run_dialog(PurchaseDetailsDialog, self.wizard, self.store,
                   model=purchase_order_view.purchase)

    def on_details_button__clicked(self, *args):
        selected = self.search.results.get_selected_rows()[0]
        if not selected:
            raise ValueError('You should have one order selected '
#.........这里部分代码省略.........
开发者ID:barkinet,项目名称:stoq,代码行数:101,代码来源:receivingwizard.py


示例13: LoanSelectionStep

class LoanSelectionStep(BaseWizardStep):
    gladefile = 'HolderTemplate'

    def __init__(self, wizard, store):
        BaseWizardStep.__init__(self, store, wizard)
        self.setup_slaves()

    def _create_filters(self):
        self.search.set_text_field_columns(['client_name', 'identifier_str'])

    def _get_columns(self):
        return [IdentifierColumn('identifier', sorted=True),
                SearchColumn('responsible_name', title=_(u'Responsible'),
                             data_type=str, expand=True),
                SearchColumn('client_name', title=_(u'Client'),
                             data_type=str, expand=True),
                SearchColumn('open_date', title=_(u'Opened'),
                             data_type=datetime.date),
                SearchColumn('expire_date', title=_(u'Expire'),
                             data_type=datetime.date),
                Column('loaned', title=_(u'Loaned'),
                       data_type=Decimal),
                ]

    def _refresh_next(self, value=None):
        can_continue = False
        selected_rows = self.search.results.get_selected_rows()
        if selected_rows:
            client = selected_rows[0].client_id
            branch = selected_rows[0].branch_id
            # Only loans that belong to the same client and are from the same
            # branch can be closed together
            can_continue = all(v.client_id == client and v.branch_id == branch
                               for v in selected_rows)
        self.wizard.refresh_next(can_continue)

    def get_extra_query(self, states):
        return LoanView.status == Loan.STATUS_OPEN

    def setup_slaves(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  store=self.store,
                                  search_spec=LoanView)
        self.search.enable_advanced_search()
        self.attach_slave('place_holder', self.search)
        executer = self.search.get_query_executer()
        executer.add_query_callback(self.get_extra_query)
        self._create_filters()
        self.search.results.connect('selection-changed',
                                    self._on_results_selection_changed)
        self.search.results.set_selection_mode(gtk.SELECTION_MULTIPLE)
        self.search.focus_search_entry()

    #
    # WizardStep
    #

    def has_previous_step(self):
        return False

    def post_init(self):
        self.register_validate_function(self._refresh_next)
        self.force_validation()

    def next_step(self):
        # FIXME: For some reason, the loan isn't in self.store
        views = self.search.results.get_selected_rows()
        self.wizard.models = [self.store.fetch(v.loan) for v in views]
        return LoanItemSelectionStep(self.wizard, self, self.store,
                                     self.wizard.models)

    #
    # Callbacks
    #

    def _on_results_selection_changed(self, widget, selection):
        self._refresh_next()
开发者ID:qman1989,项目名称:stoq,代码行数:78,代码来源:loanwizard.py


示例14: QuoteGroupSelectionStep

class QuoteGroupSelectionStep(BaseWizardStep):
    gladefile = 'QuoteGroupSelectionStep'

    def __init__(self, wizard, store):
        self._next_step = None
        BaseWizardStep.__init__(self, store, wizard)
        self._setup_slaves()

    def _setup_slaves(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  search_spec=QuotationView,
                                  store=self.store)
        self.attach_slave('search_group_holder', self.search)

        self.search.set_text_field_columns(['supplier_name', 'identifier_str'])
        filter = self.search.get_primary_filter()
        filter.set_label(_(u'Supplier:'))
        self.search.focus_search_entry()
        self.search.results.connect('selection-changed',
                                    self._on_searchlist__selection_changed)
        self.search.results.connect('row-activated',
                                    self._on_searchlist__row_activated)

        date_filter = DateSearchFilter(_('Date:'))
        self.search.add_filter(date_filter, columns=['open_date', 'deadline'])

        self.edit_button.set_sensitive(False)
        self.remove_button.set_sensitive(False)

    def _get_columns(self):
        return [IdentifierColumn('identifier', title=_("Quote #"), sorted=True),
                IdentifierColumn('group_identifier', title=_('Group #')),
                Column('supplier_name', title=_('Supplier'), data_type=str,
                       width=300),
                Column('open_date', title=_('Open date'),
                       data_type=datetime.date),
                Column('deadline', title=_('Deadline'),
                       data_type=datetime.date)]

    def _can_purchase(self, item):
        return item.cost > currency(0) and item.quantity > Decimal(0)

    def _can_order(self, quotation):
        if quotation is None:
            return False

        for item in quotation.purchase.get_items():
            if not self._can_purchase(item):
                return False
        return True

    def _update_view(self):
        selected = self.search.results.get_selected()
        has_selected = selected is not None
        self.edit_button.set_sensitive(has_selected)
        self.remove_button.set_sensitive(has_selected)
        self.wizard.refresh_next(self._can_order(selected))

    def _run_quote_editor(self):
        store = api.new_store()
        selected = store.fetch(self.search.results.get_selected().purchase)
        retval = run_dialog(QuoteFillingDialog, self.wizard, selected, store)
        store.confirm(retval)
        store.close()
        self._update_view()

    def _remove_quote(self):
        q = self.search.results.get_selected().quotation
        msg = _('Are you sure you want to remove "%s" ?') % q.get_description()
        if not yesno(msg, gtk.RESPONSE_NO,
                     _("Remove quote"), _("Don't remove")):
            return

        store = api.new_store()
        group = store.fetch(q.group)
        quote = store.fetch(q)
        group.remove_item(quote)
        # there is no reason to keep the group if there's no more quotes
        if group.get_items().count() == 0:
            store.remove(group)
        store.confirm(True)
        store.close()
        self.search.refresh()

    #
    # WizardStep hooks
    #

    def next_step(self):
        self.search.save_columns()
        selected = self.search.results.get_selected()
        if selected is None:
            return

        return QuoteGroupItemsSelectionStep(self.wizard, self.store,
                                            selected.group, self)

    #
    # Callbacks
#.........这里部分代码省略.........
开发者ID:pkaislan,项目名称:stoq,代码行数:101,代码来源:purchasequotewizard.py


示例15: SearchDialog


#.........这里部分代码省略.........

        self.enable_window_controls()
        self.disable_ok()
        self.set_ok_label(_('Se_lect Items'))
        self._setup_search()
        self._setup_details_slave()

        self._create_default_filters()
        self.create_filters()
        self.setup_widgets()
        if self.search_label:
            self.set_searchbar_label(self.search_label)

        if self.initial_string:
            search_filter = self.search.get_primary_filter()
            search_filter.set_state(self.initial_string)
            self.search.refresh()
            search_filter.entry.grab_focus()

    def _setup_selection_mode(self, selection_mode):
        # For consistency do not allow none or single, in other words,
        # only allowed values are browse and multiple so we always will
        # be able to use both the keyboard and the mouse to select items
        # in the search list.
        selection_mode = selection_mode or self.selection_mode
        if (selection_mode != gtk.SELECTION_BROWSE and
            selection_mode != gtk.SELECTION_MULTIPLE):
            raise ValueError('Invalid selection mode %r' % selection_mode)
        return selection_mode

    def _setup_search(self):
        self.columns = self.get_columns()
        SearchDialogSetupSearchEvent.emit(self)
        self.search = SearchSlave(
            self.columns,
            tree=self.tree,
            restore_name=self.__class__.__name__,
            store=self.store,
            search_spec=self.search_spec,
            fast_iter=self.fast_iter,
            result_view_class=self.result_view_class
        )
        if self.advanced_search:
            self.search.enable_advanced_search()
        self.attach_slave('main', self.search)
        self.header.hide()

        self.results = self.search.result_view
        self.results.set_selection_mode(self.selection_mode)
        self.results.connect('cell-edited', self._on_results__cell_edited)
        self.results.connect('selection-changed',
                             self._on_results__selection_changed)
        self.results.connect('row-activated', self._on_results__row_activated)

    def _setup_details_slave(self):
        # FIXME: Gross hack
        has_details_btn = hasattr(self, 'on_details_button_clicked')
        has_print_btn = self.report_class is not None
        self.results.connect('has-rows', self._has_rows)
        if not (has_details_btn or has_print_btn):
            self._details_slave = None
            return
        self._details_slave = _SearchDialogDetailsSlave()
        self.attach_slave('details_holder', self._details_slave)
        if has_details_btn:
            self._details_slave.connect("details",
开发者ID:Guillon88,项目名称:stoq,代码行数:67,代码来源:searchdialog.py


示例16: TransactionPage

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,代码行数:101,代码来源:financial.py


示例17: PurchaseSelectionStep

class PurchaseSelectionStep(BaseWizardStep):
    gladefile = 'PurchaseSelectionStep'

    def __init__(self, wizard, store):
        self._next_step = None
        BaseWizardStep.__init__(self, store, wizard)
        self.setup_slaves()

    def _refresh_next(self, validation_value):
        has_selection = self.search.results.get_selected() is not None
        self.wizard.refresh_next(has_selection)

    def _create_search(self):
        self.search = SearchSlave(self._get_columns(),
                                  restore_name=self.__class__.__name__,
                                  store=self.store,
                                  search_spec=PurchaseOrderView)
        self.search.enable_advanced_search()
        self.attach_slave('searchbar_holder', self.search)
        executer = self.search.get_query_executer()
        executer.add_query_callback(self.get_extra_query)
        self._create_filters()
        self.search.results.connect('selection-changed',
                                    self._on_results__selection_changed)
        self.search.results.connect('row-activated',
                                    self._on_results__row_activated)
        self.search.focus_search_entry()

    def _create_filters(self):
        self.search.set_text_field_columns(['supplier_name', 'identifier_str'])

    def get_extra_query(self, states):
        query = PurchaseOrderView.status == PurchaseOrder.ORDER_CONFIRMED

        # Dont let the user receive purchases from other branches when working
        # in synchronized mode
        if api.sysparam.get_bool('SYNCHRONIZED_MODE'):
            branch = api.get_current_branch(self.store)
            query = And(query,
                        PurchaseOrderView.branch_id == branch.id)
        return query

    def _get_columns(self):
        return [IdentifierColumn('identifier', sorted=True),
                SearchColumn('open_date', title=_('Date Started'),
                             data_type=datetime.date, width=100),
                SearchColumn('expected_receival_date', data_type=datetime.date,
                             title=_('Expected Receival'), visible=False),
                SearchColumn('supplier_name', title=_('Supplier'),
                             data_type=str, searchable=True, width=130,
                             expand=True),
                SearchColumn('ordered_quantity', title=_('Qty Ordered'),
                             data_type=Decimal, width=110,
                             format_func=format_quantity),
                SearchColumn('received_quantity', title=_('Qty Received'),
                             data_type=Decimal, width=145,
                             format_func=format_quantity),
                SearchColumn('total', title=_('Order Total'),
                             data_type=currency, width=120)]

    def _update_view(self):
        has_selection = self.search.results.get_selected() is not None
        self.details_button.set_sensitive(has_selection)

    #
    # WizardStep hooks
    #

    def post_init(self):
        self._update_view()
        self.register_validate_function(self._refresh_next)
        self.force_validation()

    def next_step(self):
        self.search.save_columns()
        selected = self.search.results.get_selected()
        purchase = selected.purchase

        # We cannot create the model in the wizard since we haven't
        # selected a PurchaseOrder yet which ReceivingOrder depends on
        # Create the order here since this is the first place where we
        # actually have a purchase selected
        if not self.wizard.model:
            self.wizard.model = self.model = ReceivingOrder(
                responsible=api.get_current_user(self.store),
                supplier=purchase.supplier, invoice_number=None,
                branch=purchase.branch, purchase=purchase,
                store=self.store)

        # Remove all the items added previously, used if we hit back
        # at any point in the wizard.
        if self.model.purchase != purchase:
            self.model.remove_items()
            # This forces ReceivingOrderProductStep to create a new model
            self._next_step = None

        if selected:
            self.model.purchase = purchase
            self.model.branch = purchase.branch
            self.model.supplier = purchase.supplier
#.........这里部分代码省略.........
开发者ID:pkaislan,项目名称:stoq,代码行数:101,代码来源:receivingwizard.py


示例18: SearchDialog

class SearchDialog(BasicDialog):
    """  Base class for *all* the search dialogs, responsible for the list
    construction and "Filter" and "Clear" buttons management.

    This class must be subclassed and its subclass *must* implement the methods
    'get_columns' and 'get_query_and_args' (if desired, 'get_query_and_args'
    can be implemented in the user's slave class, so SearchDialog will get its
    slave instance and call the method directly). Its subclass also must
    implement a setup_slaves method and call its equivalent base class method
    as in:

    >>> def setup_slave(self):
    ...    SearchDialog.setup_slaves(self)

    or then, call it in its constructor, like:

    >>> def __init__(self, *args):
    ...     SearchDialog.__init__(self)
    """
    main_label_text = ''

    #: Title that will appear in the window, for instance 'Product Search'
    title = ''

    # The table type which we will query on to get the objects.
    search_spec = None

    #: The label that will be used for the main filter in this dialog
    search_label = None

    #: Selection mode to use (if its possible to select more than one row)
    selection_mode = gtk.SELECTION_BROWSE

    #: Default size for this dialog
    size = ()

    #: If the advanced search is enabled or disabled. When ``True`` we will
    #: instrospect the columns returned by :meth:`get_columns`,and use those
    #: that are subclasses of :class:`stoqlib.gui.columns.SearchColumn` to add
    #: as options for the user to filter the results.
    advanced_search = True

    tree = False

    def __init__(self, store, search_spec=None, hide_footer=True,
                 title='', selection_mode=None, double_click_confirm=False):
        """
        A base class for search dialog inheritance

        :param store: a store
        :param table:
        :param search_spec:
        :param hide_footer:
        :param title:
        :param selection_mode:
        :param double_click_confirm: If double click a item in the list should
          automatically confirm
        """

        self.store = store
        self.search_spec = search_spec or self.search_spec
        if not self.search_spec:
            raise ValueError("%r needs a search table" % self)
        self.selection_mode = self._setup_selection_mode(selection_mode)
        self.summary_label = None
        self.double_click_confirm = double_click_confirm

        BasicDialog.__init__(self, hide_footer=hide_footer,
                             main_label_text=self.main_label_text,
                             title=title or self.title,
                             size=self.size)

        self.enable_window_controls()
        self.disable_ok()
        self.set_ok_label(_('Se_lect Items'))
        self._setup_search()
        self._setup_details_slave()

        self.create_filters()
        self.setup_widgets()
        if self.search_label:
            self.set_searchbar_label(self.search_label)

    def _setup_selection_mode(self, selection_mode):
        # For consistency do not allow none or single, in other words,
        # only allowed values are browse and multiple so we always will
        # be able to use both the keyboard and the mouse to select items
        # in the search list.
        selection_mode = selection_mode or self.selection_mode
        if (selection_mode != gtk.SELECTION_BROWSE and
            selection_mode != gtk.SELECTION_MULTIPLE):
            raise ValueError('Invalid selection mode %r' % selection_mode)
        return selection_mode

    def _setup_search(self):
        self.search = SearchSlave(
            self.get_columns(),
            tree=self.tree,
            restore_name=self.__class__.__name__,
            store=self.store,
#.........这里部分代码省略.........
开发者ID:leandrorchaves,项目名称:stoq,代码行数:101,代码来源:searchdialog.py


示例19: ShellApp


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python paymentmethodslave.SelectPaymentMethodSlave类代码示例发布时间:2022-05-27
下一篇:
Python searchfilters.DateSearchFilter类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap