Exemple #1
0
 def test_bignums(self):
     self.assertEqual(cel(32571), u"trente deux mille " \
                                   "cinq cent soixante-et-onze")
     self.assertEqual(cel(203), u"deux cent trois")
     self.assertEqual(cel(2000000), u"deux million")
     self.assertEqual(cel(73591228), u"soixante treize million cinq " \
                                      "cent quatre-vingt onze mille deux " \
                                      "cent vingt huit")
Exemple #2
0
 def test_tens(self):
     self.assertEqual(cel(20), u"vingt")
     self.assertEqual(cel(30), u"trente")
     self.assertEqual(cel(40), u"quarante")
     self.assertEqual(cel(50), u"cinquante")
     self.assertEqual(cel(60), u"soixante")
     self.assertEqual(cel(70), u"soixante-dix")
     self.assertEqual(cel(80), u"quatre-vingt")
     self.assertEqual(cel(90), u"quatre-vingt-dix")
Exemple #3
0
 def test_andone(self):
     self.assertEqual(cel(21), u"vingt-et-un")
     self.assertEqual(cel(31), u"trente-et-un")
     self.assertEqual(cel(41), u"quarante-et-un")
     self.assertEqual(cel(51), u"cinquante-et-un")
     self.assertEqual(cel(61), u"soixante-et-un")
     self.assertEqual(cel(121), u"cent vingt-et-un")
     self.assertEqual(cel(461), u"quatre cent soixante-et-un")
Exemple #4
0
def invoice_done(request, *args, **kwargs):
    """ display the invoice done """

    user = request.user
    try:
        last_invoice = Invoice.objects.\
                            filter(organization__owner=request.user).\
                            order_by('-id')[0]
        url = reverse('PDF_invoice_done', args=[last_invoice.id])

    except IndexError:
        raise Http404

    invoiceitems = InvoiceItem.objects.filter(invoice=last_invoice.id)
    try:
        dict_header = {'date': last_invoice.date, \
                      'number': last_invoice.number,\
                      'location': last_invoice.location,\
                      'subject': last_invoice.subject,\
                      'type': last_invoice.type,\
                      'client': last_invoice.client.name,\
                      'organization': last_invoice.organization,\
                      'tax': last_invoice.tax,\
                      'tax_rate': last_invoice.tax_rate,\
                      'logo': last_invoice.organization.image
                      }
    except:
        blank_picture = Images()
        dict_header = {'date': last_invoice.date, \
                      'number': last_invoice.number,\
                      'location': last_invoice.location,\
                      'subject': last_invoice.subject,\
                      'type': last_invoice.type,\
                      'client': last_invoice.client.name,\
                      'organization': last_invoice.organization,\
                      'tax': last_invoice.tax,\
                      'tax_rate': last_invoice.tax_rate,\
                      'logo': blank_picture
                      }

    ctx = {'invoice': invoiceitems,
           'dict_header': dict_header,
           'user': user, 'url': url}
    lists, ht, comp = [], 0, 10

    for i in invoiceitems:
        dic = {}
        dic['description'] = i.description
        dic['quantity'] = i.quantity
        dic['price'] = i.price
        dic['montant'] = i.price * i.quantity
        comp -= comp
        ht += dic['montant']
        lists.append(dic)

    nb = 10 - len(lists)
    while nb != 0:
        nb = nb - 1
        lists.append({})
    ctx.update({'lists': lists, 'ht': ht})

    # On  effectue le operations avec les valeurs de l'utisateur
    #On passe le montant total au fonction cel() qui permet de le
    # convertir en lettre
    ht_en_lettre = cel(ht)

    if dict_header['tax']:
        TVA = (dict_header['tax_rate'] * ht) / 100
        TTC = ht + TVA
        ctx.update({'tva': TVA, 'ttc': TTC, 'tax': dict_header['tax_rate']})
        # si le tax est prise en compte alors c'est le TTC qui doit être
        # convertie
        ht_en_lettre = cel(TTC)
    ctx.update({"ht_en_lettre": ht_en_lettre})
    # on teste le type
    if last_invoice.type == "Facture":
        type_ = "Pour acquit: "
    else:
        type_ = "Pour acceptation: "
    ctx.update({"type_": type_})
    return render_to_response('invoice_done.html', ctx)
Exemple #5
0
def PDF_view(request, *args, **kwargs):
    """
        cette views est cree pour la generation du PDF
    """
    from datetime import datetime, timedelta
    from subprocess import Popen, PIPE
    from cStringIO import StringIO
    from reportlab.lib.pagesizes import landscape, A4, letter, portrait
    from reportlab. platypus import Image

    from super_code import controle_caratere

    user = request.user
    num = kwargs["id"] or 1
    # on recupere la facture a afficher
    invoice = Invoice.objects.get(id=num)
    #on recupere les items de la facture
    items_invoice = InvoiceItem.objects.filter(invoice=invoice.id)

    # Static source pdf to be overlayed
    PDF_SOURCE = 'media/css/images/fact1.pdf'
    DATE_FORMAT = u"%d/%m/%Y"

    DEFAULT_FONT_SIZE = 10
    FONT = 'Courier-Bold'
    # A simple function to return a leading 0 on any single digit int.

    def double_zero(value):
        try:
            return '%02d' % value
        except TypeError:
            return value

    # temporary file-like object in which to build the pdf containing
    # only the data numbers
    buffer = StringIO()

    # setup the empty canvas
    p = canvas.Canvas(buffer, pagesize=A4)
    p.setFont(FONT, DEFAULT_FONT_SIZE)

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=facture.pdf'

    # Création de l'objet PDF, en utilisant l'objet de réponse comme "fichier"
    #on afffiche l'image de l'orgamisation
    try:
        p.drawInlineImage("media/%s" % invoice.organization.image, 60, 740,\
                                                                120, 60)
    except:
        pass
    p.drawString(370, 735, str(invoice.organization))
    # On trace Une ligne horizontale
    p.line(60, 730, 535, 730)

    p.drawString(59, 25, invoice.organization.address + "- tel : " +\
                         str(invoice.organization.address_extra) + " - " +\
                         str(invoice.organization.address_extra2))

    legal_infos, legal_infos1 = controle_caratere(invoice.organization.\
                                                    legal_infos, 55, 55)

    p.drawString(90, 14, legal_infos)
    p.drawString(90, 6, legal_infos1)
    p.drawString(60, 706, str(invoice.type) + "  N°: " + str(invoice.number))
    p.drawString(370, 706, "Date: " + str(invoice.date) + \
                              " à " + str(invoice.location))
    p.drawString(60, 690, "Doit: " + (invoice.client.name))

    if invoice.subject:
        p.drawString(60, 664, "Objet: " + str(invoice.subject))

    # On ecrit les invoiceitem
    x, y = 40, 600
    for i in items_invoice:
        p.drawString(x, y, str(i.quantity).rjust(10, ' '))
        p.drawString(x + 75, y, (i.description))
        p.drawString(x + 340, y, str(i.price).rjust(10, ' '))
        p.drawString(x + 435, y, str(i.price * i.quantity).rjust(10, ' '))
        y -= 20

    # on teste le type
    if invoice.type == "Facture":
        p.drawString(59, 95, "Pour acquit: ")
    else:
        p.drawString(59, 95, "Pour acceptation: ")

    p.drawString(435, 95, "Le fournisseur: ")
    #On calcul le montant total hors taxe et sa conversion en lettre
    ht = 0
    for i in items_invoice:
        montant = i.price * i.quantity
        ht += montant
    p.drawString(476, 204, str(ht).rjust(10, ' '))
    ht_en_lettre = cel(ht)
    # Calcul du TTC avec le TVA s'il existe
    if invoice.tax:
        TVA = (invoice.tax_rate * ht) / 100
        p.drawString(476, 183.5, str(TVA).rjust(10, ' '))
        TTC = ht + TVA
        p.drawString(476, 164, str(TTC).rjust(10, ' '))
        ht_en_lettre = cel(TTC)
        ht_en_lettre1, ht_en_lettre2 = controle_caratere(ht_en_lettre +\
                                                        " FCFA", 46, 40)
        p.drawString(263.8, 133, (ht_en_lettre1))
        p.drawString(53, 120, (ht_en_lettre2))

        p.drawString(415, 183.5, str(invoice.tax_rate))

    else:
        TTC = ht
        p.drawString(476, 164, str(TTC).rjust(10, ' '))
        ht_en_lettre1, ht_en_lettre2 = controle_caratere(ht_en_lettre + \
                                                        " FCFA", 46, 40)
        p.drawString(263.8, 133, (ht_en_lettre1))
        p.drawString(53, 120, (ht_en_lettre2))
        p.drawString(415, 183.5, str(0))
        p.drawString(476, 183.5, str(0).rjust(10, ' '))
    p.showPage()
    p.save()

    cmd = '/usr/bin/pdftk %s stamp - output -' % PDF_SOURCE

    proc = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    pdf, cmderr = proc.communicate(buffer.getvalue())
    buffer.close()
    response.write(pdf)
    return response
Exemple #6
0
def show_invoice(request, *args, **kwargs):
    """ show a selected invoice in dashboard """
    user = request.user
    num = kwargs["id"] or 1
    # on recupere la facture a afficher
    invoice = Invoice.objects.get(id=num)
    #on recupere les items de la facture
    items_invoice = InvoiceItem.objects.filter(invoice=invoice.id)
    url = reverse('PDF_invoice_done', args=[invoice.id])
    try:
        dict_header = {'date': invoice.date, \
                      'number': invoice.number,\
                      'location': invoice.location,\
                      'subject': invoice.subject,\
                      'type': invoice.type,\
                      'client': invoice.client.name,\
                      'organization': invoice.organization,\
                      'tax': invoice.tax,\
                      'tax_rate': invoice.tax_rate,\
                      'logo': invoice.organization.image}
    except:
        blank_picture = Images()
        dict_header = {'date': invoice.date, \
                      'number': invoice.number,\
                      'location': invoice.location,\
                      'subject': invoice.subject,\
                      'type': invoice.type,\
                      'client': invoice.client.name,\
                      'organization': invoice.organization,\
                      'tax': invoice.tax,\
                      'tax_rate': invoice.tax_rate,\
                      'logo': blank_picture}
    c = {'invoice': invoice, 'dict_header': dict_header, 'url': url}
    lists, ht, comp = [], 0, 10
    for i in items_invoice:
        dic = {}
        dic['description'] = i.description
        dic['quantity'] = i.quantity
        dic['price'] = i.price
        dic['montant'] = i.price * i.quantity
        comp -= comp
        ht += dic['montant']
        lists.append(dic)
    nb = 10 - len(lists)

    while nb != 0:
        nb = nb - 1
        lists.append({})
    c.update({'lists': lists, 'ht': ht})
    ht_en_lettre = cel(ht)

    if dict_header['tax']:
        TVA = (dict_header['tax_rate'] * ht) / 100
        TTC = ht + TVA
        c.update({'tva': TVA, 'ttc': TTC, 'tax': dict_header['tax_rate']})
        ht_en_lettre = cel(TTC)

    c.update({"ht_en_lettre": ht_en_lettre})
    # on teste le type
    if invoice.type == "Facture":
        type_ = "Pour acquit: "
    else:
        type_ = "Pour acceptation: "
    c.update({"type_": type_})
    return render_to_response("invoice_done.html", c)
Exemple #7
0
 def test_nounits(self):
     self.assertEqual(cel(200), u"deux cent")
     self.assertEqual(cel(2000), u"deux mille")
Exemple #8
0
 def test_andeleven(self):
     self.assertEqual(cel(71), u"soixante-et-onze")
     self.assertEqual(cel(91), u"quatre-vingt onze")
Exemple #9
0
 def test_units(self):
     self.assertEqual(cel(0), u"zéro")
     self.assertEqual(cel(1), u"un")
     self.assertEqual(cel(2), u"deux")
     self.assertEqual(cel(3), u"trois")
     self.assertEqual(cel(4), u"quatre")
     self.assertEqual(cel(5), u"cinq")
     self.assertEqual(cel(6), u"six")
     self.assertEqual(cel(10), u"dix")
     self.assertEqual(cel(11), u"onze")
     self.assertEqual(cel(12), u"douze")
     self.assertEqual(cel(16), u"seize")