Example #1
0
 def get_initial(self):
     quote = get_single_quote(self.kwargs.get('obj_id'))
     quote = vars(quote)
     address = quote['address']
     split_address = address.split(',')
     quote['street'] = split_address[0].lstrip()
     quote['city'] = split_address[1].lstrip()
     quote['post_code'] = split_address[2].lstrip()
     return quote
    def delete(self, request, *args, **kwargs):
        job = get_single_job(self.kwargs.get('obj_id'))

        # when job is deleted also delete associated quote
        quote = get_single_quote(job.associated_quote)
        quote.delete()

        name = job.customer_first_name + ' ' + job.customer_last_name

        job.delete()

        success_url = reverse_lazy('view-jobs')
        messages.success(self.request,
                         'Job and associated quote for ' + name + ' deleted')
        return HttpResponseRedirect(success_url)
Example #3
0
    def delete(self, request, *args, **kwargs):
        quote = get_single_quote(self.kwargs.get('obj_id'))

        # when quote is deleted also delete associated job
        if quote.associated_job != None:
            job = get_single_job(quote.associated_job)
            job.delete()

        name = quote.customer_first_name + ' ' + quote.customer_last_name

        quote.delete()

        success_url = reverse_lazy('view-quotes')
        messages.success(self.request,
                         'Quote and associated job for ' + name + ' deleted')
        return HttpResponseRedirect(success_url)
Example #4
0
def send_quote(request):
    if request.is_ajax():
        quote_id = request.POST.get('data')
        quote = get_single_quote(quote_id)

        try:
            if quote.customer_email == None:
                raise ValidationError('Must have a customer email')
            elif quote.date_of_job == None:
                raise ValidationError('Must have a date of job')
            elif quote.materials == None:
                raise ValidationError('Must have materials')
            elif quote.price_of_materials == None:
                raise ValidationError('Must have price of materials')
            elif quote.price_of_labour == None:
                raise ValidationError('Must have price of labour')
            elif quote.quote_price == None:
                raise ValidationError('Must have quote price')

        except ValidationError as err:
            return JsonResponse({'status': 'error'})

        quote.issued_by_first_name = quote.issued_by.first_name
        quote.issued_by_last_name = quote.issued_by.last_name
        quote.issued_by_address = quote.issued_by.address
        quote.issued_by_number = quote.issued_by.phone_num
        quote_dict = vars(quote)

        pdf = create_pdf(quote_dict)

        email = EmailMessage(
            subject='Frenchay Fencing Quote',
            body=
            'Please find attached your quote.\n\nPlease do not reply to this email. Instead, contact us using the details on your quote.',
            from_email=os.environ.get('EMAIL_USER'),
            to=[quote.customer_email],
            cc=[quote.issued_by.email])
        email.attach('quote.pdf', pdf, 'application/pdf')
        try:
            email.send()
            quote.sent_quote = True
            quote.save()
            return JsonResponse({'status': 'success'})
        except SMTPException as err:
            return JsonResponse({'status': 'error'})
Example #5
0
def create_job(request):
    if request.is_ajax():
        quote_id = request.POST.get('data')
        quote = get_single_quote(quote_id)

        job = create_job_with_quote(quote)

        try:
            job.full_clean()
            job.save()
            quote.associated_job = job._id
            quote.save()

            url = reverse('job-details', kwargs={'obj_id': job._id})
            data = {'success': url}
            name = quote.customer_first_name + ' ' + quote.customer_last_name
            messages.success(request, 'Job for ' + name + ' created')
            return JsonResponse(data)

        except ValidationError as err:
            data = {'error': err.message_dict}
            return JsonResponse(data)
Example #6
0
    def get_object(self, queryset=None):
        quote = get_single_quote(self.kwargs.get('obj_id'))
        quote.id = quote._id

        return quote