|
|
|
|
@ -1,25 +1,23 @@ |
|
|
|
|
import csv |
|
|
|
|
import datetime |
|
|
|
|
import pytils |
|
|
|
|
import weasyprint |
|
|
|
|
from decimal import Decimal |
|
|
|
|
|
|
|
|
|
import pytils |
|
|
|
|
import weasyprint |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.contrib import admin |
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
from django.template.loader import render_to_string |
|
|
|
|
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
from jet.admin import CompactInline |
|
|
|
|
from jet.filters import DateRangeFilter |
|
|
|
|
from rangefilter.filter import DateTimeRangeFilter |
|
|
|
|
|
|
|
|
|
from core.admin import SafeModelAdmin |
|
|
|
|
from core.models import Certificate |
|
|
|
|
from eshop_project.settings.base import PAY_REQUISITES |
|
|
|
|
from .models import ( |
|
|
|
|
Offer, SupplyType, |
|
|
|
|
Currency, Buying, |
|
|
|
|
Buying, |
|
|
|
|
SupplyTarget, |
|
|
|
|
Order, Discount, |
|
|
|
|
Client) |
|
|
|
|
@ -32,6 +30,7 @@ class ProductOfferInlineAdmin(CompactInline): |
|
|
|
|
show_change_link = 1 |
|
|
|
|
max_num = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Supply admins |
|
|
|
|
|
|
|
|
|
@admin.register(SupplyType) |
|
|
|
|
@ -49,7 +48,7 @@ class SupplyTargetAdmin(admin.ModelAdmin): |
|
|
|
|
@admin.register(Discount) |
|
|
|
|
class DiscountAdmin(admin.ModelAdmin): |
|
|
|
|
list_display = ['code', 'valid_from', 'valid_to', 'value', 'active'] |
|
|
|
|
list_filter = ['valid_from', 'valid_to', 'active'] |
|
|
|
|
list_filter = ['valid_from', 'valid_to', 'active'] |
|
|
|
|
search_field = ['code'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -84,9 +83,10 @@ class BuyingAdmin(SafeModelAdmin): |
|
|
|
|
data_row.append(value) |
|
|
|
|
writer.writerow(data_row) |
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
export_buyings_to_csv.short_description = _('экспортировать CSV') |
|
|
|
|
|
|
|
|
|
def print_order_in_pdf(self,buyings): |
|
|
|
|
def print_order_in_pdf(self, buyings): |
|
|
|
|
verb_price = pytils.numeral.in_words(round(buyings.total_price)) |
|
|
|
|
verb_cur = pytils.numeral.choose_plural(round(buyings.total_price), ("рубль", "рубля", "рублей")) |
|
|
|
|
html = render_to_string('bootstrap/pdf/buyings.html', { |
|
|
|
|
@ -96,17 +96,17 @@ class BuyingAdmin(SafeModelAdmin): |
|
|
|
|
response = HttpResponse(content_type='application/pdf') |
|
|
|
|
response['Content-Disposition'] = 'filename=order_{}.pdf'.format(buyings.id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
weasyprint.HTML( |
|
|
|
|
string=rendered_html, |
|
|
|
|
base_url=self.request.build_absolute_uri() |
|
|
|
|
).write_pdf( |
|
|
|
|
response, |
|
|
|
|
stylesheets = [ |
|
|
|
|
stylesheets=[ |
|
|
|
|
weasyprint.CSS(settings.STATIC_ROOT + '/css/bootstrap.min.css') |
|
|
|
|
] |
|
|
|
|
) |
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
print_order_in_pdf.short_description = _('Распечатать заказ в pdf') |
|
|
|
|
|
|
|
|
|
def mark_buyings_as_paid(self, request, queryset): |
|
|
|
|
@ -118,8 +118,8 @@ class BuyingAdmin(SafeModelAdmin): |
|
|
|
|
parent_profile.save() |
|
|
|
|
buying.status = BUYING_STATUS_PAID |
|
|
|
|
buying.save() |
|
|
|
|
mark_buyings_as_paid.short_description = _('Отметить как оплаченные') |
|
|
|
|
|
|
|
|
|
mark_buyings_as_paid.short_description = _('Отметить как оплаченные') |
|
|
|
|
|
|
|
|
|
inlines = () |
|
|
|
|
list_display = ('user', 'offer', 'status', 'amount', 'total_price') |
|
|
|
|
@ -133,11 +133,11 @@ class BuyingAdmin(SafeModelAdmin): |
|
|
|
|
|
|
|
|
|
@admin.register(Order) |
|
|
|
|
class OrderAdmin(SafeModelAdmin): |
|
|
|
|
list_display = ('order_code', 'customer_user', 'customer_name', 'customer_email','phone') |
|
|
|
|
list_display = ('order_code', 'customer_user', 'customer_name', 'customer_email', 'phone') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Client) |
|
|
|
|
class ClientAdmin(SafeModelAdmin): |
|
|
|
|
list_display = ('name','image','status',) |
|
|
|
|
list_display = ('name', 'image', 'status',) |
|
|
|
|
search_fields = ('name',) |
|
|
|
|
list_filter = ('status',) |
|
|
|
|
|