def confirm(self, sale, store, savepoint=None, subtotal=None): """Confirms a |sale| on fiscalprinter and database If the sale is confirmed, the store will be committed for you. There's no need for the callsite to call store.confirm(). If the sale is not confirmed, for instance the user cancelled the sale or there was a problem with the fiscal printer, then the store will be rolled back. :param sale: the |sale| to be confirmed :param trans: a store :param savepoint: if specified, a database savepoint name that will be used to rollback to if the sale was not confirmed. :param subtotal: the total value of all the items in the sale """ # Actually, we are confirming the sale here, so the sale # confirmation process will be available to others applications # like Till and not only to the POS. total_paid = sale.group.get_total_confirmed_value() model = run_dialog(ConfirmSaleWizard, self._parent, store, sale, subtotal=subtotal, total_paid=total_paid) if not model: CancelPendingPaymentsEvent.emit() store.rollback(name=savepoint, close=False) return False if sale.client and not self.is_customer_identified(): self.identify_customer(sale.client.person) if not self.totalize(sale): store.rollback(name=savepoint, close=False) return False if not self.setup_payments(sale): store.rollback(name=savepoint, close=False) return False if not self.close(sale, store): store.rollback(name=savepoint, close=False) return False try: sale.confirm() except SellError as err: warning(str(err)) store.rollback(name=savepoint, close=False) return False if not self.print_receipts(sale): warning(_("The sale was cancelled")) sale.cancel() print_cheques_for_payment_group(store, sale.group) # Only finish the transaction after everything passed above. store.confirm(model) return True
def confirm(self, sale, store, savepoint=None, subtotal=None): """Confirms a |sale| on fiscalprinter and database If the sale is confirmed, the store will be committed for you. There's no need for the callsite to call store.confirm(). If the sale is not confirmed, for instance the user cancelled the sale or there was a problem with the fiscal printer, then the store will be rolled back. :param sale: the |sale| to be confirmed :param trans: a store :param savepoint: if specified, a database savepoint name that will be used to rollback to if the sale was not confirmed. :param subtotal: the total value of all the items in the sale """ # Actually, we are confirming the sale here, so the sale # confirmation process will be available to others applications # like Till and not only to the POS. total_paid = sale.group.get_total_confirmed_value() model = run_dialog(ConfirmSaleWizard, self._parent, store, sale, subtotal=subtotal, total_paid=total_paid) if not model: CancelPendingPaymentsEvent.emit() store.rollback(name=savepoint, close=False) return False if sale.client and not self.is_customer_identified(): self.identify_customer(sale.client.person) if not self.totalize(sale): store.rollback(name=savepoint, close=False) return False if not self.setup_payments(sale): store.rollback(name=savepoint, close=False) return False if not self.close(sale, store): store.rollback(name=savepoint, close=False) return False try: sale.confirm() except SellError as err: warning(str(err)) store.rollback(name=savepoint, close=False) return False if not self.print_receipts(sale): warning(_("The sale was cancelled")) sale.cancel() print_cheques_for_payment_group(store, sale.group) # Only finish the transaction after everything passed above. store.confirm(model) # Try to print only after the transaction is commited, to prevent # losing data if something fails while printing group = sale.group 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"))): try: print_report(BookletReport, booklets) except ReportError: warning(_("Could not print 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"))): try: print_report(BillReport, bills) except ReportError: # TRANSLATORS: bills here refers to "boletos" in pt_BR warning(_("Could not print bills")) return True
def confirm(self, sale, store, savepoint=None, subtotal=None): """Confirms a |sale| on fiscalprinter and database If the sale is confirmed, the store will be committed for you. There's no need for the callsite to call store.confirm(). If the sale is not confirmed, for instance the user cancelled the sale or there was a problem with the fiscal printer, then the store will be rolled back. :param sale: the |sale| to be confirmed :param trans: a store :param savepoint: if specified, a database savepoint name that will be used to rollback to if the sale was not confirmed. :param subtotal: the total value of all the items in the sale """ # Actually, we are confirming the sale here, so the sale # confirmation process will be available to others applications # like Till and not only to the POS. payments_total = sale.group.get_total_confirmed_value() sale_total = sale.get_total_sale_amount() payment = get_formatted_price(payments_total) amount = get_formatted_price(sale_total) msg = _(u"Payment value (%s) is greater than sale's total (%s). " "Do you want to confirm it anyway?") % (payment, amount) if (sale_total < payments_total and not yesno(msg, gtk.RESPONSE_NO, _(u"Confirm Sale"), _(u"Don't Confirm"))): return False model = run_dialog(ConfirmSaleWizard, self._parent, store, sale, subtotal=subtotal, total_paid=payments_total, current_document=self._current_document) if not model: CancelPendingPaymentsEvent.emit() store.rollback(name=savepoint, close=False) return False if sale.client and not self.is_customer_identified(): self.identify_customer(sale.client.person) try: if not self.totalize(sale): store.rollback(name=savepoint, close=False) return False if not self.setup_payments(sale): store.rollback(name=savepoint, close=False) return False if not self.close(sale, store): store.rollback(name=savepoint, close=False) return False if not self.print_receipts(sale): store.rollback(name=savepoint, close=False) return False # FIXME: This used to be done inside sale.confirm. Maybe it would # be better to do a proper error handling till = Till.get_current(store) assert till sale.confirm(till=till) # Only finish the transaction after everything passed above. store.confirm(model) except Exception as e: warning(_("An error happened while trying to confirm the sale. " "Cancelling the coupon now..."), str(e)) self.cancel() store.rollback(name=savepoint, close=False) return False print_cheques_for_payment_group(store, sale.group) # Try to print only after the transaction is commited, to prevent # losing data if something fails while printing group = sale.group 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"))): try: print_report(BookletReport, booklets) except ReportError: warning(_("Could not print 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"))): try: print_report(BillReport, bills) except ReportError: # TRANSLATORS: bills here refers to "boletos" in pt_BR warning(_("Could not print bills")) return True
def confirm(self, sale, store, savepoint=None, subtotal=None): """Confirms a |sale| on fiscalprinter and database If the sale is confirmed, the store will be committed for you. There's no need for the callsite to call store.confirm(). If the sale is not confirmed, for instance the user cancelled the sale or there was a problem with the fiscal printer, then the store will be rolled back. :param sale: the |sale| to be confirmed :param trans: a store :param savepoint: if specified, a database savepoint name that will be used to rollback to if the sale was not confirmed. :param subtotal: the total value of all the items in the sale """ # Actually, we are confirming the sale here, so the sale # confirmation process will be available to others applications # like Till and not only to the POS. payments_total = sale.group.get_total_confirmed_value() sale_total = sale.get_total_sale_amount() payment = get_formatted_price(payments_total) amount = get_formatted_price(sale_total) msg = _(u"Payment value (%s) is greater than sale's total (%s). " "Do you want to confirm it anyway?") % (payment, amount) if (sale_total < payments_total and not yesno(msg, gtk.RESPONSE_NO, _(u"Confirm Sale"), _(u"Don't Confirm"))): return False model = run_dialog(ConfirmSaleWizard, self._parent, store, sale, subtotal=subtotal, total_paid=payments_total) if not model: CancelPendingPaymentsEvent.emit() store.rollback(name=savepoint, close=False) return False if sale.client and not self.is_customer_identified(): self.identify_customer(sale.client.person) if not self.totalize(sale): store.rollback(name=savepoint, close=False) return False if not self.setup_payments(sale): store.rollback(name=savepoint, close=False) return False if not self.close(sale, store): store.rollback(name=savepoint, close=False) return False # FIXME: This used to be done inside sale.confirm. Maybe it would be # better to do a proper error handling till = Till.get_current(store) assert till try: sale.confirm(till=till) except SellError as err: warning(str(err)) store.rollback(name=savepoint, close=False) return False if not self.print_receipts(sale): warning(_("The sale was cancelled")) sale.cancel(force=True) print_cheques_for_payment_group(store, sale.group) # Only finish the transaction after everything passed above. store.confirm(model) # Try to print only after the transaction is commited, to prevent # losing data if something fails while printing group = sale.group 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"))): try: print_report(BookletReport, booklets) except ReportError: warning(_("Could not print 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"))): try: print_report(BillReport, bills) except ReportError: # TRANSLATORS: bills here refers to "boletos" in pt_BR warning(_("Could not print bills")) return True
def confirm(self, sale, store, savepoint=None, subtotal=None, total_paid=0): """Confirms a |sale| on fiscalprinter and database If the sale is confirmed, the store will be committed for you. There's no need for the callsite to call store.confirm(). If the sale is not confirmed, for instance the user cancelled the sale or there was a problem with the fiscal printer, then the store will be rolled back. :param sale: the |sale| to be confirmed :param trans: a store :param savepoint: if specified, a database savepoint name that will be used to rollback to if the sale was not confirmed. :param subtotal: the total value of all the items in the sale :param total_paid: what has already been paid on this sale, used when returning an item """ # Actually, we are confirming the sale here, so the sale # confirmation process will be available to others applications # like Till and not only to the POS. model = run_dialog(ConfirmSaleWizard, self._parent, store, sale, subtotal=subtotal, total_paid=total_paid) missing = sale.get_missing_items() if missing: run_dialog(ConfirmSaleMissingDialog, self._parent, sale, missing) store.rollback(name=savepoint, close=False) return False if not model: CancelPendingPaymentsEvent.emit() store.rollback(name=savepoint, close=False) return False if sale.client and not self.is_customer_identified(): self.identify_customer(sale.client.person) if not self.totalize(sale): store.rollback(name=savepoint, close=False) return False if not self.setup_payments(sale): store.rollback(name=savepoint, close=False) return False if not self.close(sale, store): store.rollback(name=savepoint, close=False) return False sale.confirm() if not self.print_receipts(sale): warning('A venda foi cancelada') sale.cancel() if sale.only_paid_with_money(): sale.set_paid() else: sale.group.pay_money_payments() print_cheques_for_payment_group(store, sale.group) # Only finish the transaction after everything passed above. store.confirm(model) return True