def add_consumer_element(request):
    first_name = request.POST.get('firstname', None)
    last_name = request.POST.get('lastname', None)
    gender = request.POST.get('gender', None)
    address = request.POST.get('address', None)
    sub = request.POST.get('subconsumer', None)
    phone = request.POST.get('phone', None)
    outlet_id = request.POST.get('mainOutlet', None)
    if ((sub is None) or (not is_int(sub))):
        return HttpResponse('Impossible, certains champs devraient être des entiers', status=400)
    outlet = Element.objects.filter(id=outlet_id).first()
    if (outlet is None):
        return HttpResponse("La sortie d'eau spécifiée n'a pas été trouvée, impossible d'ajouter le consommateur", status=400)
    if (not has_access(outlet, request)):
        return HttpResponse("Vous n'avez pas les droits sur cet élément de réseau", status=403)
    consumer = Consumer(last_name=last_name, first_name=first_name, gender=gender, location=address, phone_number=phone, household_size=sub, water_outlet=outlet)
    log_element(consumer, request)
    if (outlet.type != ElementType.INDIVIDUAL.name):
        (price, duration) = outlet.get_price_and_duration()
        creation = date.today()
        expiration = (creation + relativedelta(months=duration))
        invoice = Invoice(consumer=consumer, water_outlet=outlet, amount=price, creation=creation, expiration=expiration)
        invoice.save()
    json_object = {'data': consumer.descript(), 'type': 'add', 'table': 'consumer'}
    return HttpResponse(json.dumps(json_object), status=200)
def add_consumer_element(request):
    first_name = request.POST.get('firstname', None)
    last_name = request.POST.get('lastname', None)
    gender = request.POST.get('gender', None)
    address = request.POST.get('address', None)
    sub = request.POST.get('subconsumer', None)
    phone = request.POST.get('phone', None)
    outlet_id = request.POST.get('mainOutlet', None)
    if ((sub is None) or (not is_int(sub))):
        return HttpResponse('Impossible, certains champs devraient être des entiers', status=400)
    outlet = Element.objects.filter(id=outlet_id).first()
    if (outlet is None):
        return HttpResponse("La sortie d'eau spécifiée n'a pas été trouvée, impossible d'ajouter le consommateur", status=400)
    if (not has_access(outlet, request)):
        return HttpResponse("Vous n'avez pas les droits sur cet élément de réseau", status=403)
    consumer = Consumer(last_name=last_name, first_name=first_name, gender=gender, location=address, phone_number=phone, household_size=sub, water_outlet=outlet)
    log_element(consumer, request)
    if (outlet.type != ElementType.INDIVIDUAL.name):
        (price, duration) = outlet.get_price_and_duration()
        creation = date.today()
        expiration = (creation + relativedelta(months=duration))
        invoice = Invoice(consumer=consumer, water_outlet=outlet, amount=price, creation=creation, expiration=expiration)
        invoice.save()
    json_object = {'data': consumer.descript(), 'type': 'add', 'table': 'consumer'}
    return HttpResponse(json.dumps(json_object), status=200)