def test_delete(self): self.clean_domain([CreditCardData]) device = self.create_card_device() # Create an operaton cost and a card payment for this device self.create_operation_cost(device, card_type=CreditCardData.TYPE_CREDIT) self.create_card_payment(device=device) # As we created above, there should be one cost and one credit card data self.assertEqual(device.get_all_costs().count(), 1) card_data = self.store.find(CreditCardData) self.assertEqual(card_data.count(), 1) # and the card_data should reference the device self.assertEqual(card_data[0].device, device) # Now delete the device CardPaymentDevice.delete(device.id, self.store) # The operation cost should be removed... self.assertEqual(self.store.find(CardOperationCost).count(), 0) # ... and the CreditCardData should still exist card_data = self.store.find(CreditCardData) self.assertEqual(card_data.count(), 1) # ... but does not contain a reference to the device anymore self.assertEqual(card_data[0].device, None)
def test_delete(self): self.clean_domain([CreditCardData]) device = self.create_card_device() # Create an operaton cost and a card payment for this device self.create_operation_cost(device, card_type=CreditCardData.TYPE_CREDIT) self.create_card_payment(device=device) # As we created above, there should be one cost and one credit card data self.assertEquals(device.get_all_costs().count(), 1) card_data = self.store.find(CreditCardData) self.assertEquals(card_data.count(), 1) # and the card_data should reference the device self.assertEquals(card_data[0].device, device) # Now delete the device CardPaymentDevice.delete(device.id, self.store) # The operation cost should be removed... self.assertEquals(self.store.find(CardOperationCost).count(), 0) # ... and the CreditCardData should still exist card_data = self.store.find(CreditCardData) self.assertEquals(card_data.count(), 1) # ... but does not contain a reference to the device anymore self.assertEquals(card_data[0].device, None)
def test_get_devices(self): self.clean_domain([CardPaymentDevice]) self.assertEquals(CardPaymentDevice.get_devices(self.store).count(), 0) device = self.create_card_device(u'Cielo') devices = list(CardPaymentDevice.get_devices(self.store)) self.assertEquals(len(devices), 1) self.assertEquals(devices[0], device)
def test_get_devices(self): self.clean_domain([CardPaymentDevice]) self.assertEqual(CardPaymentDevice.get_devices(self.store).count(), 0) device = self.create_card_device(u'Cielo') devices = list(CardPaymentDevice.get_devices(self.store)) self.assertEqual(len(devices), 1) self.assertEqual(devices[0], device)
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 _get_device_values(self): devices = CardPaymentDevice.get_devices(self.store).order_by( CardPaymentDevice.description) # This is used in a int filter, so we must use the id values = [(d.description, d.id) for d in devices] values.insert(0, (_("Any"), None)) return values
def _setup_widgets(self): """Populate device widgets and set some properties""" # Let the user edit provider_id when creating a new one self.provider_id.set_property('sensitive', not self.edit_mode) self.provider_id.set_property('editable', not self.edit_mode) devices = CardPaymentDevice.get_devices(self.store) self.default_device.prefill( api.for_combo(devices, empty=_(u"No device")))
def _setup_widgets(self): """Populate device widgets and set some properties""" # Let the user edit provider_id when creating a new one self.provider_id.set_property('sensitive', not self.edit_mode) self.provider_id.set_property('editable', not self.edit_mode) devices = CardPaymentDevice.get_devices(self.store) self.default_device.prefill(api.for_combo(devices, empty=_(u"No device")))
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=TextField(_('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=IntegerField(_('Authorization'), proxy=True, mandatory=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'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 populate(self): devices = CardPaymentDevice.get_devices(self.store) return devices.order_by(CardPaymentDevice.description)
def create_model(self, store): return CardPaymentDevice(store=store)
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_card_device(self, description=u'Cielo'): from stoqlib.domain.payment.card import CardPaymentDevice return CardPaymentDevice(store=self.store, description=description)
def _setup_widgets(self): """ Populate device widgets """ devices = CardPaymentDevice.get_devices(self.store) self.default_device.prefill( api.for_combo(devices, empty=_(u"No device")))
def _get_card_device(self, store, name): device = store.find(CardPaymentDevice, description=name).any() if not device: device = CardPaymentDevice(store=store, description=name) return device
def _setup_widgets(self): """ Populate device widgets """ devices = CardPaymentDevice.get_devices(self.store) self.default_device.prefill(api.for_combo(devices, empty=_(u"No device")))