Browse Source

Add PaymentMethod to admin
Fix auto-increment issue. As we import default payment method with PK (to be sure that we know the PK in data migration process in different migrations files)
we have to specify the increment value of the sequence. This is done by raw SQL commend in migration file. This in only compatible with postgreSQL.
For other backend, you have to comment the line, run the migration, then manually set the increment value of the id field of billing_payementmethod (corresponding to the backend you use)

Fabs 10 years ago
parent
commit
ec362380f7
2 changed files with 10 additions and 1 deletions
  1. 5 1
      coin/billing/admin.py
  2. 5 0
      coin/billing/migrations/0004_auto_20141101_2347.py

+ 5 - 1
coin/billing/admin.py

@@ -8,7 +8,7 @@ from django.conf.urls import url
 from django.contrib.admin.util import flatten_fieldsets
 from django.contrib.admin.util import flatten_fieldsets
 
 
 from coin.filtering_queryset import LimitedAdminInlineMixin
 from coin.filtering_queryset import LimitedAdminInlineMixin
-from coin.billing.models import Invoice, InvoiceDetail, Payment
+from coin.billing.models import Invoice, InvoiceDetail, Payment, PaymentMethod
 from coin.billing.utils import get_invoice_from_id_or_number
 from coin.billing.utils import get_invoice_from_id_or_number
 from django.core.urlresolvers import reverse
 from django.core.urlresolvers import reverse
 import autocomplete_light
 import autocomplete_light
@@ -158,4 +158,8 @@ class InvoiceAdmin(admin.ModelAdmin):
                                             args=(id,)))
                                             args=(id,)))
 
 
 
 
+class PaymentMethodAdmin(admin.ModelAdmin):
+    list_display = ('name',)
+
 admin.site.register(Invoice, InvoiceAdmin)
 admin.site.register(Invoice, InvoiceAdmin)
+admin.site.register(PaymentMethod, PaymentMethodAdmin)

+ 5 - 0
coin/billing/migrations/0004_auto_20141101_2347.py

@@ -50,4 +50,9 @@ class Migration(migrations.Migration):
 
 
     operations = [
     operations = [
         migrations.RunPython(forward, backward),
         migrations.RunPython(forward, backward),
+        # As we import method with primary key, it is not auto incremented
+        # so we have to force increment sequence.
+        # ONLY FOR POSTGRESQL, will FAIL with other db backend
+        # If so, comment this line and do it manually with your backend specificities
+        migrations.RunSQL('alter sequence billing_paymentmethod_id_seq restart with 5;', 'SELECT 1')
     ]
     ]