Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix required attribute on input fields & add sandbox site #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
*.egg-info
# Packaging
*.pyc
.idea/
__pycache__
*.egg-info
/dist/
/build/
/node_modules/

# Vagrant
.vagrant

# Temporary/OS files
*.swp
*.swo
*.*~
.~lock.*
*.DS_Store
.python-version

# IDE files
.project
.pydevproject
.settings
.idea
.vscode

# Docs
/docs/build/*
*.pdf
TODO
venv

# Test files
.coverage
.coverage\.*
.noseids
coverage.xml
violations.txt
nosetests.xml
/.cache/
/.pytest_cache/
/htmlcov/*
/.tox/*

# Sandbox content
settings_local.py
/sandbox/*.sqlite
/sandbox/assets/
/sandbox/public/
/sandbox/whoosh_index/
/sandbox/logs/
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
install:
pip install django-oscar
pip install -r requirements.txt
python setup.py develop

upgrade:
pip install -U django-oscar
pip install -U -r requirements.txt
python setup.py develop --upgrade

sandbox: install
-rm -f sandbox/db.sqlite
sandbox/manage.py migrate --noinput
sandbox/manage.py loaddata sandbox/fixtures/*.json
sandbox/manage.py oscar_import_catalogue sandbox/fixtures/catalogue.csv
3 changes: 1 addition & 2 deletions cashondelivery/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ class CashOnDeliveryTransactionAdmin(admin.ModelAdmin):
'order_number',
'method',
'amount',
'currency',
'reference',
'confirmed',
'date_confirmed',
'date_created'
]

Expand Down
20 changes: 12 additions & 8 deletions cashondelivery/forms.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from django import forms
from django.utils.translation import ugettext_lazy as _

from oscar.apps.payment import forms as payment_forms
from oscar.core.loading import get_class
from oscar.core.loading import get_classes
from oscar.core.loading import get_model

from oscar.core.loading import get_class, get_model

OscarBillingAddressForm = get_class('payment.forms', 'BillingAddressForm')
Country = get_model('address', 'Country')
BillingAddress = get_model("order", "BillingAddress")


class BillingAddressForm(payment_forms.BillingAddressForm):

class BillingAddressForm(OscarBillingAddressForm):
"""
Extended version of the core billing address form that adds a field so
customers can choose to re-use their shipping address.
Expand All @@ -29,7 +25,7 @@ class BillingAddressForm(payment_forms.BillingAddressForm):
label=_('Same as shipping')
)

class Meta(payment_forms.BillingAddressForm):
class Meta(OscarBillingAddressForm):
model = BillingAddress
exclude = ('search_text', 'first_name', 'last_name')

Expand All @@ -51,6 +47,14 @@ def __init__(self, shipping_address, data=None, *args, **kwargs):
(self.NEW_ADDRESS, _('Enter a new address')),)
self.fields['same_as_shipping'].initial = self.NEW_ADDRESS

# We set the required attribute for fields with javascript in the frontend
# in payment_details.html template.
if shipping_address and data is None:
for field in self.fields:
if field != 'same_as_shipping':
self.fields[field].required = False


# If using same address as shipping, we don't need require any of the
# required billing address fields.
if data and data.get('same_as_shipping', None) == self.SAME_AS_SHIPPING:
Expand Down
26 changes: 26 additions & 0 deletions cashondelivery/migrations/0003_auto_20181210_2046.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.1.4 on 2018-12-10 20:46

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('cashondelivery', '0002_auto_20160818_1642'),
]

operations = [
migrations.AddField(
model_name='cashondeliverytransaction',
name='cash_collector',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='txns', to=settings.AUTH_USER_MODEL, verbose_name='Cash Collector'),
),
migrations.AddField(
model_name='cashondeliverytransaction',
name='txn_note',
field=models.TextField(blank=True, null=True, verbose_name='Transaction Note'),
),
]
9 changes: 9 additions & 0 deletions cashondelivery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

from oscar.core.compat import AUTH_USER_MODEL

def _make_uuid():
return str(uuid.uuid4())
Expand All @@ -20,6 +21,14 @@ class CashOnDeliveryTransaction(models.Model):
confirmed = models.BooleanField(_('Confirmed'), default=False)
date_confirmed = models.DateTimeField(_('Date Confirmed'), auto_now=True)

# Cash can be collected with non staff user so we don't
# always have a user ID.
cash_collector = models.ForeignKey(
AUTH_USER_MODEL, verbose_name=_("Cash Collector"), null=True,
blank=True, on_delete=models.PROTECT, related_name='txns', )

txn_note = models.TextField(_("Transaction Note"), null=True, blank=True)

class Meta:
ordering = ('-date_created',)
app_label = 'cashondelivery'
Expand Down
35 changes: 26 additions & 9 deletions cashondelivery/templates/cashondelivery/payment_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% block shipping_method %}{% endblock %}

{% block payment_method %}

<p>{% trans "You've chosen to pay cash on delivery." %}</p>

<div class="row-fluid">
Expand Down Expand Up @@ -52,22 +52,39 @@
{% include 'partials/form_field.html' with field=billing_address_form.postcode %}
{% include 'partials/form_field.html' with field=billing_address_form.country %}
</div>

<button type="submit" class="pull-right btn btn-large btn-primary">{% trans "Continue" %}</button>
</form>
</div>

</div>
</div>

{% endblock payment_method %}


{% block onbodyload %}
{# Toggle visibility of the billing address form #}
if ($("input[name='same_as_shipping']")[1].checked){
$("#billing_address_form").show();
}
{# Toggle visibility of the billing address form & set required on fields #}
$("input[name='same_as_shipping']").change(function(){
$("#billing_address_form").toggle();

if($("input[name='same_as_shipping']")[1].checked)
{
$("#id_line1").prop('required', true);
$("label[for='id_line1']").prop('class','control-label required');
$("#id_line4").prop('required', true);
$("label[for='id_line4']").prop('class','control-label required');
$("#id_postcode").prop('required', true);
$("label[for='id_postcode']").prop('class','control-label required');
$("#billing_address_form").show();
}

else

{
$("#id_line1").prop('required', false);
$("#id_line4").prop('required', false);
$("#id_postcode").prop('required', false);
$("#billing_address_form").toggle();
}

});
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<tr><th>{% trans "Currency" %}</th><td>{{ txn.currency }}</td></tr>
<tr><th>{% trans "Confirmed" %}</th><td>{{ txn.confirmed }}</td></tr>
<tr><th>{% trans "Date confirmed" %}</th><td>{% if txn.confirmed %}{{ txn.date_confirmed }}{% else %} - {% endif %}</td></tr>
<tr><th>{% trans "Cash collector" %}</th><td>{% if txn.confirmed %}{{ txn.cash_collector }}{% else %} - {% endif %}</td></tr>
<tr><th>{% trans "Transaction note" %}</th><td>{{ txn.txn_note }}</td></tr>
</tbody>
</table>
{% endblock dashboard_content %}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<thead>
<tr>
<th>{% trans "Reference hash" %}</th>
<th>{% trans "Method" %}</th>
<th>{% trans "Order Number" %}</th>
<th>{% trans "Amount" %}</th>
<th>{% trans "Confirmed" %}</th>
<th>{% trans "Date Confirmed" %}</th>
<th>{% trans "Cash Collector" %}</th>
<th>{% trans "Date" %}</th>
</tr>
</thead>
Expand All @@ -43,13 +43,13 @@
<td>
<a href="{% url 'cashondelivery-transaction-detail' txn.id %}">{{ txn.reference|default:"-" }}</a>
</td>
<td>{{ txn.method }}</td>
<td>
<a href="{% url 'dashboard:order-detail' number=txn.order_number %}">{{ txn.order_number|default:"-" }}</a>
</td>
<td>{{ txn.amount|currency|default:"-" }} {{ txn.currency }}</td>
<td>{{ txn.confirmed }}</td>
<td>{% if txn.confirmed %}{{ txn.date_confirmed }}{% else %} - {% endif %}</td>
<td>{{ txn.cash_collector }}</td>
<td>{{ txn.date_created }}</td>
</tr>
{% endfor %}
Expand Down
10 changes: 7 additions & 3 deletions cashondelivery/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django import http
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _

from oscar.core.loading import (
get_model,
get_model,
get_class
)

Expand Down Expand Up @@ -68,12 +68,16 @@ def handle_payment_details_submission(self, request):
request, billing_address_form=address_form)

def handle_payment(self, order_number, total, **kwargs):
reference = gateway.create_transaction(order_number,total)

source_type, is_created = SourceType.objects.get_or_create(
name='Cash on Delivery')
source = Source(
source_type=source_type,
currency=total.currency,
amount_allocated=total.incl_tax,
amount_debited=total.incl_tax
amount_debited=total.incl_tax,
reference=reference
)
self.add_payment_source(source)
self.add_payment_event('Issued', total.incl_tax, reference=reference)
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Testing
mock==2.0.0
coverage==4.4.2
django-webtest==1.9.2
tox==2.9.1
detox==0.11
pytest-django==3.1.2
pytest-cov==2.5.1

# Development
django-extensions==1.9.8
django-debug-toolbar==1.9.1
flake8==3.5.0
Empty file added sandbox/__init__.py
Empty file.
Empty file added sandbox/apps/__init__.py
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions sandbox/apps/checkout/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# your checkout/app.py
from oscar.apps.checkout import app
from cashondelivery.views import PaymentDetailsView


class CheckoutApplication(app.CheckoutApplication):
payment_details_view = PaymentDetailsView


application = CheckoutApplication()
Empty file added sandbox/apps/checkout/models.py
Empty file.
Empty file.
Loading