def checkout(self, cancel_clear=False): """Initiates the sale wizard to confirm sale. :param cancel_clear: If cancel_clear is true, the sale will be cancelled if the checkout is cancelled. """ assert len(self.sale_items) >= 1 if self._current_store: store = self._current_store savepoint = 'before_run_fiscalprinter_confirm' store.savepoint(savepoint) else: store = api.new_store() savepoint = None if self._trade: if self._get_subtotal() < self._trade.returned_total: info(_("Traded value is greater than the new sale's value. " "Please add more items or return it in Sales app, " "then make a new sale")) return sale = self._create_sale(store) self._trade.new_sale = sale self._trade.trade() else: sale = self._create_sale(store) if sysparam.get_bool('CONFIRM_SALES_ON_TILL'): sale.order() store.commit() else: assert self._coupon ordered = self._coupon.confirm(sale, store, savepoint, subtotal=self._get_subtotal()) # Dont call store.confirm() here, since coupon.confirm() # above already did it if not ordered: # FIXME: Move to TEF plugin manager = get_plugin_manager() if manager.is_active('tef') or cancel_clear: self._cancel_order(show_confirmation=False) elif not self._current_store: # Just do that if a store was created above and # if _cancel_order wasn't called (it closes the connection) store.rollback(close=True) return log.info("Checking out") self._coupon = None POSConfirmSaleEvent.emit(sale, self.sale_items[:]) # We must close the connection only after the event is emmited, since it # may use value from the sale that will become invalid after it is # closed store.close() self._clear_order()
def checkout(self, cancel_clear=False): """Initiates the sale wizard to confirm sale. :param cancel_clear: If cancel_clear is true, the sale will be cancelled if the checkout is cancelled. """ assert len(self.sale_items) >= 1 if self._current_store: store = self._current_store savepoint = 'before_run_fiscalprinter_confirm' store.savepoint(savepoint) else: store = api.new_store() savepoint = None if self._trade: if self._get_subtotal() < self._trade.returned_total: info( _("Traded value is greater than the new sale's value. " "Please add more items or return it in Sales app, " "then make a new sale")) return sale = self._create_sale(store) self._trade.new_sale = sale self._trade.trade() else: sale = self._create_sale(store) if self.param.CONFIRM_SALES_ON_TILL: sale.order() store.commit(close=True) else: assert self._coupon ordered = self._coupon.confirm(sale, store, savepoint, subtotal=self._get_subtotal()) # Dont call store.confirm() here, since coupon.confirm() # above already did it if not ordered: # FIXME: Move to TEF plugin manager = get_plugin_manager() if manager.is_active('tef') or cancel_clear: self._cancel_order(show_confirmation=False) elif not self._current_store: # Just do that if a store was created above and # if _cancel_order wasn't called (it closes the connection) store.rollback(close=True) return log.info("Checking out") store.close() self._coupon = None POSConfirmSaleEvent.emit(sale, self.sale_items[:]) self._clear_order()