def open_till(self): """Open the till. It can only be done once per day. The final cash amount of the previous till will be used as the initial value in this one after opening it. """ if self.status == Till.STATUS_OPEN: raise TillError(_('Till is already open')) # Make sure that the till has not been opened today today = localtoday().date() if not self.store.find( Till, And( Date(Till.opening_date) >= today, Till.station_id == self.station.id)).is_empty(): raise TillError(_("A till has already been opened today")) last_till = self._get_last_closed_till() if last_till: if not last_till.closing_date: raise TillError(_("Previous till was not closed")) initial_cash_amount = last_till.final_cash_amount else: initial_cash_amount = 0 self.initial_cash_amount = initial_cash_amount self.opening_date = TransactionTimestamp() self.status = Till.STATUS_OPEN
def open_till(self): """Open the till. It can only be done once per day. The final cash amount of the previous till will be used as the initial value in this one after opening it. """ if self.status == Till.STATUS_OPEN: raise TillError(_('Till is already open')) manager = get_plugin_manager() # The restriction to only allow opening the till only once per day comes from # the (soon to be obsolete) ECF devices. if manager.is_active('ecf'): # Make sure that the till has not been opened today today = localtoday().date() if not self.store.find( Till, And( Date(Till.opening_date) >= today, Till.station_id == self.station.id)).is_empty(): raise TillError(_("A till has already been opened today")) last_till = self._get_last_closed_till() if last_till: if not last_till.closing_date: raise TillError(_("Previous till was not closed")) initial_cash_amount = last_till.final_cash_amount else: initial_cash_amount = 0 self.initial_cash_amount = initial_cash_amount self.opening_date = TransactionTimestamp() self.status = Till.STATUS_OPEN self.responsible_open = get_current_user(self.store) assert self.responsible_open is not None TillOpenedEvent.emit(self)
def get_current(cls, store, station: BranchStation): """Fetches the Till for the current station. :param store: a store :returns: a Till instance or None """ assert station is not None till = store.find(cls, status=Till.STATUS_OPEN, station=station).one() if till and till.needs_closing(): fmt = _("You need to close the till opened at %s before " "doing any fiscal operations") raise TillError(fmt % (till.opening_date.date(), )) return till
def close_till(self): """This method close the current till operation with the confirmed sales associated. If there is a sale with a differente status than SALE_CONFIRMED, a new 'pending' till operation is created and these sales are associated with the current one. """ if self.status == Till.STATUS_CLOSED: raise TillError(_("Till is already closed")) if self.get_balance() < 0: raise ValueError( _("Till balance is negative, but this should not " "happen. Contact Stoq Team if you need " "assistance")) self.final_cash_amount = self.get_balance() self.closing_date = TransactionTimestamp() self.status = Till.STATUS_CLOSED
def _till_event(*args, **kwargs): raise TillError("ERROR")