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 = StoqlibSearchSlaveDelegate(self._get_columns(), restore_name=self.__class__.__name__) self.attach_slave('search_group_holder', self.search) executer = StoqlibQueryExecuter(self.store) executer.set_table(QuotationView) self.search.set_query_executer(executer) self.search.set_text_field_columns(['supplier_name']) 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 [Column('identifier', title=_('Quote'), sorted=True, data_type=int, format="%04d"), Column('group_identifier', title=_('Group'), data_type=int, format="%04d"), 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: QuoteGroup.delete(group.id, store=store) 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 # def _on_searchlist__selection_changed(self, widget, item): self._update_view() def _on_searchlist__row_activated(self, widget, item): self._run_quote_editor() def on_edit_button__clicked(self, widget): self._run_quote_editor() def on_remove_button__clicked(self, widget): self._remove_quote()