示例#1
0
 def testGetActiveMethods(self):
     methods = PaymentMethod.get_active_methods(self.store)
     self.assertTrue(methods)
     self.assertEquals(len(methods), 9)
     self.assertEquals(methods[0].method_name, u'bill')
     self.assertEquals(methods[1].method_name, u'card')
     self.assertEquals(methods[2].method_name, u'check')
     self.assertEquals(methods[3].method_name, u'deposit')
     self.assertEquals(methods[4].method_name, u'money')
     self.assertEquals(methods[5].method_name, u'multiple')
     self.assertEquals(methods[6].method_name, u'online')
     self.assertEquals(methods[7].method_name, u'store_credit')
     self.assertEquals(methods[8].method_name, u'trade')
示例#2
0
 def test_get_active_methods(self):
     methods = PaymentMethod.get_active_methods(self.store)
     self.assertTrue(methods)
     self.assertEqual(len(methods), 10)
     self.assertEqual(methods[0].method_name, u'bill')
     self.assertEqual(methods[1].method_name, u'card')
     self.assertEqual(methods[2].method_name, u'check')
     self.assertEqual(methods[3].method_name, u'credit')
     self.assertEqual(methods[4].method_name, u'deposit')
     self.assertEqual(methods[5].method_name, u'money')
     self.assertEqual(methods[6].method_name, u'multiple')
     self.assertEqual(methods[7].method_name, u'online')
     self.assertEqual(methods[8].method_name, u'store_credit')
     self.assertEqual(methods[9].method_name, u'trade')
示例#3
0
    def create_payment_filter(self, label=None):
        from stoqlib.domain.payment.method import PaymentMethod
        methods = PaymentMethod.get_active_methods(self.store)
        items = [(_('Any'), None)]
        for method in methods:
            if method.method_name == 'multiple':
                continue
            items.append((method.description, method))

        if not label:
            label = _('Method:')
        payment_filter = ComboSearchFilter(label, items)
        payment_filter.select(None)

        return payment_filter
示例#4
0
    def create_payment_filter(self, label=None):
        from stoqlib.domain.payment.method import PaymentMethod
        methods = PaymentMethod.get_active_methods(self.store)
        items = [(_('Any'), None)]
        for method in methods:
            if method.method_name == 'multiple':
                continue
            items.append((method.description, method))

        if not label:
            label = _('Method:')
        payment_filter = ComboSearchFilter(label, items)
        payment_filter.select(None)

        return payment_filter
示例#5
0
    def _get_payment_methods(self, store):
        # PaymentMethod data
        payment_methods = []
        for pm in PaymentMethod.get_active_methods(store):
            if not pm.selectable():
                continue

            data = {'name': pm.method_name,
                    'max_installments': pm.max_installments}
            if pm.method_name == 'card':
                # FIXME: Add voucher
                data['card_types'] = [CreditCardData.TYPE_CREDIT,
                                      CreditCardData.TYPE_DEBIT]

            payment_methods.append(data)

        return payment_methods
示例#6
0
 def _get_payment_methods(self):
     methods = PaymentMethod.get_active_methods(self.store)
     values = [(i.get_description(), i.id) for i in methods]
     values.insert(0, (_("Any"), None))
     return values
示例#7
0
 def _get_method_values(self):
     methods = PaymentMethod.get_active_methods(self.store)
     values = [(i.get_description(), i.method_name) for i in methods
               if i.method_name != 'multiple']
     return values
示例#8
0
    def get(self, store):
        data = request.args

        request_is_active = data.get('ativo')

        payment_methods = store.find(PaymentMethod)
        card_payment_method = payment_methods.find(method_name='card').one()
        if request_is_active == '1':
            payment_methods = PaymentMethod.get_active_methods(store)
        if request_is_active == '0':
            payment_methods = payment_methods.find(is_active=False)

        network = _get_network_info()

        response = []
        for payment_method in payment_methods:
            # PaymentMethod 'card' will be replaced by its referring CreditProviders
            if payment_method == card_payment_method:
                continue

            res_item = {
                'ativo': payment_method.is_active,
                'id': payment_method.id,
                'codigo': _get_payment_method_code(payment_method),
                'nome': _get_payment_method_name(payment_method.method_name),
                'redeId': network['id'],
                'lojaId': None
            }
            response.append(res_item)

        select = Select((CreditCardData.card_type, CreditCardData.provider_id),
                        distinct=True)
        result = store.execute(select)
        for item in result:
            card_type = item[0]
            provider_id = item[1]
            provider = store.get(CreditProvider, provider_id)
            is_provider_active = card_payment_method and card_payment_method.is_active \
                and provider.visible

            if request_is_active == '1' and not is_provider_active:
                continue

            if request_is_active == '0' and is_provider_active:
                continue

            res_item = {
                'ativo':
                is_provider_active,
                'id':
                _get_payment_method_with_provider_code(card_type, provider),
                'codigo':
                _get_payment_method_with_provider_code(card_type, provider),
                'nome':
                _get_card_name(card_type, provider.short_name),
                'redeId':
                network['id'],
                'lojaId':
                None
            }
            response.append(res_item)

        return response
示例#9
0
 def _get_payment_methods(self):
     methods = PaymentMethod.get_active_methods(self.store)
     values = [(i.get_description(), i.id) for i in methods]
     values.insert(0, (_("Any"), None))
     return values
示例#10
0
 def _get_method_values(self):
     methods = PaymentMethod.get_active_methods(self.store)
     values = [(i.get_description(), i.method_name) for i in methods
               if i.method_name != 'multiple']
     return values