Commit 0a1daccb authored by Patrick Kimber's avatar Patrick Kimber

Payment processor no longer needs a slug (see 'MagentoSitePaymentMethod' in the 'magento' app)

parent 11b6f23e
Pipeline #82077049 passed with stage
in 5 minutes and 36 seconds
# Generated by Django 2.2.4 on 2019-09-12 16:24
# Generated by Django 2.2.4 on 2019-09-12 17:42
from django.db import migrations, models
import django.db.models.deletion
......@@ -29,6 +29,14 @@ class Migration(migrations.Migration):
"verbose_name_plural": "Invoice Issue Lines",
},
),
migrations.AlterModelOptions(
name="paymentprocessor",
options={
"ordering": ("description",),
"verbose_name": "Payment Processor",
},
),
migrations.RemoveField(model_name="paymentprocessor", name="slug"),
migrations.AlterField(
model_name="invoiceissue",
name="invoice",
......@@ -37,6 +45,11 @@ class Migration(migrations.Migration):
to="invoice.Invoice",
),
),
migrations.AlterField(
model_name="paymentprocessor",
name="description",
field=models.CharField(max_length=100, unique=True),
),
migrations.AlterUniqueTogether(
name="invoiceissue", unique_together=set()
),
......
......@@ -274,35 +274,25 @@ class InvoiceError(Exception):
class PaymentProcessorManager(models.Manager):
def _create_payment_processor(self, slug, description):
x = self.model(slug=slug, description=description)
def create_payment_processor(self, description):
x = self.model(description=description)
x.save()
return x
def init_payment_processor(self, slug, description):
try:
x = self.model.objects.get(slug=slug)
x.description = description
x.save()
except self.model.DoesNotExist:
x = self._create_payment_processor(slug, description)
return x
class PaymentProcessor(TimeStampedModel):
slug = models.SlugField(max_length=30, unique=True)
description = models.CharField(max_length=100)
description = models.CharField(max_length=100, unique=True)
deleted = models.BooleanField(default=False)
objects = PaymentProcessorManager()
class Meta:
ordering = ("description",)
verbose_name = "Payment Processor"
def __str__(self):
if self.description:
return "{} - {}".format(self.slug, self.description)
else:
return self.slug
return "{}{}".format(
self.description, " (deleted)" if self.deleted else ""
)
class InvoiceManager(TimedCreateModifyDeleteVersionModelManager):
......@@ -808,7 +798,7 @@ class Batch(TimeStampedModel):
self.batch_date.strftime("%d/%m/%Y"),
self.currency.slug,
exchange,
self.payment_processor.slug,
self.payment_processor.description,
)
)
......
......@@ -29,7 +29,7 @@
Payment Processor
</td>
<td>
{{ batch.payment_processor.slug }}
{{ batch.payment_processor.description }}
</td>
</tr>
{% if batch_net %}
......
......@@ -36,8 +36,8 @@ class PaymentProcessorFactory(factory.django.DjangoModelFactory):
model = PaymentProcessor
@factory.sequence
def slug(n):
return "slug_{}".format(n)
def description(n):
return "description_{}".format(n)
class BatchFactory(factory.django.DjangoModelFactory):
......
......@@ -26,7 +26,7 @@ def test_batch_number():
def test_create_batch():
batch_date = date(2018, 2, 22)
currency = Currency.objects.get(slug="GBP")
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory()
invoice_1 = InvoiceFactory(
invoice_date=batch_date,
currency=currency,
......@@ -52,7 +52,7 @@ def test_create_batch_exchange_rate():
batch_date = date(2018, 2, 22)
currency = Currency.objects.get(slug="EUR")
exchange_rate = Decimal("0.987")
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory()
InvoiceFactory(
invoice_date=batch_date,
currency=currency,
......@@ -76,7 +76,7 @@ def test_create_batch_exchange_rate():
def test_create_batch_no_invoices():
batch_date = date(2018, 2, 22)
currency = Currency.objects.get(slug="GBP")
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory()
batch = Batch.objects.create_batch(
batch_date, currency, None, payment_processor
)
......@@ -89,7 +89,7 @@ def test_duplicate():
batch_date = date(2018, 2, 22)
currency = Currency.objects.get(slug="GBP")
exchange_rate = Decimal()
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory()
BatchFactory(
batch_date=batch_date,
currency=currency,
......@@ -101,7 +101,7 @@ def test_duplicate():
batch_date=batch_date,
currency=currency,
exchange_rate=exchange_rate,
payment_processor=PaymentProcessorFactory(slug="stripe"),
payment_processor=PaymentProcessorFactory(),
)
with pytest.raises(IntegrityError):
BatchFactory(
......@@ -197,7 +197,7 @@ def test_net_and_vat():
@pytest.mark.django_db
def test_str():
currency = Currency.objects.get(slug="GBP")
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory(description="PayPal")
batch = BatchFactory(
batch_date=date(2018, 2, 22),
currency=currency,
......@@ -205,14 +205,14 @@ def test_str():
)
assert (
"Invoice batch {} for 22/02/2018 currency "
"'GBP' payment processor 'paypal'".format(batch.pk)
"'GBP' payment processor 'PayPal'".format(batch.pk)
) == str(batch)
@pytest.mark.django_db
def test_str_exchange_rate():
currency = Currency.objects.get(slug="EUR")
payment_processor = PaymentProcessorFactory(slug="paypal")
payment_processor = PaymentProcessorFactory(description="Stripe")
batch = BatchFactory(
batch_date=date(2018, 2, 22),
currency=currency,
......@@ -221,7 +221,7 @@ def test_str_exchange_rate():
)
assert (
"Invoice batch {} for 22/02/2018 currency 'EUR' (0.834) "
"payment processor 'paypal'".format(batch.pk)
"payment processor 'Stripe'".format(batch.pk)
) == str(batch)
......
......@@ -6,34 +6,26 @@ from .factories import PaymentProcessorFactory
@pytest.mark.django_db
def test_init_payment_processor():
PaymentProcessorFactory(slug="ABC", description="Apple")
assert 1 == PaymentProcessor.objects.count()
PaymentProcessor.objects.init_payment_processor("ABC", "Orange")
assert 1 == PaymentProcessor.objects.count()
payment_processor = PaymentProcessor.objects.first()
assert "ABC" == payment_processor.slug
assert "Orange" == payment_processor.description
def test_create_payment_processor():
PaymentProcessor.objects.create_payment_processor("Orange")
PaymentProcessor.objects.create_payment_processor("Apple")
assert ["Apple", "Orange"] == [
x.description for x in PaymentProcessor.objects.all()
]
@pytest.mark.django_db
def test_init_payment_processor_create():
assert 0 == PaymentProcessor.objects.count()
payment_processor = PaymentProcessor.objects.init_payment_processor(
"ABC", "Apple"
)
assert 1 == PaymentProcessor.objects.count()
assert "ABC" == payment_processor.slug
assert "Apple" == payment_processor.description
def test_str():
assert "Apple" == str(PaymentProcessorFactory(description="Apple"))
@pytest.mark.django_db
def test_str():
assert "ABC - Apple" == str(
PaymentProcessorFactory(slug="ABC", description="Apple")
def test_str_deleted():
assert "Apple (deleted)" == str(
PaymentProcessorFactory(description="Apple", deleted=True)
)
@pytest.mark.django_db
def test_str_no_description():
assert "ABC" == str(PaymentProcessorFactory(slug="ABC", description=""))
assert "" == str(PaymentProcessorFactory(description=""))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment