27 lines
625 B
Python
27 lines
625 B
Python
from paramecio2.libraries.db.corefields import DecimalField
|
|
from decimal import Decimal, getcontext
|
|
from locale import format_string
|
|
|
|
getcontext().prec=2
|
|
|
|
class MoneyField(DecimalField):
|
|
|
|
def __init__(self, name, required=False):
|
|
|
|
super().__init__(name, 11, required)
|
|
|
|
def check(self, value):
|
|
|
|
value=Decimal(value)
|
|
|
|
return value
|
|
|
|
def show_formatted(self, value):
|
|
|
|
return format_string('%.2f', Decimal(value), grouping=True)
|
|
|
|
@staticmethod
|
|
def format_money(value):
|
|
return format_string('%.2f', Decimal(value), grouping=True)
|
|
|
|
|