def _delete_account(self, account_view): store = api.new_store() account = store.fetch(account_view.account) methods = PaymentMethod.get_by_account(store, account) if methods.count() > 0: if not yesno( _('This account is used in at least one payment method.\n' 'To be able to delete it the payment methods needs to be' 're-configured first'), gtk.RESPONSE_NO, _("Configure payment methods"), _("Keep account")): store.close() return elif not yesno( _('Are you sure you want to remove account "%s" ?') % ( (account_view.description, )), gtk.RESPONSE_NO, _("Remove account"), _("Keep account")): store.close() return if account_view.id in self._pages: account_page = self._pages[account_view.id] self._close_page(account_page) self.accounts.remove(account_view) self.accounts.flush() imbalance = api.sysparam(store).IMBALANCE_ACCOUNT for method in methods: method.destination_account = imbalance account.remove(store) store.commit(close=True)
def open(self): while True: log.info("opening coupon") try: self.emit('open') break except CouponOpenError: if not self.cancel(): return False except OutofPaperError: if not yesno( _("The fiscal printer has run out of paper.\nAdd more paper " "before continuing."), gtk.RESPONSE_YES, _("Resume"), _("Confirm later")): return False return self.open() except PrinterOfflineError: if not yesno( (_(u"The fiscal printer is offline, turn it on and try " "again")), gtk.RESPONSE_YES, _(u"Resume"), _(u"Confirm later")): return False return self.open() except (DriverError, DeviceError) as e: warning(_(u"It is not possible to emit the coupon"), str(e)) return False self._coo = self.emit('get-coo') self.totalized = False self.coupon_closed = False self.payments_setup = False return True
def finish(self): missing = get_missing_items(self.model, self.store) if missing: # We want to close the checkout, so the user will be back to the # list of items in the sale. self.close() run_dialog(MissingItemsDialog, self, self.model, missing) return False self.retval = True invoice_number = self.invoice_model.invoice_number # Workaround for bug 4218: If the invoice is was already used by # another store (another cashier), try using the next one # available, or show a warning if the number was manually set. while True: try: self.store.savepoint('before_set_invoice_number') self.model.invoice_number = invoice_number # We need to flush the database here, or a possible collision # of invoice_number will only be detected later on, when the # execution flow is not in the try-except anymore. self.store.flush() except IntegrityError: self.store.rollback_to_savepoint('before_set_invoice_number') if self._invoice_changed(): warning(_(u"The invoice number %s is already used. " "Confirm the sale again to chose another one.") % invoice_number) self.retval = False break else: invoice_number += 1 else: break self.close() group = self.model.group # FIXME: This is set too late on Sale.confirm(). If PaymentGroup don't # have a payer, we won't be able to print bills/booklets. group.payer = self.model.client and self.model.client.person # Commit before printing to avoid losing data if something breaks self.store.confirm(self.retval) ConfirmSaleWizardFinishEvent.emit(self.model) booklets = list(group.get_payments_by_method_name(u'store_credit')) bills = list(group.get_payments_by_method_name(u'bill')) if (booklets and yesno(_("Do you want to print the booklets for this sale?"), gtk.RESPONSE_YES, _("Print booklets"), _("Don't print"))): print_report(BookletReport, booklets) if (bills and BillReport.check_printable(bills) and yesno(_("Do you want to print the bills for this sale?"), gtk.RESPONSE_YES, _("Print bills"), _("Don't print"))): print_report(BillReport, bills)
def setup_payments(self, sale): """ Add the payments defined in the sale to the coupon. Note that this function must be called after all the payments has been created. """ # XXX: Remove this when bug #2827 is fixed. if not self._item_ids: return True if self.payments_setup: return True log.info('Adding payments to the coupon') while True: try: self.emit('add-payments', sale) self.payments_setup = True return True except (DriverError, DeviceError) as details: log.info("It is not possible to add payments to the coupon: %s" % str(details)) if not yesno(_(u"An error occurred while trying to print. " u"Would you like to try again?"), gtk.RESPONSE_YES, _("Try again"), _(u"Don't try again")): CancelPendingPaymentsEvent.emit() return False _flush_interface()
def on_cancel(self): if self._storables: msg = _('Save data before close the dialog ?') if yesno(msg, gtk.RESPONSE_NO, _("Save data"), _("Don't save")): self._add_initial_stock() # change retval to True so the store gets commited self.retval = True
def run_wizard(cls, parent): """Run the wizard to create a product This will run the wizard and after finishing, ask if the user wants to create another product alike. The product will be cloned and `stoqlib.gui.editors.producteditor.ProductEditor` will run as long as the user chooses to create one alike """ with api.new_store() as store: rv = run_dialog(cls, parent, store) if rv: inner_rv = rv while yesno(_("Would you like to register another product alike?"), gtk.RESPONSE_NO, _("Yes"), _("No")): with api.new_store() as store: template = store.fetch(rv) inner_rv = run_dialog(ProductEditor, parent, store, product_type=template.product_type, template=template) if not inner_rv: break # We are insterested in the first rv that means that at least one # obj was created. return rv
def _register_branch_station(caller_store, station_name): import gtk from stoqlib.lib.parameters import sysparam if not sysparam.get_bool('DEMO_MODE'): fmt = _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") if not yesno(fmt % (station_name, db_settings.address), gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.utils.login import LoginHelper h = LoginHelper(username="******") try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.station import BranchStation with new_store() as store: branch = sysparam.get_object(store, 'MAIN_COMPANY') station = BranchStation.create(store, branch=branch, name=station_name) return caller_store.fetch(station)
def _clear(self): objs = self.get_selection() qty = len(objs) if qty < 1: raise SelectionError('There are no objects selected') msg = stoqlib_ngettext( _('Delete this item?'), _('Delete these %d items?') % qty, qty) delete_label = stoqlib_ngettext( _("Delete item"), _("Delete items"), qty) keep_label = stoqlib_ngettext( _("Keep it"), _("Keep them"), qty) if not yesno(msg, gtk.RESPONSE_NO, delete_label, keep_label): return self.emit('before-delete-items', objs) if qty == len(self.klist): self.klist.clear() else: for obj in objs: self.klist.remove(obj) self.klist.unselect_all() self._update_sensitivity() self.emit('after-delete-items')
def finish(self): for payment in self.model.group.payments: if payment.is_preview(): # Set payments created on SaleReturnPaymentStep as pending payment.set_pending() SaleReturnWizardFinishEvent.emit(self.model) total_amount = self.model.total_amount # If the user chose to create credit for the client instead of returning # money, there is no need to display this messages. if not self.credit: if total_amount == 0: info(_("The client does not have a debt to this sale anymore. " "Any existing unpaid installment will be cancelled.")) elif total_amount < 0: info(_("A reversal payment to the client will be created. " "You can see it on the Payable Application.")) self.model.return_(method_name=u'credit' if self.credit else u'money') self.retval = self.model self.close() if self.credit: if yesno(_(u'Would you like to print the credit letter?'), gtk.RESPONSE_YES, _(u"Print Letter"), _(u"Don't print")): print_report(ClientCreditReport, self.model.client)
def print_quote_details(self, model, payments_created=False): msg = _('Would you like to print the quote details now?') # We can only print the details if the quote was confirmed. if yesno(msg, gtk.RESPONSE_YES, _("Print quote details"), _("Don't print")): orders = WorkOrder.find_by_sale(self.model.store, self.model) print_report(OpticalWorkOrderReceiptReport, list(orders))
def delete_button_clicked(self, button): if not yesno(_("Are you sure you want to remove the attachment?"), gtk.RESPONSE_NO, _("Remove"), _("Don't remove")): return self.attachment.blob = None self._update_widget()
def _finish(self, returncode): logger.info('CreateDatabaseStep._finish (returncode=%s)' % returncode) if returncode: self.wizard.enable_back() # Failed to execute/create database if returncode == 30: # This probably happened because the user either; # - pressed cancel in the authentication popup # - user erred the password 3 times # Allow him to try again if yesno(_("Something went wrong while trying to create " "the database. Try again?"), gtk.RESPONSE_NO, _("Change settings"), _("Try again")): return self._launch_stoqdbadmin() return elif returncode == 31: # Missing postgresql-contrib package self.expander.set_expanded(True) warning(_("Your database is missing the postgresql-contrib " "package. Install it and try again")) else: # Unknown error, just inform user that something went wrong. self.expander.set_expanded(True) warning(_("Something went wrong while trying to create " "the Stoq database")) return self.label.set_text("") self.wizard.load_config_and_call_setup() create_default_profile_settings() self.progressbar.set_text(_("Done.")) self.progressbar.set_fraction(1.0) self.wizard.enable_next() self.done_label.set_markup( _("Installation successful, click <b>Forward</b> to continue."))
def setup_payments(self, sale): """ Add the payments defined in the sale to the coupon. Note that this function must be called after all the payments has been created. """ # XXX: Remove this when bug #2827 is fixed. if not self._item_ids: return True if self.payments_setup: return True log.info('Adding payments to the coupon') while True: try: self.emit('add-payments', sale) self.payments_setup = True return True except (DriverError, DeviceError), details: log.info("It is not possible to add payments to the coupon: %s" % str(details)) if not yesno(_(u"Erro na impressão. Deseja tentar novamente?"), gtk.RESPONSE_YES, _("Sim"), _(u"Não")): CancelPendingPaymentsEvent.emit() return False _flush_interface()
def _send_selected_items_to_supplier(self): orders = self.results.get_selected_rows() valid_order_views = [ order for order in orders if order.status == PurchaseOrder.ORDER_PENDING] if not valid_order_views: warning(_("There are no pending orders selected.")) return msg = stoqlib_ngettext( _("The selected order will be marked as sent."), _("The %d selected orders will be marked as sent.") % len(valid_order_views), len(valid_order_views)) confirm_label = stoqlib_ngettext(_("Confirm order"), _("Confirm orders"), len(valid_order_views)) if not yesno(msg, gtk.RESPONSE_YES, confirm_label, _("Don't confirm")): return with api.new_store() as store: for order_view in valid_order_views: order = store.fetch(order_view.purchase) order.confirm() self.refresh() self.select_result(orders)
def remove_item(self, item): msg = _('Removing this device will also remove all related costs.') remove = yesno(msg, gtk.RESPONSE_NO, _('Remove'), _("Keep device")) if remove: self.remove_list_item(item) self._delete_model(item) return False
def on_NewTrade__activate(self, action): if self._trade: if yesno( _("There is already a trade in progress... Do you " "want to cancel it and start a new one?"), gtk.RESPONSE_NO, _("Cancel trade"), _("Finish trade")): self._clear_trade(remove=True) else: return if self._current_store: store = self._current_store store.savepoint('before_run_wizard_saletrade') else: store = api.new_store() trade = self.run_dialog(SaleTradeWizard, store) if trade: self._trade = trade self._current_store = store elif self._current_store: store.rollback_to_savepoint('before_run_wizard_saletrade') else: store.rollback(close=True) self._show_trade_infobar(trade)
def _maybe_create_database(self): logger.info('_maybe_create_database (db_is_local=%s, remove_demo=%s)' % (self.wizard.db_is_local, self.wizard.remove_demo)) if self.wizard.db_is_local: self._launch_stoqdbadmin() return elif self.wizard.remove_demo: self._launch_stoqdbadmin() return self.wizard.write_pgpass() settings = self.wizard.settings self.wizard.config.load_settings(settings) # store = settings.get_super_store() # version = store.dbVersion() # if version < (8, 1): # info(_("Stoq requires PostgresSQL 8.1 or later, but %s found") % # ".".join(map(str, version))) # store.close() # return False # Secondly, ask the user if he really wants to create the database, dbname = settings.dbname if yesno(_(u"The specified database '%s' does not exist.\n" u"Do you want to create it?") % dbname, gtk.RESPONSE_YES, _(u"Create database"), _(u"Don't create")): self.process_view.feed("** Creating database\r\n") self._launch_stoqdbadmin() else: self.process_view.feed("** Not creating database\r\n") self.wizard.disable_next()
def close(self, sale, store): # XXX: Remove this when bug #2827 is fixed. if not self._item_ids: return True if self.coupon_closed: return True log.info('Closing coupon') while True: try: coupon_id = self.emit('close', sale) sale.coupon_id = coupon_id self.coupon_closed = True return True except (DeviceError, DriverError) as details: log.info("It is not possible to close the coupon: %s" % str(details)) if not yesno(_(u"An error occurred while trying to print. " u"Would you like to try again?"), gtk.RESPONSE_YES, _("Try again"), _(u"Don't try again")): CancelPendingPaymentsEvent.emit() return False _flush_interface()
def print_receipts(self, sale): # supports_duplicate = self.emit('get-supports-duplicate-receipt') # Vamos sempre imprimir sempre de uma vez, para simplificar supports_duplicate = False log.info('Printing payment receipts') # Merge card payments by nsu card_payments = {} for payment in sale.payments: if payment.method.method_name != 'card': continue operation = payment.method.operation card_data = operation.get_card_data_by_payment(payment) card_payments.setdefault(card_data.nsu, []) card_payments[card_data.nsu].append(payment) any_failed = False for nsu, payment_list in card_payments.items(): receipt = CardPaymentReceiptPrepareEvent.emit( nsu, supports_duplicate) if receipt is None: continue value = sum([p.value for p in payment_list]) # This is BS, but if any receipt failed to print, we must print # the remaining ones in Gerencial Rports if any_failed: retval = self.reprint_payment_receipt(receipt) else: retval = self.print_payment_receipt(payment_list[0], value, receipt) while not retval: if not yesno( _(u"An error occurred while trying to print. " u"Would you like to try again?"), gtk.RESPONSE_YES, _("Try again"), _(u"Don't try again")): CancelPendingPaymentsEvent.emit() try: GerencialReportCancelEvent.emit() except (DriverError, DeviceError) as details: log.info('Error canceling last receipt: %s' % details) warning( _(u"It wasn't possible to cancel " u"the last receipt")) return False any_failed = True _flush_interface() retval = self.reprint_payment_receipt( receipt, close_previous=True) # Only confirm payments receipt printed if *all* receipts wore # printed. for nsu in card_payments.keys(): CardPaymentReceiptPrintedEvent.emit(nsu) return True
def close_till(self, close_db=True, close_ecf=True): """Closes the till There are 3 possibilities for parameters combination: * *total close*: Both *close_db* and *close_ecf* are ``True``. The till on both will be closed. * *partial close*: Both *close_db* and *close_ecf* are ``False``. It's more like a till verification. The actual user will do it to check and maybe remove money from till, leaving it ready for the next one. Note that this will not emit 'till-status-changed' event, since the till will not really close. * *fix conflicting status*: *close_db* and *close_ecf* are different. Use this only if you need to fix a conflicting status, like if the DB is open but the ECF is closed, or the other way around. :param close_db: If the till in the DB should be closed :param close_ecf: If the till in the ECF should be closed :returns: True if the till was closed, otherwise False """ is_partial = not close_db and not close_ecf manager = get_plugin_manager() # This behavior is only because of ECF if not is_partial and not self._previous_day: if (manager.is_active('ecf') and not yesno(_("You can only close the till once per day. " "You won't be able to make any more sales today.\n\n" "Close the till?"), Gtk.ResponseType.NO, _("Close Till"), _("Not now"))): return elif not is_partial: # When closing from a previous day, close only what is needed. close_db = self._close_db close_ecf = self._close_ecf if close_db: till = Till.get_last_opened(self.store) assert till store = api.new_store() editor_class = TillVerifyEditor if is_partial else TillClosingEditor model = run_dialog(editor_class, self._parent, store, previous_day=self._previous_day, close_db=close_db, close_ecf=close_ecf) if not model: store.confirm(model) store.close() return # TillClosingEditor closes the till retval = store.confirm(model) store.close() if retval and not is_partial: self._till_status_changed(closed=True, blocked=False) return retval
def _close_till(self): if self._sale_started: if not yesno(_('You must finish or cancel the current sale before ' 'you can close the till.'), gtk.RESPONSE_NO, _("Cancel sale"), _("Finish sale")): return self._cancel_order(show_confirmation=False) self._printer.close_till()
def on_receive_button__clicked(self, event): if yesno(_(u'Receive pending returned sale?'), gtk.RESPONSE_NO, _(u'Receive'), _(u"Don't receive")): current_user = api.get_current_user(self.store) self.model.returned_sale.confirm(current_user) SaleReturnWizardFinishEvent.emit(self.model.returned_sale) self.store.commit(close=False) self._setup_status()
def validate_confirm(self): if self._old_key and self._old_key != self.model.key: msg = _("Changing the backup key will make any backup done with " "the previous key unrecoverable. Are you sure?") if not yesno(msg, Gtk.ResponseType.NO, _("Change"), _("Keep old key")): return False return True
def on_cancel(self): if yesno( _("Some products were already adjusted. Do you want to " "save that information or discard them?"), gtk.RESPONSE_NO, _("Save adjustments"), _("Discard adjustments"), ): # change retval to True so the store gets commited self.retval = self.model
def validate_confirm(self): if all(i.is_adjusted for i in self.inventory_items): return True return yesno(_("Some products were not adjusted. By proceeding, you " "will be discarding those products' count and their " "old quantities will still be in the stock. Are you sure?"), gtk.RESPONSE_NO, _("Ignore adjustments"), _("Continue adjusting"))
def can_close_application(self): can_close_application = not self._sale_started if not can_close_application: if yesno(_('You must finish or cancel the current sale before you ' 'can close the POS application.'), gtk.RESPONSE_NO, _("Cancel sale"), _("Finish sale")): self._cancel_order(show_confirmation=False) return True return can_close_application
def _ask(self, app_info): if yesno(_("A spreadsheet has been created, " "what do you want to do with it?"), gtk.RESPONSE_NO, _('Save it to disk'), _("Open with %s") % (app_info.get_name())): return 'save' else: return 'open'
def _maybe_print_labels(self): param = api.sysparam.get_string('LABEL_TEMPLATE_PATH') if not param: return if not yesno(_(u'Do you want to print the labels for the received products?'), gtk.RESPONSE_YES, _(u'Print labels'), _(u"Don't print")): return label_data = run_dialog(SkipLabelsEditor, self, self.store) if label_data: print_labels(label_data, self.store, receiving=self.model)
def _cancel_order(self): if yesno(_(u"This will cancel the selected order. Are you sure?"), gtk.RESPONSE_NO, _(u"Don't cancel"), _(u"Cancel order")): return selection = self.results.get_selected() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.cancel() self._update_view()
def _finalize_production(self): if not yesno(_("The selected order will be finalized."), Gtk.ResponseType.YES, _("Finalize order"), _("Don't finalize")): return with api.new_store() as store: model = store.fetch(self.results.get_selected()) model.try_finalize_production(ignore_completion=True) self.refresh()
def _on_close_sellable_button__clicked(self, button, parent_button_label=None): msg = (_("Do you really want to close '%s'?\n" "Please note that when it's closed, you won't be able to " "commercialize it anymore.") % self._sellable.get_description()) if not yesno(msg, Gtk.ResponseType.NO, parent_button_label, _("Don't close")): return self._sellable.close(api.get_current_branch(self.store)) self.confirm()
def _open_coupon(self, sale=None): coupon = self._printer.create_coupon(sale=sale) if coupon: while not coupon.open(): if not yesno(_("Failed to open the fiscal coupon.\n" "Until it is opened, it's not possible to " "confirm the sale. Do you want to try again?"), Gtk.ResponseType.YES, _("Try again"), _("Cancel coupon")): return None return coupon
def _on_enable_production__clicked(self, button): if not self.current_app.can_close_application(): return if not yesno(_(u"This will enable production mode and finish the " u"demonstration. Are you sure?"), Gtk.ResponseType.NO, _(u"Enable production mode"), _(u"Continue testing")): return api.config.set('Database', 'enable_production', 'True') api.config.flush() self._shutdown_application(restart=True, force=True)
def _cancel_inventory(self): if not yesno(_('Are you sure you want to cancel this inventory ?'), Gtk.ResponseType.NO, _("Cancel inventory"), _("Don't cancel")): return store = api.new_store() inventory = store.fetch(self.results.get_selected()) inventory.cancel() store.commit() store.close() self.refresh() self._update_widgets()
def approve_order(self, work_order): if not yesno( _("This will inform the order that the client has " "approved the work. Are you sure?"), Gtk.ResponseType.NO, _("Approve"), _("Don't approve")): return with api.new_store() as store: work_order = store.fetch(work_order) work_order.approve() self.emit('model-edited', work_order)
def _approve_order(self): if not yesno(_(u"This will inform the order that the client has " u"approved the work. Are you sure?"), gtk.RESPONSE_NO, _(u"Approve"), _(u"Don't approve")): return selection = self.search.get_selected_item() with api.new_store() as store: work_order = store.fetch(selection.work_order) work_order.approve() self._update_view(select_item=selection)
def _maybe_print_labels(self): param = api.sysparam.get_string('LABEL_TEMPLATE_PATH') if not param: return if not yesno( _(u'Do you want to print the labels for the received products?' ), Gtk.ResponseType.YES, _(u'Print labels'), _(u"Don't print")): return label_data = run_dialog(SkipLabelsEditor, self, self.store) if label_data: print_labels(label_data, self.store, receiving=self.model)
def close_order(self, work_order): if not yesno( _("This will mark the order as delivered. Are you " "sure?"), Gtk.ResponseType.NO, _("Mark as delivered"), _("Don't mark")): return with api.new_store() as store: work_order = store.fetch(work_order) work_order.close() self.emit('model-edited', work_order)
def _pack(self): if not yesno(_("This will mark the delivery as packed. Are you sure?"), Gtk.ResponseType.NO, _(u"Mark as packed"), _(u"Don't mark")): return selection = self.search.get_selected_item() with api.new_store() as store: delivery = store.fetch(selection.delivery) delivery.pack(api.get_current_user(store)) self._update_view(select_item=selection)
def _confirm_order(self, order_view): if self.check_open_inventory(): return store = api.new_store() sale = store.fetch(order_view.sale) expire_date = sale.expire_date if (sale.status == Sale.STATUS_QUOTE and expire_date and expire_date.date() < date.today() and not yesno(_("This quote has expired. Confirm it anyway?"), Gtk.ResponseType.YES, _("Confirm quote"), _("Don't confirm"))): store.close() return missing = get_missing_items(sale, store) if missing: retval = run_dialog(MissingItemsDialog, self, sale, missing) if retval: self.refresh() store.close() return coupon = self._open_coupon(sale) if not coupon: store.close() return subtotal = coupon.add_sale_items(sale) try: if coupon.confirm(sale, store, subtotal=subtotal): workorders = WorkOrder.find_by_sale(store, sale) for order in workorders: # at this poing, orders could be either FINISHED or # DELIVERED (closed). If it is finished, we should close it # (mark delivered) ... if order.can_close(): order.close() else: # ... but if it didn't need closing, it should already # be delivered. assert order.is_finished() store.commit() self.refresh() else: coupon.cancel() except SellError as err: warning(str(err)) except ModelDataError as err: warning(str(err)) store.close()
def _on_reopen_sellable_button__clicked(self, button, parent_button_label=None): msg = (_("Do you really want to reopen '%s'?\n" "Note that when it's opened, you will be able to " "commercialize it again.") % self._sellable.get_description()) if not yesno(msg, gtk.RESPONSE_NO, parent_button_label, _("Keep closed")): return self._sellable.set_available() self.confirm()
def on_merge_button__clicked(self, widget): model = self.dup_tree.get_selected() to_merge = model.get_to_merge() msg = (_("This will merge %s persons into 1. Are you sure?") % len(to_merge)) if not yesno(msg, Gtk.ResponseType.NO, _("Merge"), _("Don't merge")): return with api.new_store() as store: self.merge(store, to_merge) if store.committed: self.dup_tree.remove(model)
def on_receive_button__clicked(self, event): assert self.model.status == self.model.STATUS_SENT if yesno(_(u'Receive the order?'), Gtk.ResponseType.YES, _(u'Receive'), _(u"Don't receive")): responsible = api.get_current_user(self.store).person.employee self.model.receive(responsible) self.store.commit(close=False) self.receival_date.set_property('model-attribute', 'receival_date') self.transfer_proxy.update_many( ['destination_responsible_name', 'receival_date']) self._setup_status()
def _open_coupon(self): coupon = self._printer.create_coupon() if coupon: while not coupon.open(): if not yesno( _("It is not possible to start a new sale if the " "fiscal coupon cannot be opened."), gtk.RESPONSE_YES, _("Try again"), _("Cancel sale")): return None self.set_sensitive([self.PaymentReceive], False) return coupon
def _close_order(self): if not yesno(_(u"This will mark the order as delivered. Are you " "sure?"), Gtk.ResponseType.NO, _(u"Mark as delivered"), _(u"Don't mark")): return selection = self.search.get_selected_item() with api.new_store() as store: work_order = store.fetch(selection.work_order) work_order.close() self._update_view(select_item=selection)
def _print_quote_details(self, quote, payments_created=False): msg_list = [] if not quote.group.payments.is_empty(): msg_list.append( _('The created payments can be found in the Accounts ' 'Receivable application and you can set them as paid ' 'there at any time.')) msg_list.append(_('Would you like to print the quote details now?')) # We can only print the details if the quote was confirmed. if yesno('\n\n'.join(msg_list), gtk.RESPONSE_YES, _("Print quote details"), _("Don't print")): print_report(SaleOrderReport, self.model)
def _send(self): if not yesno( _("This will mark the delivery as sent to the client. " "Are you sure?"), gtk.RESPONSE_NO, _(u"Mark as sent"), _(u"Don't mark")): return selection = self.search.get_selected_item() with api.new_store() as store: delivery = store.fetch(selection.delivery) delivery.pack() self._update_view(select_item=selection)
def remove_item(self, device): providers = self.store.find(CreditProvider, default_device=device).count() if providers > 0: info(_("Can not remove this device.\n" "It is being used as default device in %s credit provider(s)." % providers)) return False msg = _('Removing this device will also remove all related costs.') remove = yesno(msg, Gtk.ResponseType.NO, _('Remove'), _("Keep device")) if remove: device.delete(device.id, self.store) self.remove_list_item(device) return False
def _receive(self): if not yesno( _("This will mark the delivery as received by the recipient. " "Are you sure?"), Gtk.ResponseType.NO, _(u"Mark as received"), _(u"Don't mark")): return selection = self.search.get_selected_item() with api.new_store() as store: delivery = store.fetch(selection.delivery) delivery.receive() self._update_view(select_item=selection)
def _finish_order(self): if not yesno( _(u"This will finish the selected order, marking the " u"work as done. Are you sure?"), gtk.RESPONSE_NO, _(u"Finish order"), _(u"Don't finish")): return selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.finish() self._update_view()
def _close_inventory(self): # We will close only if the user really wants to. # This give the option to the user update the product # counting before the adjustment be done. msg = _('You have finished the product counting and none ' 'of the products need to be adjusted.\n\n' 'Would you like to close this inventory now ?') if yesno(msg, gtk.RESPONSE_NO, _('Close inventory'), _('Continue counting')): store = api.new_store() inventory = store.fetch(self.model) inventory.close() store.confirm(inventory) store.close()
def _cancel_group(self): msg = _("This will cancel the group and related quotes. " "Are you sure?") if not yesno(msg, gtk.RESPONSE_NO, _("Cancel group"), _("Don't Cancel")): return store = api.new_store() group = store.fetch(self._group) group.cancel() QuoteGroup.delete(group.id, store=store) store.confirm(True) store.close() self.wizard.finish()
def _printer_status__reply(self, status, reply): self.progress_dialog.stop() if not self._populate_ecf_printer(status): return if yesno(_("An ECF Printer was added. You need to restart Stoq " "before using it. Would you like to restart it now?"), gtk.RESPONSE_YES, _("Restart now"), _("Restart later")): self.store.commit() raise SystemExit # FIXME: move to base dialogs or base editor self.retval = self.model self.main_dialog.close()
def _cancel_group(self): msg = _("This will cancel the group and related quotes. " "Are you sure?") if not yesno(msg, Gtk.ResponseType.NO, _("Cancel group"), _("Don't Cancel")): return store = api.new_store() group = store.fetch(self._group) group.cancel() store.remove(group) store.confirm(True) store.close() self.wizard.finish()
def _remove_component(self, component): # Only allow remove the root components, since its the component # that really belongs to the current product root_component = self.component_tree.get_root(component) msg = _("This will remove the component \"%s\". Are you sure?") % ( root_component.description) if not yesno(msg, gtk.RESPONSE_NO, _("Remove component"), _("Keep component")): return self._remove_component_list.append(root_component) self._totally_remove_component(root_component) self._update_widgets()
def _register_branch(caller_store, station_name): import gtk from stoqlib.lib.parameters import sysparam if not sysparam(caller_store).DEMO_MODE: if not yesno( _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") % (station_name, db_settings.address), gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.login import LoginHelper h = LoginHelper(username="******") try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.person import Branch from stoqlib.domain.station import BranchStation branches = caller_store.find(Branch) if branches.is_empty(): error(_("Schema error, no branches found")) # TODO # Always select the first branch as the main branch, until we # support multiple branches properly. And then, provide a way to the # user choose which one will be the main branch. branch = branches[0] store = new_store() try: station = BranchStation.create(store, branch=store.fetch(branch), name=station_name) except StoqlibError as e: error(_("ERROR: %s") % e) station_id = station.id store.commit(close=True) return caller_store.find(BranchStation, id=station_id).one()
def cancel(self): log.info('Canceling coupon') while True: try: self.emit('cancel') break except (DriverError, DeviceError) as details: log.info("Error canceling coupon: %s" % str(details)) if not yesno(_(u"An error occurred while trying to cancel the " u"the coupon. Would you like to try again?"), gtk.RESPONSE_YES, _("Try again"), _(u"Don't try again")): return False _flush_interface() return True
def _on_delete_button__clicked(self, button, parent_button_label=None): sellable_description = self._sellable.get_description() msg = (_("This will delete '%s' from the database. Are you sure?") % sellable_description) if not yesno(msg, gtk.RESPONSE_NO, _("Delete"), _("Keep")): return try: self._sellable.remove() except IntegrityError as details: warning( _("It was not possible to remove '%s'") % sellable_description, str(details)) return self.confirm()
def print_quote_details(self, quote, payments_created=False): already_printed = SaleQuoteFinishPrintEvent.emit(self.model) if already_printed is not None: return msg_list = [] if not quote.group.payments.is_empty(): msg_list.append( _('The created payments can be found in the Accounts ' 'Receivable application and you can set them as paid ' 'there at any time.')) msg_list.append(_('Would you like to print the quote details now?')) # We can only print the details if the quote was confirmed. if yesno('\n\n'.join(msg_list), Gtk.ResponseType.YES, _("Print quote details"), _("Don't print")): print_report(SaleOrderReport, self.model)
def remove_item(self, provider): if self.store.find(CardOperationCost, provider=provider).any(): info(_("You can not remove this provider.\n" "It is being used in card device.")) return False elif self.store.find(CreditCardData, provider=provider).any(): info(_("You can not remove this provider.\n" "You already have payments using this provider.")) return False msg = _('Do you want remove %s?' % provider.short_name) remove = yesno(msg, Gtk.ResponseType.NO, _('Remove'), _("Cancel")) if remove: self.delete_model(provider, self.store) self.remove_list_item(provider) return False