aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-08-15 16:26:50 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-08-15 16:26:50 +0300
commit06fc5a6b43744799060ce8fdaa78a2ecb034802c (patch)
tree1789000e325834245964fbaa452f634694203887
parentf38838154defe15e0b2d043c19f6985484993423 (diff)
downloadServo-06fc5a6b43744799060ce8fdaa78a2ecb034802c.tar.gz
Servo-06fc5a6b43744799060ce8fdaa78a2ecb034802c.tar.bz2
Servo-06fc5a6b43744799060ce8fdaa78a2ecb034802c.zip
Added symptom/issue fields
-rw-r--r--servo/forms/repairs.py19
-rw-r--r--servo/migrations/0025_auto_20150815_0921.py34
-rw-r--r--servo/models/repair.py24
-rwxr-xr-xservo/templates/orders/gsx_repair_form.html20
-rw-r--r--servo/templates/repairs/issue_code_menu.html3
-rw-r--r--servo/views/gsx.py18
6 files changed, 109 insertions, 9 deletions
diff --git a/servo/forms/repairs.py b/servo/forms/repairs.py
index 8459e52..b821ea9 100644
--- a/servo/forms/repairs.py
+++ b/servo/forms/repairs.py
@@ -67,12 +67,13 @@ class GsxRepairForm(forms.ModelForm):
model = Repair
exclude = []
widgets = {
- 'device' : forms.HiddenInput(),
+ 'device': forms.HiddenInput(),
'parts': forms.CheckboxSelectMultiple(),
'unit_received_at': DateTimePickerInput(attrs={'readonly': 'readonly'})
}
def __init__(self, *args, **kwargs):
+ from servo.lib.utils import empty
super(GsxRepairForm, self).__init__(*args, **kwargs)
repair = kwargs['instance']
techs = User.techies.filter(location=repair.order.location)
@@ -84,13 +85,25 @@ class GsxRepairForm(forms.ModelForm):
self.fields['parts'].initial = repair.order.get_parts()
if not repair.can_mark_complete:
- del self.fields['mark_complete']
- del self.fields['replacement_sn']
+ del(self.fields['mark_complete'])
+ del(self.fields['replacement_sn'])
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]
+
+ 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():
diff --git a/servo/migrations/0025_auto_20150815_0921.py b/servo/migrations/0025_auto_20150815_0921.py
new file mode 100644
index 0000000..80bf5a3
--- /dev/null
+++ b/servo/migrations/0025_auto_20150815_0921.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('servo', '0024_auto_20150813_1048'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='repair',
+ name='issue_code',
+ field=models.CharField(default=b'', max_length=7),
+ ),
+ migrations.AddField(
+ model_name='repair',
+ name='symptom_code',
+ field=models.CharField(default=b'', max_length=7),
+ ),
+ migrations.AlterField(
+ model_name='device',
+ name='product_line',
+ field=models.CharField(default=b'OTHER', max_length=16, verbose_name='Product Line', choices=[(b'IPODCLASSIC', b'iPod Classic'), (b'POWERMAC', b'Power Mac'), (b'APPLETV', b'Apple TV'), (b'IMAC', b'iMac'), (b'OTHER', b'Other Products'), (b'MACBOOKAIR', b'MacBook Air'), (b'DISPLAYS', b'Display'), (b'IPODTOUCH', b'iPod Touch'), (b'MACPRO', b'Mac Pro'), (b'IPODNANO', b'iPod nano'), (b'IPAD', b'iPad'), (b'MACBOOK', b'MacBook'), (b'MACACCESSORY', b'Mac Accessory'), (b'MACMINI', b'Mac mini'), (b'BEATS', b'Beats Products'), (b'SERVER', b'Server'), (b'MACBOOKLEGACY', b'MacBook'), (b'IPHONE', b'iPhone'), (b'IPHONEACCESSORY', b'iPhone Accessory'), (b'IPODSHUFFLE', b'iPod Shuffle'), (b'MACBOOKPRO', b'MacBook Pro')]),
+ ),
+ migrations.AlterField(
+ model_name='product',
+ name='component_code',
+ field=models.CharField(default=b'', max_length=1, verbose_name='component group', blank=True, choices=[(b'0', b'General'), (b'1', b'Visual'), (b'2', b'Displays'), (b'3', b'Mass Storage'), (b'4', b'Input Devices'), (b'5', b'Boards'), (b'6', b'Power'), (b'7', b'Printer'), (b'8', b'Multi-function Device'), (b'9', b'Communication Devices'), (b'A', b'Share'), (b'B', b'iPhone'), (b'E', b'iPod'), (b'F', b'iPad'), (b'G', b'Beats Products'), (b'W', b'Apple Watch')]),
+ ),
+ ]
diff --git a/servo/models/repair.py b/servo/models/repair.py
index c45db2f..345b69f 100644
--- a/servo/models/repair.py
+++ b/servo/models/repair.py
@@ -28,6 +28,8 @@ import json
import gsxws
import os.path
+from gsxws.repairs import SymptomIssue
+
from django.db import models
from django.conf import settings
from django.utils import timezone
@@ -38,6 +40,7 @@ from django.core.validators import MaxLengthValidator
from django.contrib.sites.managers import CurrentSiteManager
from servo import defaults
+from servo.lib.utils import cache_getset
from servo.models.common import GsxAccount
from servo.models import Queue, Order, Device, Product
from servo.models.order import ServiceOrderItem
@@ -211,6 +214,23 @@ class Repair(models.Model):
help_text=_('Unit is eligible for consumer law coverage')
)
+ symptom_code = models.CharField(max_length=7, default='')
+ issue_code = models.CharField(max_length=7, default='')
+
+ def get_symptom_code_choices(self):
+ # @fixme: what if it's someone else ordering the part?
+ self.gsx_account.connect(self.created_by)
+ ckey = 'symptom_codes-' + self.device.sn
+ si = SymptomIssue(serialNumber=self.device.sn)
+ return cache_getset(ckey, si.fetch)
+
+ def get_issue_code_choices(self):
+ # @fixme: what if it's someone else ordering the part?
+ self.gsx_account.connect(self.created_by)
+ ckey = 'issue_codes-' + self.symptom_code
+ si = SymptomIssue(reportedSymptomCode=self.symptom_code)
+ return cache_getset(ckey, si.fetch)
+
@property
def has_cl_parts(self):
"""
@@ -416,6 +436,10 @@ class Repair(models.Model):
data['poNumber'] = self.reference
data['diagnosis'] = self.diagnosis
data['shipTo'] = self.gsx_account.ship_to
+
+ data['reportedSymptomCode'] = self.symptom_code
+ data['reportedIssueCode'] = self.issue_code
+
# checkIfOutOfWarrantyCoverage
if self.tech_id:
data['diagnosedByTechId'] = self.tech_id
diff --git a/servo/templates/orders/gsx_repair_form.html b/servo/templates/orders/gsx_repair_form.html
index 512ce5a..2751b5e 100755
--- a/servo/templates/orders/gsx_repair_form.html
+++ b/servo/templates/orders/gsx_repair_form.html
@@ -47,6 +47,14 @@
<div class="tab-pane active" id="tab1">
{% include "form_field_snippet.html" with field=repair_form.symptom %}
{% include "form_field_snippet.html" with field=repair_form.diagnosis %}
+ <div class="row-fluid">
+ <div class="span6">
+ {% include "form_field_snippet.html" with field=repair_form.symptom_code %}
+ </div>
+ <div class="span6">
+ {% include "form_field_snippet.html" with field=repair_form.issue_code %}
+ </div>
+ </div>
{% include "form_field_snippet.html" with field=repair_form.tech_id %}
</div>
<div class="tab-pane" id="tab2">
@@ -90,5 +98,15 @@
{% endblock crumbs %}
{% block media %}
-{{ repair_form.media }}
+ {{ repair_form.media }}
+ <script type="text/javascript">
+ $('#id_symptom_code').change(function(e){
+ var c = $(e.target).val();
+ $('.wrapper').spin();
+ $.get('?c='+c).success(function(r) {
+ $('#id_issue_code').html(r);
+ $('.wrapper').spin(false);
+ });
+ });
+ </script>
{% endblock media %}
diff --git a/servo/templates/repairs/issue_code_menu.html b/servo/templates/repairs/issue_code_menu.html
new file mode 100644
index 0000000..8697803
--- /dev/null
+++ b/servo/templates/repairs/issue_code_menu.html
@@ -0,0 +1,3 @@
+{% for k, v in choices %}
+ <option value="{{ k|safe }}">{{ v }}</option>
+{% endfor %}
diff --git a/servo/views/gsx.py b/servo/views/gsx.py
index c9af1a1..59030c9 100644
--- a/servo/views/gsx.py
+++ b/servo/views/gsx.py
@@ -214,8 +214,16 @@ def edit_repair(request, order_id, repair_id):
"""
Edits existing (non-submitted) GSX repair
"""
- order = Order.objects.get(pk=order_id)
- repair = Repair.objects.get(pk=repair_id)
+ order = get_object_or_404(Order, pk=order_id)
+ repair = get_object_or_404(Repair, pk=repair_id)
+
+ if request.GET.get('c'):
+ from django import forms
+ repair.symptom_code = request.GET['c']
+ repair.save()
+ choices = repair.get_issue_code_choices()
+ return render(request, "repairs/issue_code_menu.html", locals())
+
repair.set_parts(order.get_parts())
try:
@@ -237,7 +245,7 @@ def edit_repair(request, order_id, repair_id):
return redirect("repairs-view_repair", order.pk, repair.pk)
messages.success(request, msg)
return redirect(order)
- except Exception, e:
+ except Exception as e:
messages.error(request, e)
return render(request, "orders/gsx_repair_form.html", data)
@@ -286,8 +294,8 @@ def create_repair(request, order_id, device_id, type):
from datetime import timedelta
from django.utils import timezone
- order = Order.objects.get(pk=order_id)
- device = order.devices.get(pk=device_id)
+ order = get_object_or_404(Order, pk=order_id)
+ device = get_object_or_404(Device, pk=device_id)
repair = Repair(order=order, created_by=request.user, device=device)
timediff = timezone.now() - order.created_at