From 5017f7b2e2e5fb5c5290340a0d103b24fc076210 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 2 Nov 2016 21:21:06 +0200 Subject: Added settings GSX repair status --- servo/forms/repairs.py | 41 ++++++++++++++++-------- servo/migrations/0058_auto_20161031_1129.py | 20 ++++++++++++ servo/migrations/0059_repair_status_code.py | 20 ++++++++++++ servo/migrations/0060_auto_20161101_1215.py | 20 ++++++++++++ servo/templates/orders/repair.html | 48 +++++++++++++++++------------ servo/views/order.py | 34 ++++++++++++-------- 6 files changed, 139 insertions(+), 44 deletions(-) create mode 100644 servo/migrations/0058_auto_20161031_1129.py create mode 100644 servo/migrations/0059_repair_status_code.py create mode 100644 servo/migrations/0060_auto_20161101_1215.py diff --git a/servo/forms/repairs.py b/servo/forms/repairs.py index 527d515..a13e9da 100644 --- a/servo/forms/repairs.py +++ b/servo/forms/repairs.py @@ -1,26 +1,31 @@ # -*- coding: utf-8 -*- import json +import gsxws from django import forms from django_countries import countries - from django.utils.translation import ugettext as _ from servo.models import User, Repair, Template -from servo.forms import (BaseForm, AutocompleteTextarea, DateTimePickerInput, - ChoiceField,) +from servo.forms import (BaseForm, AutocompleteTextarea, + DateTimePickerInput, ChoiceField,) class ImportForm(BaseForm): + """Import GSX repair.""" + confirmation = forms.CharField(min_length=8, max_length=15, - label=_('Confirmation')) + label=_('Confirmation'), + help_text=_('Please enter the GSX dispatch ID')) class GsxCustomerForm(BaseForm): + """Form for GSX customer data.""" + firstName = forms.CharField(max_length=100, label=_('First name')) - lastName = forms.CharField(max_length=100, label=_('Last name')) + lastName = forms.CharField(max_length=100, label=_('Last name')) emailAddress = forms.CharField(max_length=100, label=_('Email')) primaryPhone = forms.CharField(max_length=100, label=_('Phone')) addressLine1 = forms.CharField(max_length=100, label=_('Address')) @@ -35,7 +40,7 @@ class GsxComponentForm(forms.Form): components = kwargs.get('components') del(kwargs['components']) super(GsxComponentForm, self).__init__(*args, **kwargs) - + if len(components): components = json.loads(components) for k, v in components.items(): @@ -46,6 +51,18 @@ class GsxComponentForm(forms.Form): self.json_data = json.dumps(self.cleaned_data) +class StatusForm(forms.Form): + """Form for updating GSX repair status.""" + status = ChoiceField(label=_('Status'), choices=gsxws.repairs.REPAIR_STATUSES) + + def __init__(self, *args, **kwargs): + super(StatusForm, self).__init__(*args, **kwargs) + empty_choice = ('', '----',) + choices = list(gsxws.repairs.REPAIR_STATUSES) + choices.insert(0, empty_choice) + self.fields['status'].choices = choices + + class GsxRepairForm(forms.ModelForm): class Meta: model = Repair @@ -75,11 +92,11 @@ class GsxRepairForm(forms.ModelForm): choices = Template.templates() for f in ('notes', 'symptom', 'diagnosis',): self.fields[f].widget = AutocompleteTextarea(choices=choices) - + symptom_codes = self.instance.get_symptom_code_choices() self.fields['symptom_code'] = forms.ChoiceField(choices=symptom_codes, label=_('Symptom group')) - + if empty(self.instance.symptom_code): # default to the first choice self.instance.symptom_code = symptom_codes[0][0] @@ -87,7 +104,7 @@ class GsxRepairForm(forms.ModelForm): issue_codes = self.instance.get_issue_code_choices() self.fields['issue_code'] = forms.ChoiceField(choices=issue_codes, label=_('Issue code')) - + def clean(self, *args, **kwargs): cd = super(GsxRepairForm, self).clean(*args, **kwargs) if self.instance.has_serialized_parts(): @@ -98,11 +115,11 @@ class GsxRepairForm(forms.ModelForm): return cd def clean_attachment(self): - MAX_FILESIZE = 10*1024*1024 # 10MB + max_filesize = 10 * 1024 * 1024 # 10MB from django.template.defaultfilters import filesizeformat f = self.cleaned_data.get('attachment') - if f and f.size > MAX_FILESIZE: - size = filesizeformat(MAX_FILESIZE) + if f and f.size > max_filesize: + size = filesizeformat(max_filesize) error = _('Attachment should be no larger than %s') % size raise forms.ValidationError(error) diff --git a/servo/migrations/0058_auto_20161031_1129.py b/servo/migrations/0058_auto_20161031_1129.py new file mode 100644 index 0000000..84ef5e1 --- /dev/null +++ b/servo/migrations/0058_auto_20161031_1129.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.2 on 2016-10-31 09:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('servo', '0057_auto_20161014_1206'), + ] + + operations = [ + migrations.AlterField( + model_name='repair', + name='confirmation', + field=models.CharField(default=b'', editable=False, max_length=15), + ), + ] diff --git a/servo/migrations/0059_repair_status_code.py b/servo/migrations/0059_repair_status_code.py new file mode 100644 index 0000000..827aa31 --- /dev/null +++ b/servo/migrations/0059_repair_status_code.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.2 on 2016-10-31 12:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('servo', '0058_auto_20161031_1129'), + ] + + operations = [ + migrations.AddField( + model_name='repair', + name='status_code', + field=models.CharField(default=b'', editable=False, max_length=4), + ), + ] diff --git a/servo/migrations/0060_auto_20161101_1215.py b/servo/migrations/0060_auto_20161101_1215.py new file mode 100644 index 0000000..a206425 --- /dev/null +++ b/servo/migrations/0060_auto_20161101_1215.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.2 on 2016-11-01 10:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('servo', '0059_repair_status_code'), + ] + + operations = [ + migrations.AlterField( + model_name='repair', + name='status_code', + field=models.CharField(choices=[(b'AWTP', b'Awaiting Parts'), (b'AWTR', b'Parts Allocated'), (b'BEGR', b'In Repair'), (b'RFPU', b'Ready for Pickup')], default=b'', editable=False, max_length=4), + ), + ] diff --git a/servo/templates/orders/repair.html b/servo/templates/orders/repair.html index b3798db..6c42ce0 100755 --- a/servo/templates/orders/repair.html +++ b/servo/templates/orders/repair.html @@ -12,26 +12,34 @@ {% block second_column %}

{{ status }}

-
-
{% trans "Symptom" %}
-
{{ repair.symptom }}
-
{% trans "Diagnosis" %}
-
{{ repair.diagnosis }}
-
{% trans "Request Review" %}
-
{{ repair.request_review|yesno }}
-{% if repair.attachment %} -
{% trans "Attachment" %}
- {% with repair.attachment as a %} -
{{ a }}
- {% endwith %} -{% endif %} -
{% trans "Confirmation" %}
-
{{ repair.confirmation }}
-
{% trans "Reference" %}
-
{{ repair.reference }}
-
{% trans "Notes" %}
-
{{ notes|default:"-"|linebreaks }}
-
+
+ {% csrf_token %} +
+
{% trans "Symptom" %}
+
{{ repair.symptom|default:'-' }}
+
{% trans "Diagnosis" %}
+
{{ repair.diagnosis|default:'-' }}
+
{% trans "Request Review" %}
+
{{ repair.request_review|yesno }}
+ {% if repair.attachment %} +
{% trans "Attachment" %}
+ {% with repair.attachment as a %} +
{{ a }}
+ {% endwith %} + {% endif %} +
{% trans "Confirmation" %}
+
{{ repair.confirmation|default:'-' }}
+
{% trans "Reference" %}
+
{{ repair.reference|default:'-' }}
+
{% trans "Notes" %}
+
{{ notes|default:"-"|linebreaks }}
+
{% trans "Status" %}
+
{{ status_form.status }}
+
+ +
+
+

{% trans "Parts" %}

{% for part in parts %} diff --git a/servo/views/order.py b/servo/views/order.py index 2ae34a1..145e1f7 100644 --- a/servo/views/order.py +++ b/servo/views/order.py @@ -27,6 +27,7 @@ from servo.lib.utils import paginate from servo.models.order import * from servo.forms.orders import * +from servo.forms.repairs import StatusForm from servo.models import Note, User, Device, Customer from servo.models.common import (Tag, @@ -225,9 +226,7 @@ def reopen_order(request, pk): @permission_required("servo.add_order") def create(request, sn=None, device_id=None, product_id=None, note_id=None, customer_id=None): - """ - Creates a new Service Order - """ + """Create a new Service Order.""" order = Order(created_by=request.user) if customer_id is not None: @@ -303,11 +302,8 @@ def toggle_tag(request, order_id, tag_id): @permission_required("servo.change_order") def toggle_task(request, order_id, item_id): - """ - Toggles a given Check List item in this order - """ + """Toggle a given Check List item in this order.""" checklist_item = get_object_or_404(ChecklistItem, pk=item_id) - try: item = ChecklistItemValue.objects.get(order_id=order_id, item=checklist_item) @@ -323,9 +319,7 @@ def toggle_task(request, order_id, item_id): def repair(request, order_id, repair_id): - """ - Show the corresponding GSX Repair for this Service Order - """ + """Show the corresponding GSX Repair for this Service Order.""" repair = get_object_or_404(Repair, pk=repair_id) data = prepare_detail_view(request, order_id) data['repair'] = repair @@ -342,19 +336,35 @@ def repair(request, order_id, repair_id): messages.error(request, e) data['parts'] = repair.servicepart_set.all() + + if request.method == 'POST': + data['status_form'] = StatusForm(request.POST) + if data['status_form'].is_valid(): + code = data['status_form'].cleaned_data['status'] + try: + repair.set_status_code(code) + new_status = repair.get_status_code_display() + msg = _('Repair status updated to %s') % new_status + messages.success(request, msg) + except Exception as e: + messages.error(request, e) + else: + data['status_form'] = StatusForm(initial={'status': repair.status_code}) + return render(request, "orders/repair.html", data) @permission_required("servo.change_order") def complete_repair(request, order_id, repair_id): + """Mark this repair as complete in GSX.""" repair = get_object_or_404(Repair, pk=repair_id) - + if request.method == 'POST': try: repair.close(request.user) msg = _(u"Repair %s marked complete.") % repair.confirmation messages.success(request, msg) - except GsxError, e: + except GsxError as e: messages.error(request, e) return redirect(repair.order) -- cgit v1.2.3