views.py 661 Bytes
Newer Older
Damien Moulard committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
from outils.common_imports import *
from outils.for_view_imports import *

from sales.models import CagetteSales


def index(request):
    """Display sales export screen"""

    context = {'title': 'Export de ventes'}
    template = loader.get_template('sales/index.html')

    return HttpResponse(template.render(context, request))

def get_sales(request):
    res = {}

    date_from = request.GET.get('from', '')
    date_to = request.GET.get('to', '')

    m = CagetteSales()
    res = m.get_sales(date_from, date_to)

    if 'errors' in res and res['errors']:
        return JsonResponse(res, status=500)
    else:
        return JsonResponse({'res': res})