Download docs for pay. Got and adopted from korpmail

remotes/origin/yandex
Bachurin Sergey 12 years ago
parent aa388f256d
commit 77c07c3184
  1. 24
      project/customer/models.py
  2. 3
      project/customer/urls.py
  3. 102
      project/customer/views/docs.py
  4. 2
      project/templates/customer/profile/license_list.html
  5. BIN
      project/templates/xls/4pd.xls
  6. BIN
      project/templates/xls/act.xls
  7. BIN
      project/templates/xls/bill.xls
  8. BIN
      project/templates/xls/stamp.bmp
  9. BIN
      project/templates/xls/stamp1.bmp
  10. 1
      requirements-dev.txt
  11. 1
      requirements.txt

@ -9,6 +9,7 @@ from dateutil.relativedelta import relativedelta
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from . import consts, managers from . import consts, managers
@ -388,14 +389,15 @@ class License(models.Model):
def get_email(self): def get_email(self):
return self.user.email return self.user.email
def get_action(self): def get_action_link(self):
if self.status == 0: if self.status == 0:
if self.payform == 0: if self.payform == 0:
return u'Скачать счёт' return u'<a href="%s">Скачать счёт</a>' % reverse('customer_license_get_doc', kwargs={'order_num': self.id})
elif self.payform == 1: elif self.payform == 1:
return u'Оплатить счёт' return u'Оплатить счёт'
elif self.payform == 2: elif self.payform == 2:
return u'Скачать квитанцию' return u'<a href="%s">Скачать квитанцию</a>' % reverse('customer_license_get_doc', kwargs={'order_num': self.id})
elif self.status in [1, 2]: elif self.status in [1, 2]:
return u'История операций' return u'История операций'
else: else:
@ -409,22 +411,6 @@ class License(models.Model):
numeral.choose_plural(self.term, u"месяц, месяца, месяцев"), numeral.choose_plural(self.term, u"месяц, месяца, месяцев"),
) )
def get_action(self):
if self.status == -1:
return ''
if self.status == 0:
if self.payform == 0:
#return reverse()
return u'Скачать счёт'
elif self.payform == 1:
return u'Оплатить счёт'
elif self.payform == 2:
return u'Скачать квитанцию'
if self.status == 1:
return u'История операций'
else:
return ''
def get_paid_status(self): def get_paid_status(self):
if self.status == 1: if self.status == 1:
return u'Лицензия оплачена, ещё не активирована' return u'Лицензия оплачена, ещё не активирована'

@ -2,7 +2,7 @@
from django.conf.urls import * from django.conf.urls import *
from . import views from . import views
from .views import profile, profile_ajax, license from .views import profile, profile_ajax, license, docs
from .views import bank_accounts,bank_accounts_ajax from .views import bank_accounts,bank_accounts_ajax
from .views import clients, clients_ajax from .views import clients, clients_ajax
@ -17,6 +17,7 @@ urlpatterns = patterns('',
url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'), url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'),
url(r'^license/$', license.order_license, name='customer_order_license'), url(r'^license/$', license.order_license, name='customer_order_license'),
url(r'^delete_license/(?P<pk>\d+)/$', license.delete_license, name='customer_order_license'), url(r'^delete_license/(?P<pk>\d+)/$', license.delete_license, name='customer_order_license'),
url(r'^get_doc/(?P<order_num>\d+)/$', docs.get_doc, name='customer_license_get_doc'),
url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'), url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'),
url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'), url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'),
url(r'^robokassa/fail/$', license.payment_fail, name='robokassa_fail'), url(r'^robokassa/fail/$', license.payment_fail, name='robokassa_fail'),

@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
import os
import re
from django.conf import settings
from django.http import Http404, HttpResponseRedirect, HttpResponseForbidden, HttpResponse
from xlwt import easyxf
from xlrd import open_workbook
from xlutils.copy import copy
from pytils.numeral import rubles
from ..models import License
XLS_ROOT = os.path.join(settings.TEMPLATE_DIRS[0], 'xls')
def get_doc(request, order_num=None):
if not request.user.is_authenticated():
raise HttpResponseForbidden
license = License.objects.get(pk=order_num)
pm = license.payform
data = request.user.profile
if pm == 0:
tmp_name = 'bill.xls'
file_name = "Invoice No.%s.xls" % (order_num,)
elif pm == 2:
tmp_name = '4pd.xls'
file_name = "Kvitanciya na oplatu zakaza No.%s.xls" % (order_num,)
else:
raise Http404()
response = HttpResponse(mimetype="application/vnd.ms-excel")
response['Content-Disposition'] = 'attachment; filename=%s' % file_name
rb = open_workbook(os.path.join(XLS_ROOT, tmp_name), on_demand=True, formatting_info=True)
wb = copy(rb)
ws = wb.get_sheet(0)
# отключить колонтитулы
ws.show_headers = 0
ws.print_headers = 0
ws.header_str = ''
ws.footer_str = ''
if pm == 0: # заполняем счет
style0 = easyxf('font: name Times New Roman, height 280, bold True;')
style0_center = easyxf('font: name Times New Roman, height 280, bold True; align: horiz center')
style1 = easyxf('font: name Times New Roman, height 180;')
style2 = easyxf('font: name Times New Roman, height 180, bold True;')
style3 = easyxf('font: name Times New Roman, height 180;'
'border: top thin, left thin, right thin, bottom thin;'
)
style4 = easyxf('font: name Times New Roman, height 180, bold True;'
'border: top thin, left thin, right thin, bottom thin;'
)
style4.num_format_str = "#,##0.00"
ws.write(11, 0, u"СЧЕТ № %s от %s" % (order_num, license.order_date.strftime('%d.%m.%Y')), style0_center)
ws.write(13, 0, u"Покупатель: %s" % data.name, style1)
ws.write(16, 2, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style3)
style3.num_format_str = "#,##0.00"
ws.write(16, 36, license.pay_sum, style3)
ws.write(16, 44, license.pay_sum, style3)
ws.write(17, 44, license.pay_sum, style4)
ws.write(19, 44, license.pay_sum, style4)
ws.write(21, 0, u"Всего наименование 1, на сумму %s,00 руб." % license.pay_sum, style1)
ws.write(23, 0, u"%s." % rubles(license.pay_sum).capitalize(), style2)
ws.insert_bitmap(os.path.join(XLS_ROOT, 'stamp.bmp'), 25, 12, y=3, scale_x=1, scale_y=1.1)
elif pm == 2: # заполняем квитанцию
style0 = easyxf('font: name Times New Roman, height 160, bold True;'
'border: bottom thin;'
)
style1 = easyxf('font: name Times New Roman, height 160, bold True;'
'border: bottom thin;'
'align: horiz center;'
)
# заполняем оригинал
ws.write(11, 4, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style1)
ws.write(13, 13, data.get_boss_fio(), style0)
ws.write(14, 13, re.sub("^\s+|\n|\r|\s+$", ' ', data.address), style0)
ws.write(15, 11, license.pay_sum, style1)
# заполняем копию
ws.write(31, 4, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style1)
ws.write(33, 13, data.get_boss_fio(), style0)
ws.write(34, 13, re.sub("^\s+|\n|\r|\s+$", ' ', data.address), style0)
ws.write(35, 11, license.pay_sum, style1)
else:
raise Http404()
wb.save(response)
return response

@ -25,7 +25,7 @@
<div class='w100 left'>{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}</div> <div class='w100 left'>{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}</div>
<div class='w100 left'>{{ license.get_payform_display }}</div> <div class='w100 left'>{{ license.get_payform_display }}</div>
<div class='w100 left'>{{ license.get_status_display }}</div> <div class='w100 left'>{{ license.get_status_display }}</div>
<div class='w100 left'>{{ license.get_action }}</div> <div class='w100 left'>{{ license.get_action_link|safe }}</div>
<div class='w100 left'>{% if license.status == 0 %}<a href='#' class='delete_license' data-id='{{ license.pk }}'>Удалить</a>{% endif %}</div> <div class='w100 left'>{% if license.status == 0 %}<a href='#' class='delete_license' data-id='{{ license.pk }}'>Удалить</a>{% endif %}</div>
<div class='clear'></div> <div class='clear'></div>
</div> </div>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

@ -30,6 +30,7 @@ sqlparse==0.1.11
wsgiref==0.1.2 wsgiref==0.1.2
xlrd==0.9.2 xlrd==0.9.2
xlwt==0.7.5 xlwt==0.7.5
xlutils==1.7.1
# dev # dev
django-devserver django-devserver

@ -30,5 +30,6 @@ sqlparse==0.1.11
wsgiref==0.1.2 wsgiref==0.1.2
xlrd==0.9.2 xlrd==0.9.2
xlwt==0.7.5 xlwt==0.7.5
xlutils==1.7.1
flup flup

Loading…
Cancel
Save