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(api.get_current_user(self.store)) 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 _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 test_get_missing_items(self): sale = self.create_sale() stock_item = self.create_sale_item(sale=sale) missing_item = self.create_sale_item(sale=sale) stock_storable = self.create_storable( product=stock_item.sellable.product) missing_storable = self.create_storable( product=missing_item.sellable.product) self.create_product_stock_item(storable=stock_storable, quantity=1) self.create_product_stock_item(storable=missing_storable, quantity=0) missing = get_missing_items(sale, self.store) self.assertEqual(missing[0].storable, missing_storable)
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 for item in self.model.get_items(): sellable = item.sellable if not sellable.is_available(self.model.branch): self.close() warning( _("%s is not available for sale. Try making it " "available first or change it on sale and then try again." ) % (sellable.get_description())) 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 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 self.model.confirm() self.model.sync_stock(api.get_current_user(self.store)) self.retval = self.model self.close() NewLoanWizardFinishEvent.emit(self.model) # Confirm before printing to avoid losing data if something breaks self.store.confirm(self.retval) self._print_receipt(self.model)
def finish(self): missing = get_missing_items(self.model, self.store) if missing: run_dialog(MissingItemsDialog, self, self.model, missing) return False # If this wizard is for a purchase return, the items are automatically # added so the tax check escaped. So we do it now. if self.receiving_order is not None: missing_tax_info = [] for item in self.model.get_items(): sellable = item.sellable try: sellable.check_taxes_validity(self.model.branch) except TaxError: missing_tax_info.append(sellable.description) if missing_tax_info: warning(_("There are some items with missing tax information"), ', '.join(missing_tax_info)) 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 self.retval = self.model self.store.confirm(self.model) self.model.confirm(api.get_current_user(self.store)) self.close() StockDecreaseWizardFinishEvent.emit(self.model) # Commit before printing to avoid losing data if something breaks self.store.confirm(self.retval) self._receipt_dialog()