Esempio n. 1
0
def _ensure_card_providers():
    """ Creates a list of default card providers """
    log.info("Creating Card Providers")
    from stoqlib.domain.payment.card import CreditProvider, CardPaymentDevice

    providers = {
        u'VISA': u'VISA',
        u'MASTER': u'MASTERCARD',
        u'AMEX': u'AMERICAN EXPRESS'
    }
    store = new_store()
    for short_name, provider_id in providers.items():
        provider = CreditProvider.get_provider_by_provider_id(
            provider_id, store)
        if not provider.is_empty():
            continue

        CreditProvider(short_name=short_name,
                       provider_id=providers[short_name],
                       open_contract_date=TransactionTimestamp(),
                       store=store)
    devices = store.find(CardPaymentDevice)
    if devices.is_empty():
        CardPaymentDevice(store=store, description=_(u'Default'))
    store.commit(close=True)
Esempio n. 2
0
    def test_get_providers(self):
        self.clean_domain([CreditProvider])

        # Initialy no providers are present
        self.assertEquals(CreditProvider.get_card_providers(self.store).count(), 0)

        # Create one
        provider = self.create_credit_provider()

        # It should be fetched from the database
        providers = CreditProvider.get_card_providers(self.store)
        self.assertEquals(providers.count(), 1)
        self.assertEquals(providers[0], provider)
Esempio n. 3
0
    def test_get_providers(self):
        self.clean_domain([CreditProvider])

        # Initialy no providers are present
        self.assertEqual(CreditProvider.get_card_providers(self.store).count(), 0)

        # Create one
        provider = self.create_credit_provider()

        # It should be fetched from the database
        providers = CreditProvider.get_card_providers(self.store)
        self.assertEqual(providers.count(), 1)
        self.assertEqual(providers[0], provider)
Esempio n. 4
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(self.store).order_by(
         CreditProvider.short_name).first()
     real_model = CardOperationCost(provider=provider,
                                    device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)
Esempio n. 5
0
 def _get_provider(self, store, name):
     name = name.strip()
     name = self.PROVIDER_MAP.get(name, name)
     provider = store.find(CreditProvider, provider_id=name).one()
     if not provider:
         provider = CreditProvider(store=store, short_name=name, provider_id=name)
     return provider
Esempio n. 6
0
    def create_provider_filter(self, label=None):
        from stoqlib.domain.payment.card import CreditProvider
        providers = CreditProvider.get_card_providers(self.store)
        items = [(p.short_name, p) for p in providers]
        items.insert(0, (_("Any"), None))

        if not label:
            label = _('Provider:')
        provider_filter = ComboSearchFilter(label, items)

        return provider_filter
Esempio n. 7
0
    def create_provider_filter(self, label=None):
        from stoqlib.domain.payment.card import CreditProvider
        providers = CreditProvider.get_card_providers(self.store)
        items = [(p.short_name, p) for p in providers]
        items.insert(0, (_("Any"), None))

        if not label:
            label = _('Provider:')
        provider_filter = ComboSearchFilter(label, items)

        return provider_filter
Esempio n. 8
0
def _ensure_card_providers():
    """ Creates a list of default card providers """
    log.info("Creating Card Providers")
    from stoqlib.domain.payment.card import CreditProvider

    providers = [
        u'VISANET', u'REDECARD', u'AMEX', u'HIPERCARD', u'BANRISUL', u'PAGGO',
        u'CREDISHOP', u'CERTIF'
    ]

    store = new_store()
    for name in providers:
        provider = CreditProvider.get_provider_by_provider_id(name, store)
        if not provider.is_empty():
            continue

        CreditProvider(short_name=name,
                       provider_id=name,
                       open_contract_date=TransactionTimestamp(),
                       store=store)
    store.commit(close=True)
Esempio n. 9
0
    def create_model(self, store):
        if store.find(CardPaymentDevice).is_empty():
            raise ValueError('You must have card devices registered '
                             'before start doing sales')

        providers = CreditProvider.get_card_providers(
            self.method.store)
        if providers.count() == 0:
            raise ValueError('You must have credit providers information '
                             'stored in the database before start doing '
                             'sales')
        return _TemporaryCreditProviderGroupData(provider=None)
Esempio n. 10
0
    def _setup_widgets(self):
        devices = CardPaymentDevice.get_devices(self.method.store)
        self.card_device.prefill(api.for_combo(devices))

        providers = CreditProvider.get_card_providers(
            self.method.store)
        self.credit_provider.prefill(api.for_combo(providers))

        self._radio_group = None

        for ptype, name in CreditCardData.types.items():
            self._add_card_type(name, ptype)
Esempio n. 11
0
    def fields(self):
        device_values = api.for_combo(
            CardPaymentDevice.get_devices(self.store))
        provider_values = api.for_combo(
            CreditProvider.get_card_providers(self.store))

        return collections.OrderedDict(
            device=ChoiceField(_('Device'), proxy=True, mandatory=True,
                               values=device_values),
            provider=ChoiceField(_('Provider'), proxy=True, mandatory=True,
                                 values=provider_values),
            auth=IntegerField(_('Authorization'), proxy=True, mandatory=True)
        )
Esempio n. 12
0
    def fields(self):
        device_values = api.for_combo(
            CardPaymentDevice.get_devices(self.store))
        provider_values = api.for_combo(
            CreditProvider.get_card_providers(self.store))

        return collections.OrderedDict(
            device=ChoiceField(_('Device'), proxy=True, mandatory=True,
                               values=device_values),
            provider=ChoiceField(_('Provider'), proxy=True, mandatory=True,
                                 values=provider_values),
            auth=TextField(_('Authorization'), proxy=True, mandatory=True)
        )
Esempio n. 13
0
    def _setup_widgets(self):
        # Set a default provider, otherwise, if the user does not change the
        # combo, the provider may not be set (bug in kiwi)
        providers = CreditProvider.get_card_providers(self.store)
        self.provider.prefill(api.for_combo(providers))

        types = [(value, key) for key, value in CreditCardData.types.items()]
        self.card_type.prefill(types)

        # Set values to the ones of the model
        self.installment_start.set_value(self.model.installment_start)
        self.installment_end.set_value(self.model.installment_end)

        self.set_installment_limits()
Esempio n. 14
0
    def _setup_widgets(self):
        # Set a default provider, otherwise, if the user does not change the
        # combo, the provider may not be set (bug in kiwi)
        providers = CreditProvider.get_card_providers(self.store)
        self.provider.prefill(api.for_combo(providers))

        types = [(value, key) for key, value in CreditCardData.types.items()]
        self.card_type.prefill(types)

        # Set values to the ones of the model
        self.installment_start.set_value(self.model.installment_start)
        self.installment_end.set_value(self.model.installment_end)

        self.set_installment_limits()
Esempio n. 15
0
File: admin.py Progetto: stoq/stoq
def _ensure_card_providers():
    """ Creates a list of default card providers """
    log.info("Creating Card Providers")
    from stoqlib.domain.payment.card import CreditProvider, CardPaymentDevice

    providers = [u"VISANET", u"REDECARD", u"AMEX", u"HIPERCARD", u"BANRISUL", u"PAGGO", u"CREDISHOP", u"CERTIF"]

    store = new_store()
    for name in providers:
        provider = CreditProvider.get_provider_by_provider_id(name, store)
        if not provider.is_empty():
            continue

        CreditProvider(short_name=name, provider_id=name, open_contract_date=TransactionTimestamp(), store=store)
    devices = store.find(CardPaymentDevice)
    if devices.is_empty():
        CardPaymentDevice(store=store, description=_(u"Default"))
    store.commit(close=True)
Esempio n. 16
0
File: admin.py Progetto: romaia/stoq
def _ensure_card_providers():
    """ Creates a list of default card providers """
    log.info("Creating Card Providers")
    from stoqlib.domain.payment.card import CreditProvider

    providers = [u'VISANET', u'REDECARD', u'AMEX', u'HIPERCARD',
                 u'BANRISUL', u'PAGGO', u'CREDISHOP', u'CERTIF']

    store = new_store()
    for name in providers:
        provider = CreditProvider.get_provider_by_provider_id(name, store)
        if not provider.is_empty():
            continue

        CreditProvider(short_name=name,
                       provider_id=name,
                       open_contract_date=TransactionTimestamp(),
                       store=store)
    store.commit(close=True)
Esempio n. 17
0
def _ensure_card_providers():
    """ Creates a list of default card providers """
    log.info("Creating Card Providers")
    from stoqlib.domain.payment.card import CreditProvider, CardPaymentDevice

    providers = {u'VISA': u'VISA',
                 u'MASTER': u'MASTER',
                 u'AMEX': u'AMEX'}
    store = new_store()
    for short_name, provider_id in providers.items():
        provider = CreditProvider.get_provider_by_provider_id(provider_id, store)
        if not provider.is_empty():
            continue

        CreditProvider(short_name=short_name,
                       provider_id=providers[short_name],
                       open_contract_date=TransactionTimestamp(),
                       store=store)
    devices = store.find(CardPaymentDevice)
    if devices.is_empty():
        CardPaymentDevice(store=store, description=_(u'Default'))
    store.commit(close=True)
Esempio n. 18
0
    def next_step(self):
        if not self.wizard.need_create_payment():
            return

        selected_method = self.get_selected_method()
        if selected_method.method_name == u'money':
            if not self.cash_change_slave.can_finish():
                warning(_(u"Invalid value, please verify if it was "
                          "properly typed."))
                self.cash_change_slave.received_value.select_region(
                    0, len(self.cash_change_slave.received_value.get_text()))
                self.cash_change_slave.received_value.grab_focus()
                return self

            # We have to modify the payment, so the fiscal printer can
            # calculate and print the payback, if necessary.
            payment = self.setup_cash_payment()
            total = self.cash_change_slave.get_received_value()
            payment.base_value = total

            # Return None here means call wizard.finish, which is exactly
            # what we need
            return None
        elif selected_method.method_name == u'store_credit':
            client = self.model.client
            total = self.wizard.get_total_amount()

            assert client.can_purchase(selected_method, total)

            step_class = PaymentMethodStep
        elif selected_method.method_name == 'card':
            providers = CreditProvider.get_card_providers(self.store)
            if providers.is_empty():
                warning(_("You need active credit providers to use the "
                          "card payment method."))
                return self
            step_class = PaymentMethodStep
        else:
            step_class = PaymentMethodStep

        retval = CreatePaymentEvent.emit(selected_method, self.model,
                                         self.store)

        # None means no one catched this event
        if retval is None or retval == CreatePaymentStatus.UNHANDLED:
            # FIXME: We cannot send outstanding_value to multiple editor
            # since if we have a trade going on, it will be calculated wrong
            if selected_method.method_name == 'multiple':
                outstanding_value = None
            else:
                outstanding_value = self.wizard.get_total_to_pay()

            return step_class(self.wizard, self, self.store, self.model,
                              selected_method,
                              outstanding_value=outstanding_value)

        # finish the wizard
        if retval == CreatePaymentStatus.SUCCESS:
            return None

        # returning self to stay on this step
        return self
Esempio n. 19
0
 def create_model(self, store):
     return CreditProvider(store=store)
Esempio n. 20
0
 def process_one(self, data, fields, store):
     CreditProvider(open_contract_date=TransactionTimestamp(),
                    short_name=data.provider_name,
                    store=store)
Esempio n. 21
0
    def test_has_providers(self):
        self.clean_domain([CreditProvider])
        self.assertFalse(CreditProvider.has_card_provider(self.store))

        self.create_credit_provider()
        self.assertTrue(CreditProvider.has_card_provider(self.store))
Esempio n. 22
0
    def test_get_provider_by_id(self):
        provider = self.create_credit_provider()
        provider.provider_id = u'foo'

        obj = CreditProvider.get_provider_by_provider_id(u'foo', self.store)
        self.assertEquals(provider, obj[0])
Esempio n. 23
0
 def __init__(self, store, model, visual_mode=None):
     self.fields['device'].values = api.for_combo(
         CardPaymentDevice.get_devices(store))
     self.fields['provider'].values = api.for_combo(
         CreditProvider.get_card_providers(store))
     BaseEditor.__init__(self, store, model)
Esempio n. 24
0
 def create_credit_provider(self, short_name=u'Velec'):
     from stoqlib.domain.payment.card import CreditProvider
     return CreditProvider(store=self.store,
                           short_name=short_name,
                           open_contract_date=localdate(2006, 01,
                                                        01).date())
Esempio n. 25
0
    def test_has_providers(self):
        self.clean_domain([CreditProvider])
        self.assertFalse(CreditProvider.has_card_provider(self.store))

        self.create_credit_provider()
        self.assertTrue(CreditProvider.has_card_provider(self.store))
Esempio n. 26
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(store).any()
     real_model = CardOperationCost(provider=provider, device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)
Esempio n. 27
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(
         self.store).order_by(CreditProvider.short_name).first()
     real_model = CardOperationCost(provider=provider, device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)
Esempio n. 28
0
 def __init__(self, store, model, visual_mode=None):
     self.fields['device'].values = api.for_combo(
         CardPaymentDevice.get_devices(store))
     self.fields['provider'].values = api.for_combo(
         CreditProvider.get_card_providers(store))
     BaseEditor.__init__(self, store, model)
Esempio n. 29
0
 def selectable(self, method):
     return CreditProvider.has_card_provider(
         method.store)
Esempio n. 30
0
    def _get_card_providers(self, store):
        providers = []
        for i in CreditProvider.get_card_providers(store):
            providers.append({'short_name': i.short_name, 'provider_id': i.provider_id})

        return providers
Esempio n. 31
0
    def test_get_provider_by_id(self):
        provider = self.create_credit_provider()
        provider.provider_id = u'foo'

        obj = CreditProvider.get_provider_by_provider_id(u'foo', self.store)
        self.assertEqual(provider, obj[0])
Esempio n. 32
0
    def next_step(self):
        if not self.wizard.need_create_payment():
            if self.cash_change_slave.credit_checkbutton.get_active():
                self._create_change_payment()
            return

        selected_method = self.get_selected_method()
        if selected_method.method_name == u'money':
            if not self.cash_change_slave.can_finish():
                warning(
                    _(u"Invalid value, please verify if it was "
                      "properly typed."))
                self.cash_change_slave.received_value.select_region(
                    0, len(self.cash_change_slave.received_value.get_text()))
                self.cash_change_slave.received_value.grab_focus()
                return self

            # We have to modify the payment, so the fiscal printer can
            # calculate and print the payback, if necessary.
            payment = self.setup_cash_payment()
            if payment is None:
                return

            total = self.cash_change_slave.get_received_value()
            payment.base_value = total

            # Return None here means call wizard.finish, which is exactly
            # what we need
            return None
        elif selected_method.method_name == u'credit':
            client = self.model.client
            total = self.wizard.get_total_to_pay()

            assert client.can_purchase(selected_method, total)

            try:
                payment = selected_method.create_payment(
                    Payment.TYPE_IN, self.model.group, self.model.branch,
                    total)
            except PaymentMethodError as err:
                warning(str(err))
                return self

            # Return None here means call wizard.finish, which is exactly
            # what we need
            return None
        elif selected_method.method_name == u'store_credit':
            client = self.model.client
            total = self.wizard.get_total_to_pay()

            assert client.can_purchase(selected_method, total)

            step_class = PaymentMethodStep
        elif selected_method.method_name == 'card':
            providers = CreditProvider.get_card_providers(self.store)
            if providers.is_empty():
                warning(
                    _("You need active credit providers to use the "
                      "card payment method."))
                return self
            step_class = PaymentMethodStep
        else:
            step_class = PaymentMethodStep

        retval = CreatePaymentEvent.emit(selected_method, self.model,
                                         self.store)

        # None means no one catched this event
        if retval is None or retval == CreatePaymentStatus.UNHANDLED:
            # FIXME: We cannot send outstanding_value to multiple editor
            # since if we have a trade going on, it will be calculated wrong
            if selected_method.method_name == 'multiple':
                outstanding_value = None
            else:
                outstanding_value = self.wizard.get_total_to_pay()

            manager = get_plugin_manager()
            return step_class(self.wizard,
                              self,
                              self.store,
                              self.model,
                              selected_method,
                              outstanding_value=outstanding_value,
                              finish_on_total=manager.is_active('tef'))

        # finish the wizard
        if retval == CreatePaymentStatus.SUCCESS:
            return None

        # returning self to stay on this step
        return self
Esempio n. 33
0
 def create_model(self, store):
     provider = CreditProvider.get_card_providers(store).any()
     real_model = CardOperationCost(provider=provider,
                                    device=self.device,
                                    store=self.store)
     return _TemporaryOperationCost(real_model)