def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("_Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False)
class ServiceSearch(SearchEditor): title = _('Service Search') search_spec = ServiceView size = (-1, 450) editor_class = ServiceEditor model_list_lookup_attr = 'service_id' footer_ok_label = _('Add services') def __init__(self, store, hide_footer=True, hide_toolbar=False, selection_mode=None, hide_cost_column=False, use_product_statuses=None, hide_price_column=False): if selection_mode is None: selection_mode = gtk.SELECTION_BROWSE self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column self.use_product_statuses = use_product_statuses SearchEditor.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, selection_mode=selection_mode) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) self.results.connect('has-rows', self._has_rows) def _has_rows(self, results, obj): SearchEditor._has_rows(self, results, obj) self._print_slave.print_price_button.set_sensitive(obj) # # SearchDialog Hooks # def create_filters(self): self.set_text_field_columns(['description', 'barcode']) executer = self.search.get_query_executer() executer.add_query_callback(self._get_query) service_filter = self.create_sellable_filter() self.add_filter(service_filter, SearchFilterPosition.TOP, ['status']) # # SearchEditor Hooks # def get_editor_model(self, model): return self.store.get(Service, model.service_id) def get_columns(self): columns = [ SearchColumn('code', title=_('Code'), data_type=str, sorted=True, sort_func=sort_sellable_code, width=130), SearchColumn('barcode', title=_('Barcode'), data_type=str, visible=True, width=130), SearchColumn('description', title=_('Description'), data_type=str, expand=True) ] if not self.hide_cost_column: columns.append( SearchColumn('cost', _('Cost'), data_type=currency, width=80)) if not self.hide_price_column: columns.append( SearchColumn('price', title=_('Price'), data_type=currency, width=80)) return columns def _get_query(self, states): return Ne(ServiceView.service_id, None) def on_print_button_clicked(self, button): print_report(ServiceReport, self.results, list(self.results), filters=self.search.get_search_filters()) def on_print_price_button_clicked(self, button): print_report(ServicePriceReport, list(self.results), filters=self.search.get_search_filters())
class ProductSearch(SellableSearch): title = _('Product Search') search_spec = ProductFullWithClosedStockView editor_class = ProductEditor report_class = ProductReport has_branch_filter = True has_status_filter = True has_print_price_button = True csv_data = (_("Product"), _("product")) footer_ok_label = _('Add products') def __init__(self, store, hide_footer=True, hide_toolbar=False, hide_cost_column=False, hide_price_column=False, double_click_confirm=False): """ :param store: a store :param hide_footer: do I have to hide the dialog footer? :param hide_toolbar: do I have to hide the dialog toolbar? :param hide_cost_column: if it's True, no need to show the column 'cost' :param hide_price_column: if it's True no need to show the column 'price' """ self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SellableSearch.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, double_click_confirm=double_click_confirm) if self.has_print_price_button: self._setup_print_slave() else: self._print_slave = None def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("_Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) def on_print_price_button_clicked(self, button): print_report(ProductPriceReport, list(self.results), filters=self.search.get_search_filters(), branch_name=self.branch_filter.combo.get_active_text()) # # ProductSearch # def setup_widgets(self): super(ProductSearch, self).setup_widgets() if self.csv_data is not None: self.add_csv_button(*self.csv_data) def create_filters(self): super(ProductSearch, self).create_filters() if self.has_branch_filter: branch_filter = self.create_branch_filter(_('In branch:')) self.add_filter(branch_filter, columns=[]) self.branch_filter = branch_filter else: self.branch_filter = None if self.has_status_filter: status_filter = self.create_sellable_filter() self.add_filter(status_filter, columns=['status'], position=SearchFilterPosition.TOP) self.status_filter = status_filter else: self.status_filter = None def get_editor_class_for_object(self, obj): if obj is None: return ProductCreateWizard return self.editor_class def get_editor_model(self, product_full_stock_view): return product_full_stock_view.product def get_columns(self): cols = [SearchColumn('code', title=_('Code'), data_type=str, sort_func=sort_sellable_code, sorted=True), SearchColumn('barcode', title=_('Barcode'), data_type=str), SearchColumn('category_description', title=_(u'Category'), data_type=str, width=120), SearchColumn('description', title=_(u'Description'), expand=True, data_type=str), SearchColumn('manufacturer', title=_('Manufacturer'), data_type=str, visible=False), SearchColumn('model', title=_('Model'), data_type=str, visible=False), SearchColumn('location', title=_('Location'), data_type=str, visible=False)] # The price/cost columns must be controlled by hide_cost_column and # hide_price_column. Since the product search will be available across # the applications, it's important to restrict such columns depending # of the context. if not self.hide_cost_column: cols.append(SearchColumn('cost', _('Cost'), data_type=currency, format_func=get_formatted_cost, width=90)) if not self.hide_price_column: cols.append(SearchColumn('price', title=_('Price'), data_type=currency, width=90)) cols.append(QuantityColumn('stock', title=_('Stock'))) return cols def executer_query(self, store): branch_id = self.branch_filter.get_state().value if branch_id is None: branch = None else: branch = store.get(Branch, branch_id) results = self.search_spec.find_by_branch(store, branch) return results.find(Eq(Product.is_composed, False)) # # Callbacks # def on_results__has_rows(self, results, obj): if self._print_slave is not None: self._print_slave.print_price_button.set_sensitive(obj)
class ProductSearch(SearchEditor): title = _('Product Search') table = Product size = (775, 450) search_spec = ProductFullWithClosedStockView editor_class = ProductEditor footer_ok_label = _('Add products') def __init__(self, store, hide_footer=True, hide_toolbar=False, selection_mode=gtk.SELECTION_BROWSE, hide_cost_column=False, use_product_statuses=None, hide_price_column=False): """ Create a new ProductSearch object. :param store: a store :param hide_footer: do I have to hide the dialog footer? :param hide_toolbar: do I have to hide the dialog toolbar? :param selection_mode: the kiwi list selection mode :param hide_cost_column: if it's True, no need to show the column 'cost' :param use_product_statuses: a list instance that, if provided, will overwrite the statuses list defined in get_filter_slave method :param hide_price_column: if it's True no need to show the column 'price' """ self.use_product_statuses = use_product_statuses self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SearchEditor.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, selection_mode=selection_mode) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("_Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) self.results.connect('has-rows', self._has_rows) def on_print_button_clicked(self, button): print_report(ProductReport, self.results, list(self.results), filters=self.search.get_search_filters()) def on_print_price_button_clicked(self, button): print_report(ProductPriceReport, list(self.results), filters=self.search.get_search_filters(), branch_name=self.branch_filter.combo.get_active_text()) def _has_rows(self, results, obj): SearchEditor._has_rows(self, results, obj) self._print_slave.print_price_button.set_sensitive(obj) # # SearchDialog Hooks # def setup_widgets(self): self.csv_button = self.add_button(label=_('Export to spreadsheet...')) self.csv_button.connect('clicked', self._on_export_csv_button__clicked) self.csv_button.show() self.csv_button.set_sensitive(False) self.results.connect('has_rows', self._on_results__has_rows) def create_filters(self): self.set_text_field_columns( ['description', 'barcode', 'category_description']) self.search.set_query(self.executer_query) # Branch branch_filter = self.create_branch_filter(_('In branch:')) branch_filter.select(None) self.add_filter(branch_filter, columns=[]) self.branch_filter = branch_filter # Status statuses = [(desc, id) for id, desc in Sellable.statuses.items()] statuses.insert(0, (_('Any'), None)) status_filter = ComboSearchFilter(_('with status:'), statuses) status_filter.select(None) self.add_filter(status_filter, columns=['status'], position=SearchFilterPosition.TOP) self.status_filter = status_filter # # SearchEditor Hooks # def get_editor_model(self, product_full_stock_view): return product_full_stock_view.product def get_columns(self): cols = [ SearchColumn('code', title=_('Code'), data_type=str, sort_func=sort_sellable_code, sorted=True), SearchColumn('barcode', title=_('Barcode'), data_type=str), SearchColumn('category_description', title=_(u'Category'), data_type=str, width=120), SearchColumn('description', title=_(u'Description'), expand=True, data_type=str), SearchColumn('manufacturer', title=_('Manufacturer'), data_type=str, visible=False), SearchColumn('model', title=_('Model'), data_type=str, visible=False), SearchColumn('location', title=_('Location'), data_type=str, visible=False) ] # The price/cost columns must be controlled by hide_cost_column and # hide_price_column. Since the product search will be available across # the applications, it's important to restrict such columns depending # of the context. if not self.hide_cost_column: cols.append( SearchColumn('cost', _('Cost'), data_type=currency, format_func=get_formatted_cost, width=90)) if not self.hide_price_column: cols.append( Column('price', title=_('Price'), data_type=currency, width=90)) cols.append( SearchColumn('stock', title=_('Stock'), format_func=format_quantity, data_type=Decimal, width=80)) return cols def executer_query(self, store): branch_id = self.branch_filter.get_state().value if branch_id is None: branch = None else: branch = store.get(Branch, branch_id) results = self.search_spec.find_by_branch(store, branch) return results.find(Eq(Product.is_composed, False)) # # Callbacks # def _on_export_csv_button__clicked(self, widget): sse = SpreadSheetExporter() sse.export(object_list=self.results, name=_('Product'), filename_prefix=_('product')) def _on_results__has_rows(self, widget, has_rows): self.csv_button.set_sensitive(has_rows)
class ProductSearch(SearchEditor): title = _('Product Search') table = Product size = (775, 450) search_spec = ProductFullWithClosedStockView editor_class = ProductEditor footer_ok_label = _('Add products') def __init__(self, store, hide_footer=True, hide_toolbar=False, selection_mode=None, hide_cost_column=False, use_product_statuses=None, hide_price_column=False): """ Create a new ProductSearch object. :param store: a store :param hide_footer: do I have to hide the dialog footer? :param hide_toolbar: do I have to hide the dialog toolbar? :param selection_mode: the kiwi list selection mode :param hide_cost_column: if it's True, no need to show the column 'cost' :param use_product_statuses: a list instance that, if provided, will overwrite the statuses list defined in get_filter_slave method :param hide_price_column: if it's True no need to show the column 'price' """ if selection_mode is None: selection_mode = gtk.SELECTION_BROWSE self.use_product_statuses = use_product_statuses self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SearchEditor.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, selection_mode=selection_mode) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("_Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) self.results.connect('has-rows', self._has_rows) def on_print_button_clicked(self, button): print_report(ProductReport, self.results, list(self.results), filters=self.search.get_search_filters()) def on_print_price_button_clicked(self, button): print_report(ProductPriceReport, list(self.results), filters=self.search.get_search_filters(), branch_name=self.branch_filter.combo.get_active_text()) def _has_rows(self, results, obj): SearchEditor._has_rows(self, results, obj) self._print_slave.print_price_button.set_sensitive(obj) # # SearchDialog Hooks # def setup_widgets(self): self.csv_button = self.add_button(label=_('Export to spreadsheet...')) self.csv_button.show() self.csv_button.set_sensitive(False) self.branch_stock_button = self.add_button(label=_('Stocks details')) self.branch_stock_button.show() self.branch_stock_button.set_sensitive(False) def create_filters(self): self.set_text_field_columns(['description', 'barcode', 'category_description']) self.search.set_query(self.executer_query) # Branch branch_filter = self.create_branch_filter(_('In branch:')) self.add_filter(branch_filter, columns=[]) self.branch_filter = branch_filter # Status status_filter = self.create_sellable_filter() self.add_filter(status_filter, columns=['status'], position=SearchFilterPosition.TOP) self.status_filter = status_filter # # SearchEditor Hooks # def get_editor_model(self, product_full_stock_view): return product_full_stock_view.product def get_columns(self): cols = [SearchColumn('code', title=_('Code'), data_type=str, sort_func=sort_sellable_code, sorted=True), SearchColumn('barcode', title=_('Barcode'), data_type=str), SearchColumn('category_description', title=_(u'Category'), data_type=str, width=120), SearchColumn('description', title=_(u'Description'), expand=True, data_type=str), SearchColumn('manufacturer', title=_('Manufacturer'), data_type=str, visible=False), SearchColumn('model', title=_('Model'), data_type=str, visible=False), SearchColumn('location', title=_('Location'), data_type=str, visible=False)] # The price/cost columns must be controlled by hide_cost_column and # hide_price_column. Since the product search will be available across # the applications, it's important to restrict such columns depending # of the context. if not self.hide_cost_column: cols.append(SearchColumn('cost', _('Cost'), data_type=currency, format_func=get_formatted_cost, width=90)) if not self.hide_price_column: cols.append(Column('price', title=_('Price'), data_type=currency, width=90)) cols.append(SearchColumn('stock', title=_('Stock'), format_func=format_quantity, data_type=Decimal, width=80)) return cols def executer_query(self, store): branch_id = self.branch_filter.get_state().value if branch_id is None: branch = None else: branch = store.get(Branch, branch_id) results = self.search_spec.find_by_branch(store, branch) return results.find(Eq(Product.is_composed, False)) # # Callbacks # def on_results__has_rows(self, widget, has_rows): self.csv_button.set_sensitive(has_rows) def on_results__selection_changed(self, widget, selection): enable_details = selection and selection.product.storable self.branch_stock_button.set_sensitive(bool(enable_details)) def on_csv_button__clicked(self, widget): sse = SpreadSheetExporter() sse.export(object_list=self.results, name=_('Product'), filename_prefix=_('product')) def on_branch_stock_button__clicked(self, widget): product_viewable = self.get_selection() if product_viewable: self.run_dialog(ProductBranchSearch, self, self.store, product_viewable.product.storable)
class ProductSearch(SellableSearch): title = _('Product Search') search_spec = ProductFullWithClosedStockView editor_class = ProductEditor report_class = ProductReport has_branch_filter = True has_status_filter = True has_print_price_button = True csv_data = (_("Product"), _("product")) footer_ok_label = _('Add products') def __init__(self, store, hide_footer=True, hide_toolbar=False, hide_cost_column=False, hide_price_column=False, double_click_confirm=False): """ :param store: a store :param hide_footer: do I have to hide the dialog footer? :param hide_toolbar: do I have to hide the dialog toolbar? :param hide_cost_column: if it's True, no need to show the column 'cost' :param hide_price_column: if it's True no need to show the column 'price' """ # We only want to display data as a tree for ProductSearch, but # not setting 'tree = True' on the class definition as it has too many # subclasses for us to manually set to False on each one if self.__class__ is ProductSearch: self.result_view_class = _ProductSearchResultTreeView self.tree = True self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SellableSearch.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, double_click_confirm=double_click_confirm) if self.has_print_price_button: self._setup_print_slave() else: self._print_slave = None def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("_Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) def on_print_price_button_clicked(self, button): print_report(ProductPriceReport, list(self.results), filters=self.search.get_search_filters(), branch_name=self.branch_filter.combo.get_active_text()) # # Private # def _get_status_values(self): return ([(_('Any'), None)] + [(v, k) for k, v in Sellable.statuses.items()]) # # ProductSearch # def setup_widgets(self): super(ProductSearch, self).setup_widgets() if self.csv_data is not None: self.add_csv_button(*self.csv_data) def create_filters(self): super(ProductSearch, self).create_filters() if self.has_branch_filter: branch_filter = self.create_branch_filter(_('In branch:')) self.add_filter(branch_filter, columns=[]) self.branch_filter = branch_filter else: self.branch_filter = None if self.has_status_filter: status_filter = self.create_sellable_filter() self.add_filter(status_filter, columns=['status'], position=SearchFilterPosition.TOP) self.status_filter = status_filter else: self.status_filter = None def get_editor_class_for_object(self, obj): if obj is None: return ProductCreateWizard return self.editor_class def get_editor_model(self, product_full_stock_view): return product_full_stock_view.product def run_editor(self, obj): editor_class = self.get_editor_class_for_object(obj) if obj is None and issubclass(editor_class, ProductCreateWizard): return editor_class.run_wizard(self) return super(ProductSearch, self).run_editor(obj) def get_columns(self): cols = [ SearchColumn('code', title=_('Code'), data_type=str, sort_func=sort_sellable_code, sorted=True), SearchColumn('barcode', title=_('Barcode'), data_type=str), SearchColumn('category_description', title=_(u'Category'), data_type=str, width=120), SearchColumn('description', title=_(u'Description'), expand=True, data_type=str), SearchColumn('manufacturer', title=_('Manufacturer'), data_type=str, visible=False), SearchColumn('model', title=_('Model'), data_type=str, visible=False), SearchColumn('ncm', title=_('NCM'), data_type=str, visible=False), Column('unit', title=_('Unit'), data_type=str, visible=False), SearchColumn('location', title=_('Location'), data_type=str, visible=False), SearchColumn('status', title=_('Status'), data_type=str, valid_values=self._get_status_values(), visible=False), SearchColumn('brand', title=_('Brand'), data_type=str, visible=False), SearchColumn('family', title=_('Family'), data_type=str, visible=False), SearchColumn('internal_use', title=_('Is internal'), data_type=bool, visible=False) ] # The price/cost columns must be controlled by hide_cost_column and # hide_price_column. Since the product search will be available across # the applications, it's important to restrict such columns depending # of the context. if not self.hide_cost_column: cols.append( SearchColumn('cost', _('Cost'), data_type=currency, format_func=get_formatted_cost, width=90)) if not self.hide_price_column: cols.append( SearchColumn('price', title=_('Price'), data_type=currency, width=90)) cols.append(QuantityColumn('stock', title=_('Stock'), use_having=True)) return cols def executer_query(self, store): branch_id = self.branch_filter.get_state().value if branch_id is None: branch = None else: branch = store.get(Branch, branch_id) results = self.search_spec.find_by_branch(store, branch) return results.find(Eq(Product.is_composed, False)) # # Callbacks # def on_results__has_rows(self, results, obj): if self._print_slave is not None: self._print_slave.print_price_button.set_sensitive(obj)
class ServiceSearch(SellableSearch): title = _('Service Search') search_spec = ServiceView editor_class = ServiceEditor report_class = ServiceReport model_list_lookup_attr = 'service_id' footer_ok_label = _('Add services') exclude_delivery_service = False def __init__(self, store, hide_footer=True, hide_toolbar=False, double_click_confirm=False, hide_cost_column=False, hide_price_column=False): self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SellableSearch.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, double_click_confirm=double_click_confirm) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, Gtk.STOCK_PRINT, _("Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) # # SellableSearch # def create_filters(self): super(ServiceSearch, self).create_filters() executer = self.search.get_query_executer() executer.add_query_callback(self._get_query) service_filter = self.create_sellable_filter() self.add_filter(service_filter, SearchFilterPosition.TOP, ['status']) def get_editor_model(self, model): return self.store.get(Service, model.service_id) def get_columns(self): columns = [ SearchColumn('code', title=_('Code'), data_type=str, sorted=True, sort_func=sort_sellable_code, width=130), SearchColumn('barcode', title=_('Barcode'), data_type=str, visible=True, width=130), SearchColumn('description', title=_('Description'), data_type=str, expand=True) ] if not self.hide_cost_column: columns.append( SearchColumn('cost', _('Cost'), data_type=currency, width=80)) if not self.hide_price_column: columns.append( SearchColumn('price', title=_('Price'), data_type=currency, width=80)) return columns def _get_query(self, states): return Ne(ServiceView.service_id, None) # # Callbacks # def on_print_price_button_clicked(self, button): print_report(ServicePriceReport, list(self.results), filters=self.search.get_search_filters()) def on_results__has_rows(self, results, obj): self._print_slave.print_price_button.set_sensitive(obj)
class ServiceSearch(SearchEditor): title = _('Service Search') search_spec = ServiceView size = (-1, 450) editor_class = ServiceEditor model_list_lookup_attr = 'service_id' footer_ok_label = _('Add services') def __init__(self, store, hide_footer=True, hide_toolbar=False, selection_mode=None, hide_cost_column=False, use_product_statuses=None, hide_price_column=False): if selection_mode is None: selection_mode = gtk.SELECTION_BROWSE self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column self.use_product_statuses = use_product_statuses SearchEditor.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, selection_mode=selection_mode) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) self.results.connect('has-rows', self._has_rows) def _has_rows(self, results, obj): SearchEditor._has_rows(self, results, obj) self._print_slave.print_price_button.set_sensitive(obj) # # SearchDialog Hooks # def create_filters(self): self.set_text_field_columns(['description', 'barcode']) executer = self.search.get_query_executer() executer.add_query_callback(self._get_query) service_filter = self.create_sellable_filter() self.add_filter(service_filter, SearchFilterPosition.TOP, ['status']) # # SearchEditor Hooks # def get_editor_model(self, model): return self.store.get(Service, model.service_id) def get_columns(self): columns = [SearchColumn('code', title=_('Code'), data_type=str, sorted=True, sort_func=sort_sellable_code, width=130), SearchColumn('barcode', title=_('Barcode'), data_type=str, visible=True, width=130), SearchColumn('description', title=_('Description'), data_type=str, expand=True)] if not self.hide_cost_column: columns.append(SearchColumn('cost', _('Cost'), data_type=currency, width=80)) if not self.hide_price_column: columns.append(SearchColumn('price', title=_('Price'), data_type=currency, width=80)) return columns def _get_query(self, states): return Ne(ServiceView.service_id, None) def on_print_button_clicked(self, button): print_report(ServiceReport, self.results, list(self.results), filters=self.search.get_search_filters()) def on_print_price_button_clicked(self, button): print_report(ServicePriceReport, list(self.results), filters=self.search.get_search_filters())
class ServiceSearch(SellableSearch): title = _('Service Search') search_spec = ServiceView editor_class = ServiceEditor report_class = ServiceReport model_list_lookup_attr = 'service_id' footer_ok_label = _('Add services') exclude_delivery_service = False def __init__(self, store, hide_footer=True, hide_toolbar=False, double_click_confirm=False, hide_cost_column=False, hide_price_column=False): self.hide_cost_column = hide_cost_column self.hide_price_column = hide_price_column SellableSearch.__init__(self, store, hide_footer=hide_footer, hide_toolbar=hide_toolbar, double_click_confirm=double_click_confirm) self._setup_print_slave() def _setup_print_slave(self): self._print_slave = SearchDialogPrintSlave() change_button_appearance(self._print_slave.print_price_button, gtk.STOCK_PRINT, _("Price table")) self.attach_slave('print_holder', self._print_slave) self._print_slave.connect('print', self.on_print_price_button_clicked) self._print_slave.print_price_button.set_sensitive(False) # # SellableSearch # def create_filters(self): super(ServiceSearch, self).create_filters() executer = self.search.get_query_executer() executer.add_query_callback(self._get_query) service_filter = self.create_sellable_filter() self.add_filter(service_filter, SearchFilterPosition.TOP, ['status']) def get_editor_model(self, model): return self.store.get(Service, model.service_id) def get_columns(self): columns = [SearchColumn('code', title=_('Code'), data_type=str, sorted=True, sort_func=sort_sellable_code, width=130), SearchColumn('barcode', title=_('Barcode'), data_type=str, visible=True, width=130), SearchColumn('description', title=_('Description'), data_type=str, expand=True)] if not self.hide_cost_column: columns.append(SearchColumn('cost', _('Cost'), data_type=currency, width=80)) if not self.hide_price_column: columns.append(SearchColumn('price', title=_('Price'), data_type=currency, width=80)) return columns def _get_query(self, states): return Ne(ServiceView.service_id, None) # # Callbacks # def on_print_price_button_clicked(self, button): print_report(ServicePriceReport, list(self.results), filters=self.search.get_search_filters()) def on_results__has_rows(self, results, obj): self._print_slave.print_price_button.set_sensitive(obj)