Exemplo n.º 1
0
 def _round_products(self):
     """
         Round the products ht and tva
     """
     for value in self.products.values():
         value['ht'] = floor_to_precision(value['ht'])
         value['tva'] = floor_to_precision(value['tva'])
 def test_floor_to_precision(self):
     a = 299999
     self.assertEqual(floor_to_precision(a), 300000)
     a = 299455
     self.assertEqual(floor_to_precision(a), 299000)
     a = 299999
     self.assertEqual(floor_to_precision(a, round_floor=True), 299000)
Exemplo n.º 3
0
def format_amount(amount, trim=True, grouping=True, precision=2):
    """
        return a pretty printable amount
    """
    resp = u""
    if amount is not None:
        dividor = 10.0 ** precision

        # Limit to 2 trailing zeros
        if isinstance(amount, float) and precision <= 2:
            if amount == int(amount):
                trim = True
        elif precision > 2:
            if math_utils.floor_to_precision(
                amount,
                precision=2,
                dialect_precision=precision
            ) == amount:
                trim = True

        if trim:
            formatter = "%.2f"
            amount = int(amount) / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
        else:
            formatter = "%.{0}f".format(precision)
            amount = amount / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
            resp = resp.rstrip('0')
            resp = add_trailing_zeros(resp)

    if grouping:
        resp = resp.replace(' ', '&nbsp;')
    return resp
Exemplo n.º 4
0
    def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            )
        )

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append(
                {
                    'tva_id': tva.id,
                    'amount': floor_to_precision(
                        value,
                        precision=2,
                        dialect_precision=5
                    )
                }
            )

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
Exemplo n.º 5
0
    def test_manual_payment_line_amounts(self):
        def compute_payment_ttc(payment):
            total = 0
            for tva, ht in payment.items():
                line = DummyLine(tva=tva, cost=ht)
                total += line.total()
            return total

        task = self.getOne()
        task.manualDeliverables = 1
        payments = task.manual_payment_line_amounts()
        assert payments[0].keys() == [1960]
        assert payments[1].keys() == [1960, 500]
        assert payments[2].keys() == [500]
        deposit = task.deposit_amount_ttc()
        amount1 = compute_payment_ttc(payments[0])
        amount2 = compute_payment_ttc(payments[1])
        assert math_utils.floor(amount1) == 4000000
        assert math_utils.floor(amount2) == 6000000
        total = task.sold() + deposit + amount1 + amount2
        assert math_utils.floor_to_precision(total) == task.total()
Exemplo n.º 6
0
    def test_manual_payment_line_amounts(self):
        def compute_payment_ttc(payment):
            total = 0
            for tva, ht in payment.items():
                line = DummyLine(tva=tva, cost=ht)
                total += line.total()
            return total

        task = self.getOne()
        task.manualDeliverables = 1
        payments = task.manual_payment_line_amounts()
        assert payments[0].keys() == [1960]
        assert payments[1].keys() == [1960, 500]
        assert payments[2].keys() == [500]
        deposit = task.deposit_amount_ttc()
        amount1 = compute_payment_ttc(payments[0])
        amount2 = compute_payment_ttc(payments[1])
        assert math_utils.floor(amount1) == 4000000
        assert math_utils.floor(amount2) == 6000000
        total = task.sold() + deposit + amount1 + amount2
        assert math_utils.floor_to_precision(total) == task.total()
Exemplo n.º 7
0
def format_amount(amount, trim=True, grouping=True, precision=2, dividor=None):
    """
        return a pretty printable amount
    """
    resp = u""
    if amount is not None:
        if dividor is None:
            dividor = 10.0 ** precision

        # Limit to 2 trailing zeros
        if isinstance(amount, float) and precision <= 2:
            if amount == int(amount):
                trim = True
        elif precision > 2:
            if math_utils.floor_to_precision(
                amount,
                precision=2,
                dialect_precision=precision
            ) == amount:
                trim = True

        if trim:
            formatter = "%.2f"
            amount = int(amount) / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
        else:
            formatter = "%.{0}f".format(precision)
            amount = amount / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
            resp = resp.rstrip('0')
            resp = add_trailing_zeros(resp)

        if grouping:
            resp = resp.replace(' ', '&nbsp;')
            resp = resp.replace("\xe2\x80\xaf", "&nbsp;")

        if isinstance(resp, str):
            resp = resp.decode('utf-8')

    return resp
Exemplo n.º 8
0
    def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            ))

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append({
                'tva_id':
                tva.id,
                'amount':
                floor_to_precision(value, precision=2, dialect_precision=5)
            })

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
Exemplo n.º 9
0
 def floor(self, amount):
     return math_utils.floor_to_precision(amount, self.round_floor)
Exemplo n.º 10
0
    2456125,
    4410000,
    -1019200,
)  # 0.392, 0.588)

LINES_TOTAL_HT = sum(TASK_LINES_TOTAL_HT) * 2
LINES_TOTAL_TVAS = sum(TASK_LINES_TVAS) * 2
EXPENSE_TVA = 196000

DISCOUNT_TOTAL_HT = sum([d['amount'] for d in DISCOUNTS])
DISCOUNT_TVAS = (392000, )
DISCOUNT_TOTAL_TVAS = sum(DISCOUNT_TVAS)

# Totals should be multiple of 1000 (ending to be floats with 2 numbers after
# the comma
HT_TOTAL = math_utils.floor_to_precision(LINES_TOTAL_HT - DISCOUNT_TOTAL_HT +
                                         TASK['expenses_ht'])
TVA = math_utils.floor_to_precision(LINES_TOTAL_TVAS - DISCOUNT_TOTAL_TVAS +
                                    EXPENSE_TVA)

# TASK_TOTAL = lines + tva + expenses rounded
TASK_TOTAL = HT_TOTAL + TVA + TASK['expenses']


class DummyLine(Dummy, LineCompute):
    """
        Dummy line model
    """
    pass


class DummyGroup(Dummy, GroupCompute):
Exemplo n.º 11
0
 def floor(self, amount):
     return math_utils.floor_to_precision(amount, self.round_floor)
Exemplo n.º 12
0
from autonomie.tests.base import Dummy
TASK_LINES_TOTAL_HT = (12531250.0, 22500000, -5200000, ) # 2, 3 )
TASK_LINES_TVAS = (2456125, 4410000, -1019200, )  # 0.392, 0.588)

LINES_TOTAL_HT = sum(TASK_LINES_TOTAL_HT) * 2
LINES_TOTAL_TVAS = sum(TASK_LINES_TVAS) * 2
EXPENSE_TVA = 196000

DISCOUNT_TOTAL_HT = sum([d['amount']for d in DISCOUNTS])
DISCOUNT_TVAS = (392000,)
DISCOUNT_TOTAL_TVAS = sum(DISCOUNT_TVAS)

# Totals should be multiple of 1000 (ending to be floats with 2 numbers after
# the comma
HT_TOTAL =  math_utils.floor_to_precision(
    LINES_TOTAL_HT - DISCOUNT_TOTAL_HT + TASK['expenses_ht']
)
TVA = math_utils.floor_to_precision(
    LINES_TOTAL_TVAS - DISCOUNT_TOTAL_TVAS + EXPENSE_TVA
)

# TASK_TOTAL = lines + tva + expenses rounded
TASK_TOTAL = HT_TOTAL + TVA + TASK['expenses']


class DummyLine(Dummy, LineCompute):
    """
        Dummy line model
    """
    pass