Exemplo n.º 1
0
    def _open_till(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        TillOpenEvent.emit(till=till)
        self.assertEquals(till, Till.get_current(store))
        return till
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
0
 def before_start(self, store):
     till = Till.get_current(store)
     if till is None:
         till = Till(store=store,
                     station=get_current_station(store))
         till.open_till()
         assert till == Till.get_current(store)
Exemplo n.º 5
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)
Exemplo n.º 6
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))
Exemplo n.º 7
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)
Exemplo n.º 8
0
    def testGetCashAmount(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.till = till
        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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def testTillClose(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)
Exemplo n.º 11
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)
Exemplo n.º 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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
    def testTillOpenOnce(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)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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())
Exemplo n.º 21
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)
Exemplo n.º 22
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)
Exemplo n.º 23
0
    def testGetCurrentTillClose(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)
Exemplo n.º 24
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())
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
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)
Exemplo n.º 28
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)
Exemplo n.º 29
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))
Exemplo n.º 30
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)
Exemplo n.º 31
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)
Exemplo n.º 32
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)
Exemplo n.º 33
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)
Exemplo n.º 34
0
    def test_till_history_report(self):
        from stoqlib.gui.dialogs.tillhistory import TillHistoryDialog

        dialog = TillHistoryDialog(self.store)

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

        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(Payment.TYPE_IN, sale.group, sale.branch, Decimal(100))
        TillEntry(
            value=25,
            identifier=20,
            description=u"Cash In",
            payment=None,
            till=till,
            branch=till.station.branch,
            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,
            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,
            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))
Exemplo n.º 35
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)
Exemplo n.º 36
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)
Exemplo n.º 37
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)
Exemplo n.º 38
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
Exemplo n.º 39
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)
Exemplo n.º 40
0
    def testTillOpenPreviouslyNotClosed(self):
        yesterday = datetime.datetime.today() - 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)
Exemplo n.º 41
0
    def testGetCurrentTillOpen(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)
Exemplo n.º 42
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)
Exemplo n.º 43
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)
Exemplo n.º 44
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)
Exemplo n.º 45
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)
Exemplo n.º 46
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)
Exemplo n.º 47
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.failUnless(new_till._get_last_closed_till())
        new_till.open_till()
        self.assertEquals(new_till.initial_cash_amount, till.final_cash_amount)
Exemplo n.º 48
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)
Exemplo n.º 49
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)
Exemplo n.º 50
0
 def testGetLastClosed(self):
     till = Till(store=self.store,
                 station=get_current_station(self.store))
     till.open_till()
     till.close_till()
     self.assertEquals(Till.get_last_closed(self.store), till)
Exemplo n.º 51
0
 def testTillCloseMoreThanBalance(self):
     station = self.create_station()
     till = Till(store=self.store, station=station)
     till.open_till()
     till.add_debit_entry(currency(20), u"")
     self.assertRaises(ValueError, till.close_till)
Exemplo n.º 52
0
 def _createUnclosedTill(self):
     till = Till(station=get_current_station(self.store),
                 store=self.store)
     till.open_till()
     yesterday = datetime.date.today() - datetime.timedelta(1)
     till.opening_date = yesterday
Exemplo n.º 53
0
    def create_model(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        return _TillOpeningModel(till=till, value=currency(0))
Exemplo n.º 54
0
 def test_get_last(self):
     till = Till(store=self.store,
                 station=get_current_station(self.store))
     till.open_till()
     self.assertEquals(Till.get_last(self.store), till)