def _edit(self, payable_views): with api.new_store() as store: order = store.fetch(payable_views[0].purchase) run_dialog(PurchasePaymentsEditor, self, store, order) if store.committed: self.refresh()
def test_dialog(): # pragma nocover from stoqlib.gui.base.dialogs import run_dialog ec = api.prepare_test() client = ec.store.find(Client).any() run_dialog(OpticalPatientDetails, None, ec.store, client) ec.store.commit()
def _pay(self, payable_views): """ Pay a list of items from a payable_views, note that the list of payable_views must reference the same order @param payables_views: a list of payable_views """ assert self._can_pay(payable_views) # Do not allow confirming the payment if the purchase was not # completely received. purchase_order = payable_views[0].purchase if (purchase_order and api.sysparam.get_bool('BLOCK_INCOMPLETE_PURCHASE_PAYMENTS') and not purchase_order.status == PurchaseOrder.ORDER_CLOSED): return warning(_("Can't confirm the payment if the purchase " "is not completely received yet.")) with api.new_store() as store: payments = [store.fetch(view.payment) for view in payable_views] run_dialog(PurchasePaymentConfirmSlave, self, store, payments=payments) if store.committed: # We need to refresh the whole list as the payment(s) can possibly # disappear for the selected view self.refresh() self._update_widgets()
def on_details_button_clicked(self, button): work_order_view = self.results.get_selected() if not work_order_view: return run_dialog(WorkOrderEditor, self, self.store, model=work_order_view.work_order, visual_mode=True)
def finish(self): missing = get_missing_items(self.model, self.store) if missing: run_dialog(MissingItemsDialog, self, self.model, missing) return False order = TransferOrder( open_date=self.model.open_date, receival_date=self.model.receival_date, source_branch=self.model.source_branch, destination_branch=self.model.destination_branch, source_responsible=self.model.source_responsible, destination_responsible=self.model.destination_responsible, store=self.store) for item in self.model.get_items(): transfer_item = order.add_sellable(item.sellable, quantity=item.quantity, batch=item.batch) transfer_item.send() # XXX Waiting for transfer order receiving wizard implementation order.receive() self.retval = self.model self.close() StockTransferWizardFinishEvent.emit(order) self._receipt_dialog(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 ' 'at this point, got nothing') run_dialog(PurchaseDetailsDialog, self.wizard, self.store, model=selected.purchase)
def on_details_button_clicked(self, *args): # FIXME: Person editor/slaves are depending on the store being a # StoqlibStore. See bug 5012 with api.trans() as store: selected = self.results.get_selected() user = store.fetch(selected.user) run_dialog(UserEditor, self, store, user, visual_mode=True)
def _dialog_client(self, id): from stoqlib.domain.person import Client from stoqlib.gui.dialogs.clientdetails import ClientDetailsDialog with api.new_store() as store: model = store.get(Client, id) run_dialog(ClientDetailsDialog, self.app, store, model)
def search_products(self): with api.new_store() as store: profile = api.get_current_user(store).profile can_create = (profile.check_app_permission('admin') or profile.check_app_permission('purchase')) run_dialog(ProductSearch, None, store, hide_footer=True, hide_toolbar=not can_create, hide_cost_column=not can_create)
def finish(self): missing = get_missing_items(self.model, self.store) if missing: run_dialog(MissingItemsDialog, self, self.model, missing) return False invoice_ok = InvoiceSetupEvent.emit() if invoice_ok is False: # If there is any problem with the invoice, the event will display an error # message and the dialog is kept open so the user can fix whatever is wrong. return # FIXME: If any issue happen at any point of the "send process", # trying to issue it again would make some products have their stock # decreased twice. Make sure we undo it first. # The issue itself was related to missing stock. Why get_missing_items # failed above? self.store.savepoint('before_send_transfer') try: self.model.send() except Exception as e: warning(_("An error happened when trying to confirm the transfer"), str(e)) self.store.rollback_to_savepoint('before_send_transfer') raise self.retval = self.model self.close() StockTransferWizardFinishEvent.emit(self.model) # Commit before printing to avoid losing data if something breaks self.store.confirm(self.retval) self._receipt_dialog(self.model)
def on_credit_transactions_button__clicked(self, button): # If we are not in edit mode, we are creating a new object, and thus we # should reuse the transaction reuse_store = not self.edit_mode run_dialog(CreditInfoListDialog, self.get_toplevel().get_toplevel(), self.store, self.model, reuse_store=reuse_store) self.proxy.update('credit_account_balance')
def run_person_role_dialog(role_editor, parent, store, model=None, **editor_kwargs): if not model: editor_kwargs.pop('visual_mode', None) return run_dialog(PersonRoleWizard, parent, store, role_editor, **editor_kwargs) return run_dialog(role_editor, parent, store, model, **editor_kwargs)
def test(): # pragma: no cover from stoqlib.gui.base.dialogs import run_dialog from stoqlib.api import api ec = api.prepare_test() model = ec.store.find(CostCenter).any() run_dialog(CostCenterDialog, None, ec.store, model)
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 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 invoice_ok = InvoiceSetupEvent.emit() if invoice_ok is False: # If there is any problem with the invoice, the event will display an error # message and the dialog is kept open so the user can fix whatever is wrong. # If this is the second time the user is trying to confirm, an # error message is being displayed saying that the payment can't be # created twice, so we clear the payments created to avoid the message # TODO: Create the payments on the wizard finish event (here) self.payment_group.clear_unused() return self.retval = True self.close() retval = ConfirmSaleWizardFinishEvent.emit(self.model) if retval is not None: self.retval = retval if sysparam.get_bool('PRINT_SALE_DETAILS_ON_POS'): self.print_sale_details()
def _show_details(self, model): from stoqlib.gui.editors.workordereditor import WorkOrderPackageItemEditor parent = self.get_toplevel().get_toplevel() # XXX: The window here is not decorated on gnome-shell, and because of # the visual_mode it gets no buttons. What to do? run_dialog(WorkOrderPackageItemEditor, parent, self.store, model=model.package_item, visual_mode=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 _show_client_birthdays_by_date(self, date): from stoqlib.gui.search.personsearch import ClientSearch with api.new_store() as store: y, m, d = map(int, date.split('-')) date = localdate(y, m, d).date() run_dialog(ClientSearch, self.app, store, birth_date=date)
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 _show_client_calls_by_date(self, date): from stoqlib.gui.search.callsearch import ClientCallsSearch store = api.new_store() y, m, d = map(int, date.split('-')) date = localdate(y, m, d).date() run_dialog(ClientCallsSearch, self.app, store, date=date) store.close()
def new_sale(self): store = self.window.store if Inventory.has_open(store, api.get_current_branch(store)): warning(_("You cannot create a quote with an open inventory.")) return with api.new_store() as store: run_dialog(SaleQuoteWizard, None, store)
def test_price_editor(): # pragma nocover from decimal import Decimal ec = api.prepare_test() sellable = ec.create_sellable() sellable.cost = Decimal('15.55') sellable.price = Decimal('21.50') run_dialog(SellablePriceEditor, parent=None, store=ec.store, model=sellable)
def _run_editor(self, button, editor_class): with api.trans() as store: run_dialog(editor_class, self, store) if store.committed: self.search.refresh() self.results.unselect_all() if len(self.results): self.results.select(self.results[-1])
def test_grid_editor(): # pragma nocover from stoqlib.gui.base.dialogs import run_dialog ec = api.prepare_test() group = ec.store.find(GridGroup).any() attribute = ec.create_grid_attribute(attribute_group=group) attribute.group = None run_dialog(GridAttributeEditor, parent=None, store=ec.store, model=attribute) print(attribute.group)
def show_details(self): """Called when the details button is clicked. Displays the details of the selected object in the list.""" model = self.get_details_model(self.klist.get_selected()) run_dialog(self.get_details_dialog_class(), parent=self._parent, store=self._parent.store, model=model, visual_mode=True)
def _maybe_show_welcome_dialog(self): from stoqlib.api import api if not api.user_settings.get('show-welcome-dialog', True): return api.user_settings.set('show-welcome-dialog', False) from stoq.gui.welcomedialog import WelcomeDialog from stoqlib.gui.base.dialogs import run_dialog run_dialog(WelcomeDialog)
def _dialog_work_order(self, id): from stoqlib.domain.workorder import WorkOrder from stoqlib.gui.editors.workordereditor import WorkOrderEditor with api.new_store() as store: model = store.get(WorkOrder, id) user = api.get_current_user(store) visual_mode = not user.profile.check_app_permission(u'services') run_dialog(WorkOrderEditor, self.app, store, model, visual_mode=visual_mode)
def _create_pre_sale(self): if self._current_app.check_open_inventory(): warning(_("You cannot create a pre-sale with an open inventory.")) return with api.new_store() as store: run_dialog(OpticalSaleQuoteWizard, self._current_app, store) if store.committed: self._current_app.refresh()
def _show_missing_products(self): missing_products = set([i.sellable for i in self.model.get_items()]) for quote in self.quoting_list: if quote.selected: missing_products = missing_products.difference(quote.items) if len(missing_products) == 0: break run_dialog(SimpleListDialog, self.wizard, self.product_columns, missing_products, title=_(u'Missing Products'))
def _run_comments_editor(self, item=None): if item is not None: run_dialog(NoteEditor, self, self.store, item, "comment", title=_("Sale Comment"), visual_mode=True) return with api.new_store() as store: item = SaleComment(store=store, sale=store.fetch(self.model.sale), author=api.get_current_user(store)) run_dialog(NoteEditor, self, store, item, "comment", title=_("New Sale Comment")) if store.committed: self._refresh_comments()
def _export_spreadsheet(self): """Runs a dialog to export the current search results to a CSV file. """ if self._is_accounts_tab(): run_dialog(FinancialReportDialog, self, self.store) else: page = self.get_current_page() sse = SpreadSheetExporter() sse.export(object_list=page.result_view, name=self.app_title, filename_prefix=self.app_name)
def test(): # pragma nocover creator = api.prepare_test() run_dialog(CloseLoanWizard, None, creator.store, create_sale=True) creator.store.rollback()
def on_client_details__clicked(self, button): client = self.model.client run_dialog(ClientDetailsDialog, self.wizard, self.store, client)
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, button): run_dialog(ClientDetailsDialog, self, self.store, self.model.client)
def _edit_order(self, order_view): run_dialog(NoteEditor, self, self.store, model=order_view, attr_name='notes', title=_(u"Notes"))
def _run_card_payment_search(self): run_dialog(CardPaymentSearch, self, self.store)
def on_status_details_button__clicked(self, button): run_dialog(RenegotiationDetailsDialog, self, self.store, self.model.group.renegotiation)
def show_details(self): model = self.get_details_model(self.klist.get_selected()) run_dialog(self.get_details_dialog_class(), store=self._parent.store, model=model)
class FiscalBookEntryEditor(BaseEditor): model_type = FiscalBookEntry gladefile = 'FiscalBookEntryEditor' proxy_widgets = ('cfop', 'date', 'invoice_number') def _setup_widgets(self): cfop_items = [(item.get_description(), item) for item in self.store.find(CfopData)] self.cfop.prefill(cfop_items) # # BaseEditor Hooks # def get_title(self, model): # FIXME: bug 5531 return _("Edit Fiscal Book Entry #%d") % (model.invoice_number or 0) def setup_proxies(self): self._setup_widgets() self.add_proxy(self.model, FiscalBookEntryEditor.proxy_widgets) if __name__ == '__main__': # pragma nocover ec = api.prepare_test() cfop = ec.create_cfop_data() run_dialog(CfopEditor, parent=None, store=ec.trans, model=cfop)
def on_additional_info_button__clicked(self, button): if run_dialog(NoteEditor, self, self.store, self.model, 'notes', title=_('Delivery Instructions')): self._update_widgets()
def on_details_btn__clicked(self, button): model = self.workorders.get_selected().work_order run_dialog(WorkOrderEditor, self, self.store, model=model, visual_mode=True)
def on_TillRemoveCash__activate(self, action): with api.new_store() as store: run_dialog(CashOutEditor, self, store) if store.committed: self._update_total()
def _run_details_dialog(self): sale_view = self._check_selected() run_dialog(SaleDetailsDialog, self, self.store, sale_view)
def _run_bill_check_search(self): run_dialog(InPaymentBillCheckSearch, self, self.store)
def test(): # pragma nocover creator = api.prepare_test() retval = run_dialog(PurchaseWizard, None, creator.store) creator.store.confirm(retval)
def test(): # pragma nocover creator = api.prepare_test() sale_item = creator.create_sale_item() retval = run_dialog(ConfirmSaleWizard, None, creator.store, sale_item.sale) creator.store.confirm(retval)
confirm_widgets = ['name', 'max_discount'] fields = dict( name=TextField(_('Name'), proxy=True), max_discount=PercentageField(_('Max Discount'), proxy=True), ) def create_model(self, store): return ClientCategory(name=u'', store=store) def setup_proxies(self): self.name.grab_focus() # # Kiwi Callbacks # def on_name__validate(self, widget, new_name): if not new_name: return ValidationError( _("The client category should have a name.")) if self.model.check_unique_value_exists(ClientCategory.name, new_name): return ValidationError( _("The client category '%s' already exists.") % new_name) if __name__ == '__main__': # pragma nocover ec = api.prepare_test() model = ec.create_client_category() run_dialog(ClientCategoryEditor, parent=None, store=ec.store, model=model)
def on_notes_button__clicked(self, *args): run_dialog(NoteEditor, self.wizard, self.store, self.model, 'notes', title=_("Additional Information"))
def test(): # pragma: no cover from stoqlib.gui.base.dialogs import run_dialog ec = api.prepare_test() run_dialog(ProductSearch, None, ec.store)
def test(): # pragma nocover creator = api.prepare_test() retval = run_dialog(InPaymentEditor, None, creator.store, None) creator.store.confirm(retval)
def on_print_labels__clicked(self, button): label_data = run_dialog(SkipLabelsEditor, self, self.store) if label_data: print_labels(label_data, self.store, receiving=self.model)
def show_details(self, sale_view=None): if sale_view is None: sale_view = self.sales.get_selected() run_dialog(SaleDetailsDialog, self.parent, self.store, sale_view)
def on_return_btn__clicked(self, button): with api.new_store() as store: receiving_order = store.fetch(self.model) if run_dialog(StockDecreaseWizard, self, store, receiving_order=receiving_order): self.return_btn.set_sensitive(not self.model.is_totally_returned())
def _create_pre_sale(self): with api.trans() as store: run_dialog(OpticalSaleQuoteWizard, self._current_app, store)
def on_items_list__double_click(self, objectlist, item): if not item.reason: return run_dialog(NoteEditor, self, self.store, item, 'reason', title=_('Reason'), label_text=_('Adjust reason'), visual_mode=True)
default_store.commit() self._manager.install_plugin(plugin_name) self._manager.activate_plugin(plugin_name) # # BasicDialog # def confirm(self): msg = _("Are you sure you want activate this plugin?\n" "Please note that, once activated you will not " "be able to disable it.") response = yesno(msg, gtk.RESPONSE_NO, _("Activate plugin"), _("Not now")) if response: self._enable_plugin(self.klist.get_selected()) self.close() # # Callbacks # def _on_klist__selection_changed(self, list, data): self._update_widgets() if __name__ == '__main__': # pragma nocover ec = api.prepare_test() run_dialog(PluginManagerDialog, None, ec.store)
def on_info_button__clicked(self, button): item = self.items_list.get_selected() run_dialog(NoteEditor, self, self.store, item, 'reason', title=_('Reason'), label_text=_('Adjust reason'), visual_mode=True)
def run_dialog(self, editor_class, parent, *args, **kwargs): return run_dialog(editor_class, parent, *args, **kwargs)
def search_activate(self): run_dialog(OutPaymentBillCheckSearch, self, self.store)
def on_Preferences__activate(self, action): with api.new_store() as store: run_dialog(PreferencesEditor, self, store) self._update_toolbar_style()