From f3967081566462e6f321420227ac93bdd68fe882 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 27 Aug 2018 11:52:42 +0200 Subject: [PATCH] finish work on custom invoice address --- .../migrations/0056_auto_20180827_1020.py | 22 +++++++++++++++++++ src/shop/models.py | 11 +++++----- src/shop/templates/order_detail.html | 12 ++++++++-- src/shop/templates/pdf/invoice.html | 4 ++-- src/shop/views.py | 2 ++ 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/shop/migrations/0056_auto_20180827_1020.py diff --git a/src/shop/migrations/0056_auto_20180827_1020.py b/src/shop/migrations/0056_auto_20180827_1020.py new file mode 100644 index 00000000..fa2aa4d0 --- /dev/null +++ b/src/shop/migrations/0056_auto_20180827_1020.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.4 on 2018-08-27 08:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0055_order_customer_address'), + ] + + operations = [ + migrations.RemoveField( + model_name='order', + name='customer_address', + ), + migrations.AddField( + model_name='order', + name='invoice_address', + field=models.TextField(blank=True, help_text='The invoice address for this order. Leave blank to use the email associated with the logged in user.'), + ), + ] diff --git a/src/shop/models.py b/src/shop/models.py index 3aad4399..ef5ea1d9 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -87,12 +87,6 @@ class Order(CreatedUpdatedModel): default=True, ) - customer_address = models.TextField( - help_text=_('The additional customer address for this order'), - blank=True - ) - - CREDIT_CARD = 'credit_card' BLOCKCHAIN = 'blockchain' BANK_TRANSFER = 'bank_transfer' @@ -134,6 +128,11 @@ class Order(CreatedUpdatedModel): blank=True, ) + invoice_address = models.TextField( + help_text=_('The invoice address for this order. Leave blank to use the email associated with the logged in user.'), + blank=True + ) + objects = OrderQuerySet.as_manager() def __str__(self): diff --git a/src/shop/templates/order_detail.html b/src/shop/templates/order_detail.html index 6a43b040..94450ef1 100644 --- a/src/shop/templates/order_detail.html +++ b/src/shop/templates/order_detail.html @@ -68,9 +68,17 @@ {% if not order.open == None %}

Comment:

-

+

{% elif order.open == None and order.comment %} -
{{ order.comment }}
+
{{ order.comment|linebreaks }}
+ {% endif %} + + {% if not order.open == None %} +

Invoice Address:

+

+ {% elif order.open == None and order.invoice_address %} +

Invoice Address:

+
{{ order.invoice_address|linebreaks }}
{% endif %} {% if order.open %} diff --git a/src/shop/templates/pdf/invoice.html b/src/shop/templates/pdf/invoice.html index f95e05a7..a6d0561b 100644 --- a/src/shop/templates/pdf/invoice.html +++ b/src/shop/templates/pdf/invoice.html @@ -14,9 +14,9 @@ -{% if invoice.order.customer_address %} +{% if invoice.order.invoice_address %}

CUSTOMER

-

{{ invoice.order.customer_address|linebreaks }}

+

{{ invoice.order.invoice_address|linebreaks }}

{% else %}

Customer: {{ invoice.order.user.email }}

{% endif %} diff --git a/src/shop/views.py b/src/shop/views.py index 0ddfa13a..52def189 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -306,6 +306,7 @@ class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderH order.payment_method = payment_method order.open = None order.customer_comment = request.POST.get('customer_comment') or '' + order.invoice_address = request.POST.get('invoice_address') or '' order.save() reverses = { @@ -337,6 +338,7 @@ class OrderDetailView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureOrderH order_product.quantity = new_quantity order_product.save() order.customer_comment = request.POST.get('customer_comment') or '' + order.invoice_address = request.POST.get('invoice_address') or '' order.save() product_remove = request.POST.get('remove_product')