Exemplo n.º 1
0
def send_mail_voucher(invoice):
    """Creates a voucher from an invoice and sends it by email to the client"""
    ctx = {
        'asso_name': AssoOption.get_cached_value('name'),
        'pres_name': AssoOption.get_cached_value('pres_name'),
        'firstname': invoice.user.name,
        'lastname': invoice.user.surname,
        'email': invoice.user.email,
        'phone': invoice.user.telephone,
        'date_end': invoice.get_subscription().latest('date_end').date_end,
        'date_begin':
        invoice.get_subscription().earliest('date_start').date_start
    }
    templatename = CotisationsOption.get_cached_value(
        'voucher_template').template.name.split('/')[-1]
    pdf = create_pdf(templatename, ctx)
    template = get_template('cotisations/email_subscription_accepted')

    ctx = {
        'name': "{} {}".format(invoice.user.name, invoice.user.surname),
        'asso_email': AssoOption.get_cached_value('contact'),
        'asso_name': AssoOption.get_cached_value('name')
    }

    mail = EmailMessage('Votre reçu / Your voucher',
                        template.render(ctx),
                        GeneralOption.get_cached_value('email_from'),
                        [invoice.user.get_mail],
                        attachments=[('voucher.pdf', pdf, 'application/pdf')])
    mail.send()
Exemplo n.º 2
0
def voucher_pdf(request, invoice, **_kwargs):
    """
    View used to generate a PDF file from a controlled invoice
    Creates a line for each Purchase (thus article sold) and generate the
    invoice with the total price, the payment method, the address and the
    legal information for the user.
    """
    if not invoice.control:
        messages.error(request,
                       _("Could not find a voucher for that invoice."))
        return redirect(reverse("cotisations:index"))
    president = Mandate.get_mandate(invoice.date).president
    return render_voucher(
        request,
        {
            "asso_name": AssoOption.get_cached_value("name"),
            "pres_name": " ".join([president.name, president.surname]),
            "firstname": invoice.user.name,
            "lastname": invoice.user.surname,
            "email": invoice.user.email,
            "phone": invoice.user.telephone,
            "date_end":
            invoice.get_subscription().latest("date_end_memb").date_end_memb,
            "date_begin": invoice.date,
        },
    )
Exemplo n.º 3
0
def all_has_access(search_time=None, including_asso=True):
    """ Return all connected users : active users and whitelisted +
    asso_user defined in AssoOption pannel
    ----
    Renvoie tous les users beneficiant d'une connexion
    : user adherent et whiteliste non banni plus l'utilisateur asso"""
    if search_time is None:
        search_time = timezone.now()
    filter_user = (
        Q(state=User.STATE_ACTIVE) &
        ~Q(ban__in=Ban.objects.filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))) &
        (Q(whitelist__in=Whitelist.objects.filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))) |
         Q(facture__in=Facture.objects.filter(
             vente__in=Vente.objects.filter(
                 cotisation__in=Cotisation.objects.filter(
                     Q(type_cotisation='All') | Q(type_cotisation='Connexion'),
                     vente__in=Vente.objects.filter(
                         facture__in=Facture.objects.all()
                         .exclude(valid=False)
                     )
                 ).filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))
             )
         )))
    )
    if including_asso:
        asso_user = AssoOption.get_cached_value('utilisateur_asso')
        if asso_user:
            filter_user |= Q(id=asso_user.id)
    return User.objects.filter(filter_user).distinct()
Exemplo n.º 4
0
def send_mail_voucher(invoice, request=None):
    """Creates a voucher from an invoice and sends it by email to the client"""
    president = Mandate.get_mandate(invoice.date).president
    ctx = {
        "asso_name":
        AssoOption.get_cached_value("name"),
        "pres_name":
        " ".join([president.name, president.surname]),
        "firstname":
        invoice.user.name,
        "lastname":
        invoice.user.surname,
        "email":
        invoice.user.email,
        "phone":
        invoice.user.telephone,
        "date_end":
        invoice.get_subscription().latest("date_end_memb").date_end_memb,
        "date_begin":
        invoice.get_subscription().earliest("date_start_memb").date_start_memb,
    }
    templatename = CotisationsOption.get_cached_value(
        "voucher_template").template.name.split("/")[-1]
    pdf = create_pdf(templatename, ctx)
    template = get_template("cotisations/email_subscription_accepted")

    ctx = {
        "name":
        "{} {}".format(invoice.user.name, invoice.user.surname),
        "asso_email":
        AssoOption.get_cached_value("contact"),
        "asso_name":
        AssoOption.get_cached_value("name"),
        "date_end":
        invoice.get_subscription().latest("date_end_memb").date_end_memb,
    }

    mail = EmailMessage(
        "Votre reçu / Your voucher",
        template.render(ctx),
        GeneralOption.get_cached_value("email_from"),
        [invoice.user.get_mail],
        attachments=[("voucher.pdf", pdf, "application/pdf")],
    )

    send_mail_object(mail, request)
Exemplo n.º 5
0
def voucher_pdf(request, invoice, **_kwargs):
    """
    View used to generate a PDF file from a controlled invoice
    Creates a line for each Purchase (thus article sold) and generate the
    invoice with the total price, the payment method, the address and the
    legal information for the user.
    """
    if not invoice.control:
        messages.error(request,
                       _("Could not find a voucher for that invoice."))
        return redirect(reverse('cotisations:index'))
    return render_voucher(
        request, {
            'asso_name': AssoOption.get_cached_value('name'),
            'pres_name': AssoOption.get_cached_value('pres_name'),
            'firstname': invoice.user.name,
            'lastname': invoice.user.surname,
            'email': invoice.user.email,
            'phone': invoice.user.telephone,
            'date_end': invoice.get_subscription().latest('date_end').date_end,
            'date_begin': invoice.date
        })
Exemplo n.º 6
0
def send_mail_invoice(invoice, request=None):
    """Creates the pdf of the invoice and sends it by email to the client"""
    purchases_info = []
    for purchase in invoice.vente_set.all():
        purchases_info.append({
            "name": purchase.name,
            "price": purchase.prix,
            "quantity": purchase.number,
            "total_price": purchase.prix_total,
        })

    ctx = {
        "paid": True,
        "fid": invoice.id,
        "DATE": invoice.date,
        "recipient_name": "{} {}".format(invoice.user.name,
                                         invoice.user.surname),
        "address": invoice.user.room,
        "article": purchases_info,
        "total": invoice.prix_total(),
        "asso_name": AssoOption.get_cached_value("name"),
        "line1": AssoOption.get_cached_value("adresse1"),
        "line2": AssoOption.get_cached_value("adresse2"),
        "siret": AssoOption.get_cached_value("siret"),
        "email": AssoOption.get_cached_value("contact"),
        "phone": AssoOption.get_cached_value("telephone"),
        "tpl_path": os.path.join(settings.BASE_DIR, LOGO_PATH),
    }

    template = CotisationsOption.get_cached_value(
        "invoice_template").template.name.split("/")[-1]
    pdf = create_pdf(template, ctx)
    template = get_template("cotisations/email_invoice")

    ctx = {
        "name": "{} {}".format(invoice.user.name, invoice.user.surname),
        "contact_mail": AssoOption.get_cached_value("contact"),
        "asso_name": AssoOption.get_cached_value("name"),
    }

    mail = EmailMessage(
        "Votre facture / Your invoice",
        template.render(ctx),
        GeneralOption.get_cached_value("email_from"),
        [invoice.user.get_mail],
        attachments=[("invoice.pdf", pdf, "application/pdf")],
    )

    send_mail_object(mail, request)
Exemplo n.º 7
0
def facture_pdf(request, facture, **_kwargs):
    """
    View used to generate a PDF file from  an existing invoice in database
    Creates a line for each Purchase (thus article sold) and generate the
    invoice with the total price, the payment method, the address and the
    legal information for the user.
    """
    # TODO : change vente to purchase
    purchases_objects = Vente.objects.all().filter(facture=facture)
    # Get the article list and build an list out of it
    # contiaining (article_name, article_price, quantity, total_price)
    purchases_info = []
    for purchase in purchases_objects:
        purchases_info.append({
            "name": purchase.name,
            "price": purchase.prix,
            "quantity": purchase.number,
            "total_price": purchase.prix_total,
        })
    return render_invoice(
        request,
        {
            "paid":
            True,
            "fid":
            facture.id,
            "DATE":
            facture.date,
            "recipient_name":
            "{} {}".format(facture.user.name, facture.user.surname),
            "address":
            facture.user.room,
            "article":
            purchases_info,
            "total":
            facture.prix_total(),
            "asso_name":
            AssoOption.get_cached_value("name"),
            "line1":
            AssoOption.get_cached_value("adresse1"),
            "line2":
            AssoOption.get_cached_value("adresse2"),
            "siret":
            AssoOption.get_cached_value("siret"),
            "email":
            AssoOption.get_cached_value("contact"),
            "phone":
            AssoOption.get_cached_value("telephone"),
            "tpl_path":
            os.path.join(settings.BASE_DIR, LOGO_PATH),
            "payment_method":
            facture.paiement.moyen,
        },
    )
Exemplo n.º 8
0
def send_mail_invoice(invoice):
    """Creates the pdf of the invoice and sends it by email to the client"""
    purchases_info = []
    for purchase in invoice.vente_set.all():
        purchases_info.append({
            'name': purchase.name,
            'price': purchase.prix,
            'quantity': purchase.number,
            'total_price': purchase.prix_total
        })

    ctx = {
        'paid': True,
        'fid': invoice.id,
        'DATE': invoice.date,
        'recipient_name': "{} {}".format(invoice.user.name,
                                         invoice.user.surname),
        'address': invoice.user.room,
        'article': purchases_info,
        'total': invoice.prix_total(),
        'asso_name': AssoOption.get_cached_value('name'),
        'line1': AssoOption.get_cached_value('adresse1'),
        'line2': AssoOption.get_cached_value('adresse2'),
        'siret': AssoOption.get_cached_value('siret'),
        'email': AssoOption.get_cached_value('contact'),
        'phone': AssoOption.get_cached_value('telephone'),
        'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
    }

    pdf = create_pdf('cotisations/factures.tex', ctx)
    template = get_template('cotisations/email_invoice')

    ctx = {
        'name': "{} {}".format(invoice.user.name, invoice.user.surname),
        'contact_mail': AssoOption.get_cached_value('contact'),
        'asso_name': AssoOption.get_cached_value('name')
    }

    mail = EmailMessage('Votre facture / Your invoice',
                        template.render(ctx),
                        GeneralOption.get_cached_value('email_from'),
                        [invoice.user.get_mail],
                        attachments=[('invoice.pdf', pdf, 'application/pdf')])
    mail.send()
Exemplo n.º 9
0
def index(request):
    """Affiche la liste des services sur la page d'accueil de re2o"""
    services = [[], [], []]
    for indice, serv in enumerate(Service.objects.all()):
        services[indice % 3].append(serv)
    twitter_url = HomeOption.get_cached_value('twitter_url')
    facebook_url = HomeOption.get_cached_value('facebook_url')
    twitter_account_name = HomeOption.get_cached_value('twitter_account_name')
    asso_name = AssoOption.get_cached_value('pseudo')
    return form(
        {
            'services_urls': services,
            'twitter_url': twitter_url,
            'twitter_account_name': twitter_account_name,
            'facebook_url': facebook_url,
            'asso_name': asso_name
        }, 're2o/index.html', request)
Exemplo n.º 10
0
def facture_pdf(request, facture, **_kwargs):
    """
    View used to generate a PDF file from  an existing invoice in database
    Creates a line for each Purchase (thus article sold) and generate the
    invoice with the total price, the payment method, the address and the
    legal information for the user.
    """
    # TODO : change vente to purchase
    purchases_objects = Vente.objects.all().filter(facture=facture)
    # Get the article list and build an list out of it
    # contiaining (article_name, article_price, quantity, total_price)
    purchases_info = []
    for purchase in purchases_objects:
        purchases_info.append({
            'name': purchase.name,
            'price': purchase.prix,
            'quantity': purchase.number,
            'total_price': purchase.prix_total
        })
    return render_invoice(
        request, {
            'paid':
            True,
            'fid':
            facture.id,
            'DATE':
            facture.date,
            'recipient_name':
            "{} {}".format(facture.user.name, facture.user.surname),
            'address':
            facture.user.room,
            'article':
            purchases_info,
            'total':
            facture.prix_total(),
            'asso_name':
            AssoOption.get_cached_value('name'),
            'line1':
            AssoOption.get_cached_value('adresse1'),
            'line2':
            AssoOption.get_cached_value('adresse2'),
            'siret':
            AssoOption.get_cached_value('siret'),
            'email':
            AssoOption.get_cached_value('contact'),
            'phone':
            AssoOption.get_cached_value('telephone'),
            'tpl_path':
            os.path.join(settings.BASE_DIR, LOGO_PATH),
            'payment_method':
            facture.paiement.moyen,
        })
Exemplo n.º 11
0
def edit_ap(request, ap, **_kwargs):
    """ Edition d'un switch. Permet de chambre nombre de ports,
    place dans le stack, interface et machine associée"""
    interface_form = EditInterfaceForm(request.POST or None,
                                       user=request.user,
                                       instance=ap.interface_set.first())
    ap_form = EditAccessPointForm(request.POST or None,
                                  user=request.user,
                                  instance=ap)
    domain_form = DomainForm(request.POST or None,
                             instance=ap.interface_set.first().domain)
    if ap_form.is_valid() and interface_form.is_valid():
        user = AssoOption.get_cached_value('utilisateur_asso')
        if not user:
            messages.error(
                request,
                (_("The organisation's user doesn't exist yet, please create"
                   " or link it in the preferences.")))
            return redirect(reverse('topologie:index-ap'))
        new_ap_obj = ap_form.save(commit=False)
        new_interface_obj = interface_form.save(commit=False)
        new_domain_obj = domain_form.save(commit=False)
        if ap_form.changed_data:
            new_ap_obj.save()
        if interface_form.changed_data:
            new_interface_obj.save()
        if domain_form.changed_data:
            new_domain_obj.save()
        messages.success(request, _("The access point was edited."))
        return redirect(reverse('topologie:index-ap'))
    i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
    return form(
        {
            'topoform': interface_form,
            'machineform': ap_form,
            'domainform': domain_form,
            'i_mbf_param': i_mbf_param,
            'device': 'wifi ap',
        }, 'topologie/topo_more.html', request)
Exemplo n.º 12
0
def new_ap(request):
    """ Creation d'une ap. Cree en meme temps l'interface et la machine
    associée. Vue complexe. Appelle successivement les 3 models forms
    adaptés : machine, interface, domain et switch"""
    ap = AddAccessPointForm(request.POST or None, user=request.user)
    interface = AddInterfaceForm(request.POST or None, user=request.user)
    domain = DomainForm(request.POST or None, )
    if ap.is_valid() and interface.is_valid():
        user = AssoOption.get_cached_value('utilisateur_asso')
        if not user:
            messages.error(
                request,
                (_("The organisation's user doesn't exist yet, please create"
                   " or link it in the preferences.")))
            return redirect(reverse('topologie:index'))
        new_ap_obj = ap.save(commit=False)
        new_ap_obj.user = user
        new_interface_obj = interface.save(commit=False)
        domain.instance.interface_parent = new_interface_obj
        if domain.is_valid():
            new_domain_obj = domain.save(commit=False)
            new_ap_obj.save()
            new_interface_obj.machine = new_ap_obj
            new_interface_obj.save()
            new_domain_obj.interface_parent = new_interface_obj
            new_domain_obj.save()
            messages.success(request, _("The access point was created."))
            return redirect(reverse('topologie:index-ap'))
    i_mbf_param = generate_ipv4_mbf_param(interface, False)
    return form(
        {
            'topoform': interface,
            'machineform': ap,
            'domainform': domain,
            'i_mbf_param': i_mbf_param,
            'device': 'wifi ap',
        }, 'topologie/topo_more.html', request)
Exemplo n.º 13
0
def all_adherent(search_time=None, including_asso=True):
    """ Fonction renvoyant tous les users adherents. Optimisee pour n'est
    qu'une seule requete sql
    Inspecte les factures de l'user et ses cotisation, regarde si elles
    sont posterieur à now (end_time)"""
    if search_time is None:
        search_time = timezone.now()
    filter_user = (
        Q(facture__in=Facture.objects.filter(
            vente__in=Vente.objects.filter(
                Q(type_cotisation='All') | Q(type_cotisation='Adhesion'),
                cotisation__in=Cotisation.objects.filter(
                    vente__in=Vente.objects.filter(
                        facture__in=Facture.objects.all().exclude(valid=False)
                    )
                ).filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time))
            )
        )
    ))
    if including_asso:
        asso_user = AssoOption.get_cached_value('utilisateur_asso')
        if asso_user:
            filter_user |= Q(id=asso_user.id)
    return User.objects.filter(filter_user).distinct()