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__) self.search.enable_advanced_search() self.attach_slave('searchbar_holder', self.search) self.executer = QueryExecuter(self.store) self.search.set_query_executer(self.executer) self.executer.set_table(PurchaseOrderView) self.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']) def get_extra_query(self, states): return PurchaseOrderView.status == PurchaseOrder.ORDER_CONFIRMED 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 self.model.transporter = purchase.transporter else: self.model.purchase = None # FIXME: Improve the infrastructure to avoid this local caching of # Wizard steps. if not self._next_step: # Remove all the items added previously, used if we hit back # at any point in the wizard. self._next_step = ReceivingOrderItemStep(self.store, self.wizard, self.model, self) return self._next_step def has_previous_step(self): return False def setup_slaves(self): self._create_search() # # Kiwi callbacks # # def on_searchbar_activate(self, slave, objs): # """Use this callback with SearchBar search-activate signal""" # self.results.add_list(objs, clear=True) # has_selection = self.results.get_selected() is not None # self.wizard.refresh_next(has_selection) 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() if not selected: raise ValueError('You should have one order selected ' 'at this point, got nothing') run_dialog(PurchaseDetailsDialog, self.wizard, self.store, model=selected.purchase)
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']) 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__) self.search.enable_advanced_search() self.attach_slave('place_holder', self.search) self.executer = QueryExecuter(self.store) self.search.set_query_executer(self.executer) self.executer.set_table(LoanView) self.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()