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)
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)
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)
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)
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
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
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)
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)
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)
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) )
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) )
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()
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)
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)
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)
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
def create_model(self, store): return CreditProvider(store=store)
def process_one(self, data, fields, store): CreditProvider(open_contract_date=TransactionTimestamp(), short_name=data.provider_name, store=store)
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))
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])
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)
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())
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)
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)
def selectable(self, method): return CreditProvider.has_card_provider( method.store)
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
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])
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