def send_invoice(request):
    if request.is_ajax():
        job_id = request.POST.get('data')
        job = get_single_job(job_id)

        job.issued_by_first_name = job.issued_by.first_name
        job.issued_by_last_name = job.issued_by.last_name
        job.issued_by_address = job.issued_by.address
        job.issued_by_number = job.issued_by.phone_num
        job_dict = vars(job)

        pdf = create_pdf(job_dict)

        email = EmailMessage(
            subject='Frenchay Fencing Invoice',
            body=
            'Please find attached your invoice.\n\nPlease do not reply to this email. Instead, contact us using the details on your invoice.',
            from_email=os.environ.get('EMAIL_USER'),
            to=[job.customer_email],
            cc=[job.issued_by.email])
        email.attach('invoice.pdf', pdf, 'application/pdf')
        try:
            email.send()
            job.sent_invoice = True
            job.save()
            return JsonResponse({'status': 'success'})
        except SMTPException as err:
            return JsonResponse({'status': 'error'})
 def get_initial(self):
     job = get_single_job(self.kwargs.get('obj_id'))
     job = vars(job)
     address = job['address']
     split_address = address.split(',')
     job['street'] = split_address[0].lstrip()
     job['city'] = split_address[1].lstrip()
     job['post_code'] = split_address[2].lstrip()
     return job
    def get_object(self, queryset=None):
        job = get_single_job(self.kwargs.get('obj_id'))
        job.id = job._id

        address = job.address
        address = address.split(",")
        job.street = address[0].lstrip()
        job.city = address[1].lstrip().lower()
        job.post_code = address[2].lstrip()

        return job
    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)
Exemple #5
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)
    def get_object(self, queryset=None):
        job = get_single_job(self.kwargs.get('obj_id'))
        job.id = job._id

        return job