from paramecio2.libraries.db.corefields import FloatField
from decimal import Decimal, getcontext
from locale import format_string

getcontext().prec=2

class MoneyField(FloatField):
    
    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)        

