Beispiel #1
0
    def test_till_open_other_station(self):
        till = Till(station=self.create_station(), store=self.store)
        till.open_till()

        till = Till(station=get_current_station(self.store), store=self.store)
        till.open_till()

        self.assertEqual(Till.get_last_opened(self.store), till)
Beispiel #2
0
    def test_till_open_other_station(self):
        till = Till(branch=self.current_branch,
                    station=self.create_station(),
                    store=self.store)
        till.open_till(self.current_user)

        till = Till(branch=self.current_branch,
                    station=self.current_station,
                    store=self.store)
        till.open_till(self.current_user)

        self.assertEqual(
            Till.get_last_opened(self.store, self.current_station), till)
Beispiel #3
0
    def test_till_close_final_cash_amount(self):
        station = self.create_station()
        till = Till(store=self.store,
                    branch=self.current_branch,
                    station=station)
        till.open_till(self.current_user)

        # There is no cash amount yet
        self.assertEqual(till.get_cash_amount(), 0)

        # Add a card payment. Cash amount is still at zero
        payment = self.create_card_payment(provider_id='VISA')
        TillEntry(description=u'test',
                  value=payment.value,
                  till=till,
                  station=station,
                  branch=till.station.branch,
                  payment=payment,
                  store=self.store)
        self.assertEqual(till.get_cash_amount(), 0)

        # Add a cash payment. cash amount increases
        payment = self.create_payment()
        TillEntry(description=u'test',
                  value=payment.value,
                  till=till,
                  station=self.current_station,
                  branch=till.station.branch,
                  payment=payment,
                  store=self.store)
        self.assertEqual(till.get_cash_amount(), 10)

        # Final cash amount should consider only CASH payments
        till.close_till(self.current_user)
        self.assertEqual(till.final_cash_amount, 10)
Beispiel #4
0
    def test_get_cash_amount(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        old = till.get_cash_amount()
        # money operations
        till.add_credit_entry(currency(10), u"")
        self.assertEqual(till.get_cash_amount(), old + 10)
        till.add_debit_entry(currency(5), u"")
        self.assertEqual(till.get_cash_amount(), old + 5)
        # non-money operations
        payment1 = self._create_inpayment()
        till.add_entry(payment1)
        self.assertEqual(till.get_cash_amount(), old + 5)
        payment2 = self._create_outpayment()
        till.add_entry(payment2)
        self.assertEqual(till.get_cash_amount(), old + 5)
        # money payment method operation
        payment = self.create_payment()
        payment.due_date = till.opening_date
        payment.set_pending()
        TillEntry(description=u'test',
                  value=payment.value,
                  till=till,
                  branch=till.station.branch,
                  payment=payment,
                  store=self.store)
        payment.pay()
        self.assertEqual(till.get_cash_amount(), old + 5 + payment.value)
Beispiel #5
0
    def test_till_open_previously_opened(self):
        yesterday = localnow() - datetime.timedelta(1)

        # Open a till, set the opening_date to yesterday
        till = Till(station=get_current_station(self.store), store=self.store)
        till.open_till()
        till.opening_date = yesterday
        till.add_credit_entry(currency(10), u"")
        till.close_till()
        till.closing_date = yesterday

        new_till = Till(station=get_current_station(self.store),
                        store=self.store)
        self.assertTrue(new_till._get_last_closed_till())
        new_till.open_till()
        self.assertEqual(new_till.initial_cash_amount, till.final_cash_amount)
Beispiel #6
0
    def test_add_debit_entry(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        self.assertEqual(till.get_balance(), 0)
        till.add_debit_entry(10)
        self.assertEqual(till.get_balance(), -10)
Beispiel #7
0
    def _open_till(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        TillOpenEvent.emit(till=till)
        self.assertEqual(till, Till.get_current(store))
        return till
Beispiel #8
0
    def create_model(self, store):
        till = Till(store=store,
                    branch=api.get_current_branch(store),
                    station=api.get_current_station(store))
        till.open_till(api.get_current_user(store))

        return _TillOpeningModel(till=till, value=currency(0))
Beispiel #9
0
 def test_get_last_closed(self):
     till = Till(store=self.store,
                 branch=self.current_branch,
                 station=self.current_station)
     till.open_till(self.current_user)
     till.close_till(self.current_user)
     self.assertEqual(
         Till.get_last_closed(self.store, self.current_station), till)
Beispiel #10
0
    def testAddEntryInPayment(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        payment = self._create_inpayment()
        self.assertEqual(till.get_balance(), 0)
        till.add_entry(payment)
        self.assertEqual(till.get_balance(), 10)
Beispiel #11
0
    def test_till_open_once(self):
        station = get_current_station(self.store)
        till = Till(store=self.store, station=station)

        till.open_till()
        till.close_till()

        self.assertRaises(TillError, till.open_till)
Beispiel #12
0
    def test_add_entry_out_payment(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        payment = self._create_outpayment()
        self.assertEqual(till.get_balance(), 0)
        till.add_entry(payment)
        self.assertEqual(till.get_balance(), -10)
Beispiel #13
0
 def test_till_close(self):
     station = self.create_station()
     till = Till(store=self.store, station=station)
     till.open_till()
     self.assertEqual(till.status, Till.STATUS_OPEN)
     till.close_till()
     self.assertEqual(till.status, Till.STATUS_CLOSED)
     self.assertRaises(TillError, till.close_till)
Beispiel #14
0
 def test_till_close_more_than_balance(self):
     station = self.create_station()
     till = Till(store=self.store,
                 branch=self.current_branch,
                 station=station)
     till.open_till(self.current_user)
     till.add_debit_entry(currency(20), u"")
     with self.assertRaises(ValueError):
         till.close_till(self.current_user)
Beispiel #15
0
 def test_needs_closing(self):
     till = Till(station=self.create_station(), store=self.store)
     self.failIf(till.needs_closing())
     till.open_till()
     self.failIf(till.needs_closing())
     till.opening_date = localnow() - datetime.timedelta(1)
     self.failUnless(till.needs_closing())
     till.close_till()
     self.failIf(till.needs_closing())
Beispiel #16
0
    def test_add_credit_entry(self):
        till = Till(store=self.store,
                    branch=self.current_branch,
                    station=self.create_station())
        till.open_till(self.current_user)

        self.assertEqual(till.get_balance(), 0)
        till.add_credit_entry(10)
        self.assertEqual(till.get_balance(), 10)
Beispiel #17
0
    def test_get_current_till_close(self):
        station = get_current_station(self.store)
        self.assertEqual(Till.get_current(self.store), None)
        till = Till(store=self.store, station=station)
        till.open_till()

        self.assertEqual(Till.get_current(self.store), till)
        till.close_till()
        self.assertEqual(Till.get_current(self.store), None)
Beispiel #18
0
    def test_get_balance(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        old = till.get_balance()
        till.add_credit_entry(currency(10), u"")
        self.assertEqual(till.get_balance(), old + 10)
        till.add_debit_entry(currency(5), u"")
        self.assertEqual(till.get_balance(), old + 5)
Beispiel #19
0
    def test_till_history_report(self):
        from stoqlib.gui.dialogs.tillhistory import TillHistoryDialog
        dialog = TillHistoryDialog(self.store)

        till = Till(station=self.current_station,
                    branch=self.current_branch,
                    store=self.store)
        till.open_till(self.current_user)

        sale = self.create_sale()
        sellable = self.create_sellable()
        sale.add_sellable(sellable, price=100)
        method = PaymentMethod.get_by_name(self.store, u'bill')
        payment = method.create_payment(sale.branch, sale.station,
                                        Payment.TYPE_IN, sale.group,
                                        Decimal(100))
        TillEntry(value=25,
                  identifier=20,
                  description=u"Cash In",
                  payment=None,
                  till=till,
                  branch=till.station.branch,
                  station=self.current_station,
                  date=datetime.date(2007, 1, 1),
                  store=self.store)
        TillEntry(value=-5,
                  identifier=21,
                  description=u"Cash Out",
                  payment=None,
                  till=till,
                  branch=till.station.branch,
                  station=self.current_station,
                  date=datetime.date(2007, 1, 1),
                  store=self.store)

        TillEntry(value=100,
                  identifier=22,
                  description=sellable.get_description(),
                  payment=payment,
                  till=till,
                  branch=till.station.branch,
                  station=self.current_station,
                  date=datetime.date(2007, 1, 1),
                  store=self.store)
        till_entry = list(self.store.find(TillEntry, till=till))
        today = datetime.date.today().strftime('%x')
        for item in till_entry:
            if today in item.description:
                date = datetime.date(2007, 1, 1).strftime('%x')
                item.description = item.description.replace(today, date)

            item.date = datetime.date(2007, 1, 1)
            dialog.results.append(item)

        self._diff_expected(TillHistoryReport, 'till-history-report',
                            dialog.results, list(dialog.results))
Beispiel #20
0
    def test_till_open_once(self):
        station = get_current_station(self.store)
        till = Till(store=self.store, station=station)

        till.open_till()
        till.close_till()

        with mock.patch.object(PluginManager, 'is_active') as is_active:
            is_active.return_value = True
            self.assertRaises(TillError, till.open_till)
Beispiel #21
0
    def test_get_debits_total(self):
        till = Till(store=self.store, station=self.create_station())
        till.open_till()

        old = till.get_debits_total()
        till.add_debit_entry(currency(10), u"")
        self.assertEqual(till.get_debits_total(), old - 10)
        # This should not affect the debit
        till.add_credit_entry(currency(5), u"")
        self.assertEqual(till.get_debits_total(), old - 10)
Beispiel #22
0
    def test_add_entry_in_payment(self):
        till = Till(store=self.store,
                    branch=self.current_branch,
                    station=self.create_station())
        till.open_till(self.current_user)

        payment = self._create_inpayment()
        self.assertEqual(till.get_balance(), 0)
        till.add_entry(payment)
        self.assertEqual(till.get_balance(), 10)
Beispiel #23
0
 def test_till_close(self):
     station = self.create_station()
     till = Till(store=self.store,
                 branch=self.current_branch,
                 station=station)
     till.open_till(self.current_user)
     self.assertEqual(till.status, Till.STATUS_OPEN)
     till.close_till(self.current_user)
     self.assertEqual(till.status, Till.STATUS_CLOSED)
     with self.assertRaises(TillError):
         till.close_till(self.current_user)
Beispiel #24
0
    def test_till_open_previously_not_closed(self):
        yesterday = localnow() - datetime.timedelta(1)

        # Open a till, set the opening_date to yesterday
        till = Till(station=get_current_station(self.store), store=self.store)
        till.open_till()
        till.opening_date = yesterday
        till.close_till()
        till.closing_date = None

        self.assertRaises(TillError, till.open_till)
Beispiel #25
0
 def _open_till(self, store, initial_cash_amount=0):
     station = get_current_station(store)
     last_till = Till.get_last(store)
     if not last_till or last_till.status != Till.STATUS_OPEN:
         # Create till and open
         till = Till(store=store, station=station)
         till.open_till()
         till.initial_cash_amount = decimal.Decimal(initial_cash_amount)
     else:
         # Error, till already opened
         assert False
Beispiel #26
0
    def test_till_open_once(self):
        till = Till(store=self.store,
                    branch=self.current_branch,
                    station=self.current_station)

        till.open_till(self.current_user)
        till.close_till(self.current_user)

        with mock.patch.object(PluginManager, 'is_active') as is_active:
            is_active.return_value = True
            with self.assertRaises(TillError):
                till.open_till(self.current_user)
Beispiel #27
0
    def test_get_current_till_open(self):
        self.assertEqual(Till.get_current(self.store), None)

        station = get_current_station(self.store)
        till = Till(store=self.store, station=station)

        self.assertEqual(Till.get_current(self.store), None)
        till.open_till()
        self.assertEqual(Till.get_current(self.store), till)
        self.assertEqual(till.opening_date.date(), localtoday().date())
        self.assertEqual(till.status, Till.STATUS_OPEN)

        self.assertRaises(TillError, till.open_till)
Beispiel #28
0
    def test_till_open_previously_not_closed(self):
        yesterday = localnow() - datetime.timedelta(1)

        # Open a till, set the opening_date to yesterday
        till = Till(branch=self.current_branch,
                    station=self.current_station,
                    store=self.store)
        till.open_till(self.current_user)
        till.opening_date = yesterday
        till.close_till(self.current_user)
        till.closing_date = None

        with self.assertRaises(TillError):
            till.open_till(self.current_user)
Beispiel #29
0
    def test_till_open_yesterday(self):
        yesterday = localnow() - datetime.timedelta(1)

        # Open a till, set the opening_date to yesterday
        till = Till(station=get_current_station(self.store), store=self.store)
        till.open_till()
        till.opening_date = yesterday

        self.assertRaises(TillError, Till.get_current, self.store)
        # This is used to close a till
        self.assertEqual(Till.get_last_opened(self.store), till)

        till.close_till()

        self.assertEqual(Till.get_current(self.store), None)
Beispiel #30
0
    def test_get_current_till_open(self):
        self.assertEqual(Till.get_current(self.store, self.current_station),
                         None)

        till = Till(store=self.store,
                    branch=self.current_branch,
                    station=self.current_station)

        self.assertEqual(Till.get_current(self.store, self.current_station),
                         None)
        till.open_till(self.current_user)
        self.assertEqual(Till.get_current(self.store, self.current_station),
                         till)
        self.assertEqual(till.opening_date.date(), localtoday().date())
        self.assertEqual(till.status, Till.STATUS_OPEN)

        with self.assertRaises(TillError):
            till.open_till(self.current_user)