コード例 #1
0
    def test_created_methods(self):
        # Payment.TYPE_IN
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)
        methods = ['bill', 'card', 'check', 'credit', 'deposit',
                   'money', 'multiple', 'store_credit']
        self.assertEqual(set(slave._widgets.keys()), set(methods))

        for method in methods:
            widget = slave._widgets.get(method)
            self.assertTrue(widget.get_visible())

        # Payment.TYPE_OUT
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_OUT)
        methods = ['bill', 'check', 'deposit', 'money']
        self.assertEqual(set(slave._widgets.keys()), set(methods))

        for method in methods:
            widget = slave._widgets.get(method)
            self.assertTrue(widget.get_visible())

        # Only 1 method available
        for method in self.store.find(PaymentMethod,
                                      PaymentMethod.method_name != u'money'):
            method.is_active = False
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)
        self.assertEqual(set(slave._widgets.keys()), set([u'money']))
        self.assertEqual(slave.get_selected_method().method_name, u'money')
コード例 #2
0
    def test_default_method(self):
        method = self.store.find(PaymentMethod, method_name=u'multiple').one()
        with self.sysparam(DEFAULT_PAYMENT_METHOD=method):
            slave = SelectPaymentMethodSlave(store=self.store,
                                             payment_type=Payment.TYPE_IN)
            self.assertEqual(slave.get_selected_method().method_name,
                             u'multiple')

            # If the default method is not created (setting is_active to False
            # does the trick), it should fallback to money
            method.is_active = False
            slave = SelectPaymentMethodSlave(store=self.store,
                                             payment_type=Payment.TYPE_IN)
            self.assertEqual(slave.get_selected_method().method_name, u'money')
コード例 #3
0
    def test_set_client_without_credit_and_store_credit(self):
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)
        client = self.create_client()

        slave.set_client(client, 100)
        self.check_slave(
            slave,
            'slave-select-payment-method-client-without-credit-and-store-credit')
コード例 #4
0
    def test_set_client_with_some_store_credit(self):
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)
        client = self.create_client()
        client.credit_limit = 10

        slave.set_client(client, 100)
        self.check_slave(
            slave, 'slave-select-payment-method-client-with-some-store-credit')
コード例 #5
0
ファイル: salewizard.py プロジェクト: esosaja/stoq
    def setup_slaves(self):
        marker('SelectPaymentMethodSlave')
        self.pm_slave = SelectPaymentMethodSlave(store=self.store,
                                                 payment_type=Payment.TYPE_IN)
        self.attach_slave('select_method_holder', self.pm_slave)

        marker('CashChangeSlave')
        self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard)
        self.attach_slave('cash_change_holder', self.cash_change_slave)
        self.cash_change_slave.received_value.connect(
            'activate', lambda entry: self.wizard.go_to_next())
コード例 #6
0
ファイル: purchasewizard.py プロジェクト: rosalin/stoq
    def _setup_widgets(self):
        register_payment_slaves()

        self._ms = SelectPaymentMethodSlave(store=self.store,
                                            payment_type=Payment.TYPE_OUT,
                                            default_method=self._method)
        self._ms.connect_after('method-changed',
                               self._after_method_select__method_changed)

        self.attach_slave('method_select_holder', self._ms)
        self._update_payment_method_slave()
コード例 #7
0
    def test_init_default_method(self):
        check_method = self.store.find(PaymentMethod,
                                       method_name=u'check').one()
        multiple_method = self.store.find(PaymentMethod,
                                          method_name=u'multiple').one()
        money_method = self.store.find(PaymentMethod,
                                       method_name=u'money').one()

        # Check should be selected here since it was passed as default ethod
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN,
                                         default_method=u'check')
        self.assertEqual(slave.get_selected_method(), check_method)

        with self.sysparam(DEFAULT_PAYMENT_METHOD=multiple_method):
            # Even with multiple as default, the constructor default
            # should overwrite it
            slave = SelectPaymentMethodSlave(store=self.store,
                                             payment_type=Payment.TYPE_IN,
                                             default_method=u'check')
            self.assertEqual(slave.get_selected_method(), check_method)

            # Making check inactive should make the DEFAULT_PAYMENT_METHOD
            # the default one on the slave
            check_method.is_active = False
            slave = SelectPaymentMethodSlave(store=self.store,
                                             payment_type=Payment.TYPE_IN,
                                             default_method=u'check')
            self.assertEqual(slave.get_selected_method(), multiple_method)

            # Making check and the DEFAULT_PAYMENT_METHOD inactive,
            # the default should fallback to money
            multiple_method.is_active = False
            slave = SelectPaymentMethodSlave(store=self.store,
                                             payment_type=Payment.TYPE_IN,
                                             default_method=u'check')
            self.assertEqual(slave.get_selected_method(), money_method)
コード例 #8
0
    def test_set_client_with_enough_credit(self):
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)
        client = self.create_client()
        method = self.store.find(PaymentMethod, method_name=u'credit').one()
        payment = self.create_payment(payment_type=Payment.TYPE_OUT,
                                      value=100, method=method)
        payment.group.payer = client.person
        payment.set_pending()
        payment.pay()

        slave.set_client(client, 100)
        self.check_slave(
            slave,
            'slave-select-payment-method-client-with-enough-credit')
コード例 #9
0
    def test_method_set_sensitive(self):
        inactive = self.store.find(PaymentMethod, method_name=u'bill').one()
        inactive.is_active = False

        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN,
                                         default_method=u'check')
        self.assertEqual(slave.get_selected_method().method_name, u'check')

        slave.method_set_sensitive(u'check', False)
        self.assertFalse(slave._widgets[u'check'].get_sensitive())
        self.assertEqual(slave.get_selected_method().method_name, u'money')

        # Test when the widget is not there
        slave.method_set_sensitive(u'bill', True)
コード例 #10
0
 def test_init(self):
     with self.assertRaisesRegexp(ValueError, "payment_type must be set"):
         SelectPaymentMethodSlave(payment_type=None)
コード例 #11
0
    def test_set_client_none(self):
        slave = SelectPaymentMethodSlave(store=self.store,
                                         payment_type=Payment.TYPE_IN)

        slave.set_client(None, 100)
        self.check_slave(slave, 'slave-select-payment-method-client-none')