def _edit(self, payable_views): with api.trans() as store: order = store.fetch(payable_views[0].purchase) run_dialog(PurchasePaymentsEditor, self, store, order) if store.committed: self.refresh()
def _run_order_details_dialog(self): selection = self.search.get_selected_item() with api.trans() as store: self.run_dialog(WorkOrderEditor, store, model=store.fetch(selection.work_order), visual_mode=True)
def _work(self): selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.work() self._update_view(select_item=selection)
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(self.store).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.trans() 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 _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.trans() as store: for order_view in valid_order_views: order = store.fetch(order_view.purchase) order.confirm() self.refresh() self.select_result(orders)
def _receive(self): with api.trans() as store: till = Till.get_current(store) assert till in_payment = self.results.get_selected() payment = store.fetch(in_payment.payment) assert self._can_receive(payment) retval = run_dialog(SalePaymentConfirmSlave, self, store, payments=[payment], show_till_info=False) if not retval: return try: TillAddCashEvent.emit(till=till, value=payment.value) except (TillError, DeviceError, DriverError) as e: warning(str(e)) return till_entry = till.add_credit_entry( payment.value, _(u'Received payment: %s') % payment.description) TillAddTillEntryEvent.emit(till_entry, store) if store.committed: self.search.refresh()
def _run_client_editor(self, client=None): with api.trans() as store: rv = run_person_role_dialog(ClientEditor, self, store, client, visual_mode=self.visual_mode) if rv: self._fill_clients_combo() self.client.select(self.store.fetch(rv))
def _update_list(self, sellable): assert isinstance(sellable, Sellable) try: sellable.check_taxes_validity() except TaxError as strerr: # If the sellable icms taxes are not valid, we cannot sell it. warning(strerr) return quantity = self.sellableitem_proxy.model.quantity is_service = sellable.service if is_service and quantity > 1: # It's not a common operation to add more than one item at # a time, it's also problematic since you'd have to show # one dialog per service item. See #3092 info( _("It's not possible to add more than one service " "at a time to an order. So, only one was added.")) sale_item = TemporarySaleItem(sellable=sellable, quantity=quantity) if is_service: with api.trans() as store: rv = self.run_dialog(ServiceItemEditor, store, sale_item) if not rv: return self._update_added_item(sale_item)
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 _update_list(self, sellable): assert isinstance(sellable, Sellable) try: sellable.check_taxes_validity() except TaxError as strerr: # If the sellable icms taxes are not valid, we cannot sell it. warning(strerr) return quantity = self.sellableitem_proxy.model.quantity is_service = sellable.service if is_service and quantity > 1: # It's not a common operation to add more than one item at # a time, it's also problematic since you'd have to show # one dialog per service item. See #3092 info(_("It's not possible to add more than one service " "at a time to an order. So, only one was added.")) sale_item = TemporarySaleItem(sellable=sellable, quantity=quantity) if is_service: with api.trans() as store: rv = self.run_dialog(ServiceItemEditor, store, sale_item) if not rv: return self._update_added_item(sale_item)
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(self.store).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.trans() 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 _open_inventory(self): with api.trans() as store: rv = self.run_dialog(InventoryOpenEditor, store) if rv: self.refresh() self._update_widgets()
def _run_category_editor(self, category=None): with api.trans() as store: rv = run_dialog(WorkOrderCategoryEditor, self, store, category, visual_mode=self.visual_mode) if rv: self._fill_categories_combo() self.category.select(self.store.fetch(rv))
def _run_medic_editor(self, medic=None, visual_mode=False): with api.trans() as store: medic = run_person_role_dialog(MedicEditor, self, store, medic, visual_mode=True) if medic: self._medic_combo_prefill() medic = self.store.fetch(medic) self.medic_combo.select(medic)
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.trans() as store: for order_view in valid_order_views: order = store.fetch(order_view.purchase) order.confirm() self.refresh() self.select_result(orders)
def _receive(self): with api.trans() as store: till = Till.get_current(store) assert till in_payment = self.results.get_selected() payment = store.fetch(in_payment.payment) assert self._can_receive(payment) retval = run_dialog(SalePaymentConfirmSlave, self, store, payments=[payment], show_till_info=False) if not retval: return try: TillAddCashEvent.emit(till=till, value=payment.value) except (TillError, DeviceError, DriverError) as e: warning(str(e)) return till_entry = till.add_credit_entry(payment.value, _(u'Received payment: %s') % payment.description) TillAddTillEntryEvent.emit(till_entry, store) if store.committed: self.search.refresh()
def on_ProductsPriceSearch__activate(self, action): from stoqlib.domain.person import ClientCategory if not self.store.find(ClientCategory).count(): warning(_("Can't use prices editor without client categories")) return with api.trans() as store: self.run_dialog(SellablePriceDialog, store)
def _new_consignment(self): with api.trans() as store: self.run_dialog(ConsignmentWizard, store, model=None) if store.committed: self.refresh() res = self.store.find(PurchaseOrderView, id=store.retval.id).one() self.select_result(res)
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 _new_order(self, order=None, edit_mode=False): with api.trans() as store: order = store.fetch(order) self.run_dialog(PurchaseWizard, store, order, edit_mode) if store.committed: self.refresh() res = self.store.find(PurchaseOrderView, id=store.retval.id).one() self.select_result(res)
def _new_order(self, category=None): with api.trans() as store: work_order = self.run_dialog(WorkOrderEditor, store, category=store.fetch(category)) if store.committed: self._update_view(select_item=work_order) # A category may have been created on the editor self._update_filters()
def add_payment(self, category=None): with api.trans() as store: self.run_dialog(self.editor_class, store, category=category) if store.committed: self._update_filter_items() self.search.refresh() self.select_result(self.store.find(self.search_table, id=store.retval.id).one())
def add_payment(self, category=None): with api.trans() as store: self.run_dialog(self.editor_class, store, category=category) if store.committed: self._update_filter_items() self.search.refresh() self.select_result(self.store.find(self.search_spec, id=store.retval.id).one())
def _quote_order(self, quote=None): with api.trans() as store: quote = store.fetch(quote) self.run_dialog(QuotePurchaseWizard, store, quote) if store.committed: self.refresh() res = self.store.find(PurchaseOrderView, id=store.retval.id).one() self.select_result(res)
def on_StockInitial__activate(self, action): if self.check_open_inventory(): return with api.trans() as store: self.run_dialog(InitialStockDialog, store) if store.committed: self.refresh()
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 _edit_order(self): selection = self.results.get_selected() with api.trans() as store: self.run_dialog(WorkOrderEditor, store, model=store.fetch(selection.work_order)) if store.committed: self._update_view() # A category may have been created on the editor self._update_filters()
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.trans() as store: run_dialog(OpticalSaleQuoteWizard, self._current_app, store) if store.committed: self._current_app.refresh()
def _cancel_order(self): if not yesno(_(u"This will cancel the selected order. Are you sure?"), gtk.RESPONSE_NO, _(u"Cancel order"), _(u"Don't cancel")): return selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.cancel() self._update_view()
def _run_add_cash_dialog(self): with api.trans() as store: try: run_dialog(CashInEditor, self, store) except TillError as err: # Inform the error to the user instead of crashing warning(str(err)) return if store.committed: self._update_total()
def _edit_order(self, work_order=None): if work_order is None: work_order = self.search.get_selected_item().work_order with api.trans() as store: self.run_dialog(WorkOrderEditor, store, model=store.fetch(work_order)) if store.committed: self._update_view() # A category may have been created on the editor self._update_filters()
def show_comments(self, payment_view): """Shows a dialog with comments saved on the payment @param payment_view: an OutPaymentView or InPaymentView instance """ with api.trans() as store: run_dialog(PaymentCommentsDialog, self, store, payment_view.payment) if store.committed: payment_view.sync() self.results.update(payment_view)
def _cancel_order(self): msg_text = _(u"This will cancel the selected order. Are you sure?") rv = self._run_notes_editor(msg_text=msg_text, mandatory=True) if not rv: return selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.cancel(reason=rv.notes) self._update_view()
def _return_sale(self): if self.check_open_inventory(): return sale_view = self._check_selected() with api.trans() as store: return_sale(self.get_toplevel(), store.fetch(sale_view.sale), store) if store.committed: self._update_total() self.refresh()
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.trans() as store: work_order = store.fetch(selection.work_order) work_order.approve() 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 _finish_order(self): order_views = self.results.get_selected_rows() qty = len(order_views) if qty != 1: raise ValueError('You should have only one order selected ' 'at this point, got %d' % qty) with api.trans() as store: order = store.fetch(order_views[0].purchase) self.run_dialog(PurchaseFinishWizard, store, order) self.refresh() self.select_result(order_views)
def _undo_rejection(self): msg_text = _(u"This will undo the rejection of the order. " u"Are you sure?") rv = self._run_notes_editor(msg_text=msg_text, mandatory=False) if not rv: return selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.undo_rejection(reason=rv.notes) 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 show_details(self, payment_view): """Shows some details about the payment, allowing to edit a few properties """ with api.trans() as store: payment = store.fetch(payment_view.payment) run_dialog(self.editor_class, self, store, payment) if store.committed: payment_view.sync() self.results.update(payment_view) return payment
def _pause_order(self): msg_text = _(u"This will inform the order that we are waiting. " u"Are you sure?") rv = self._run_notes_editor(msg_text=msg_text, mandatory=True) if not rv: return selection = self.search.get_selected_item() with api.trans() as store: work_order = store.fetch(selection.work_order) work_order.pause(reason=rv.notes) self._update_view(select_item=selection)