use locale to format currency

This commit is contained in:
2020-10-17 08:25:56 +02:00
parent 71305e8002
commit 6bc9d34fde
4 changed files with 17 additions and 18 deletions

View File

@@ -69,9 +69,9 @@
<th class="text-right">TVA</th> <th class="text-right">TVA</th>
</tr> </tr>
<tr> <tr>
<td class="text-right">${layout.to_decz(dossier.TOTALHT)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALHT)}</td>
<td class="text-right">${layout.to_euroz(dossier.TOTALTVA)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALTVA)}</td>
<td class="text-right">${layout.to_euroz(dossier.TOTALTTC)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALTTC)}</td>
<td class="text-right">${dossier.TAUXTVA} %</td> <td class="text-right">${dossier.TAUXTVA} %</td>
</tr> </tr>
</table> </table>
@@ -88,7 +88,7 @@
<tr tal:repeat="detail details"> <tr tal:repeat="detail details">
<td>${detail.REF}</td> <td>${detail.REF}</td>
<td>${detail.LIB}</td> <td>${detail.LIB}</td>
<td class="text-right">${layout.to_decz(detail.QTE)}</td> <td class="text-right">${layout.to_euro(detail.QTE)}</td>
<td class="text-right">${layout.to_euroz(detail.PRIXHT)}</td> <td class="text-right">${layout.to_euroz(detail.PRIXHT)}</td>
<td class="text-right">${layout.to_euroz(detail.MTHT)}</td> <td class="text-right">${layout.to_euroz(detail.MTHT)}</td>
<td class="text-center">${detail.USERMAJ}</td> <td class="text-center">${detail.USERMAJ}</td>

View File

@@ -44,9 +44,9 @@
<th class="text-right">TVA</th> <th class="text-right">TVA</th>
</tr> </tr>
<tr> <tr>
<td class="text-right">${layout.to_decz(dossier.TOTALHT)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALHT)}</td>
<td class="text-right">${layout.to_euroz(dossier.TOTALTVA)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALTVA)}</td>
<td class="text-right">${layout.to_euroz(dossier.TOTALTTC)}</td> <td class="text-right">${layout.to_euro(dossier.TOTALTTC)}</td>
<td class="text-right">${dossier.TAUXTVA} %</td> <td class="text-right">${dossier.TAUXTVA} %</td>
</tr> </tr>
</table> </table>

View File

@@ -17,12 +17,13 @@ from pyramid.httpexceptions import (
from pyramid_mailer import get_mailer from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message, Attachment from pyramid_mailer.message import Message, Attachment
from datetime import * from datetime import *
import hashlib
from sqlalchemy.exc import DBAPIError from sqlalchemy.exc import DBAPIError
from ..security import groupfinder from ..security import groupfinder
from user_agents import parse from user_agents import parse
import json import json
import locale
import hashlib
from ..models.default import * from ..models.default import *
from ..models.agenda import * from ..models.agenda import *
@@ -37,25 +38,23 @@ def to_decimal(x):
def to_euro(x): def to_euro(x):
"""Takes a float and returns a string""" """Takes a float and returns a string"""
#if x == 0: locale.setlocale(locale.LC_ALL,'')
# return "" return locale.currency(x, True, True)
#else:
return ("%.2f" % x).replace('.', ',')
def to_euroz(x): def to_euroz(x):
"""Takes a float and returns a string""" """Takes a float and returns a string"""
if x == 0: if x == 0:
return "" return ""
else: else:
return ("%9.2f" % x).replace('.', ',') return to_euro(x)
def to_decz(x): def to_decz(x):
"""Takes a decimal and returns a string""" """Takes a float and returns a number with 2 dec"""
locale.setlocale(locale.LC_ALL,'')
if x == 0: if x == 0:
return "" return ""
else: else:
return ("%.2f" % x).replace('.', ',') return locale.format_string('%.2f',x, False)
def to_sha1(message): def to_sha1(message):
return hashlib.sha1(message.encode('utf-8')).hexdigest() return hashlib.sha1(message.encode('utf-8')).hexdigest()

View File

@@ -305,8 +305,8 @@ def devis_preview(request):
dt_html += '<i>%s</i><br />' % ligne.deduction dt_html += '<i>%s</i><br />' % ligne.deduction
dt_html += '</p></div>' dt_html += '</p></div>'
dt_html += '<div class="col-sm-1"><p class="text-right">%s</p></div>' % ligne.qte dt_html += '<div class="col-sm-1"><p class="text-right">%s</p></div>' % ligne.qte
dt_html += '<div class="col-sm-2"><p class="text-right">%s</p></div>' % ligne.prixht dt_html += '<div class="col-sm-2"><p class="text-right">%s</p></div>' % to_euro(ligne.prixht)
dt_html += '<div class="col-sm-2"><p class="text-right">%s</p></div>' % ligne.mtht dt_html += '<div class="col-sm-2"><p class="text-right">%s</p></div>' % to_euro(ligne.mtht)
return { return {
'page_title': '', 'page_title': '',