Exemple #1
0
    def test_compute_total(
        self, dbsession, income_statement_measure_type_category
    ):
        from autonomie.models.accounting.income_statement_measures import (
            IncomeStatementMeasureType,
        )
        type_ = IncomeStatementMeasureType(
            account_prefix="-100 / {Salaires (et Cotisations)}",
            is_total=True,
            total_type="complex_total",
        )
        # - 3.33333
        assert 3.34 + type_.compute_total(
            {'Salaires (et Cotisations)': 30, 'other': 2}
        ) < 0.01

        assert type_.compute_total({'other': 2}) == 0
        assert type_.compute_total({'Salaires (et Cotisations)': 0}) == 0

        type_ = IncomeStatementMeasureType(
            account_prefix="-100 / {Salaires:Cotisations}",
            is_total=True,
            total_type="complex_total",
        )
        # Wrong syntax
        assert type_.compute_total({'Salaires:Cotisations': 15}) == 0

        type_ = IncomeStatementMeasureType(
            account_prefix="Achats,Produits,Salaires",
            is_total=True,
            total_type="categories",
        )
        assert type_.compute_total(
            {'Achats': 30, 'Produits': 50, 'other': 2}
        ) == 80
Exemple #2
0
def income_measure_types(dbsession, income_measure_type_categories):
    from autonomie.models.accounting.income_statement_measures import (
        IncomeStatementMeasureType,
    )
    types = []
    for (
        label, category_index, account_prefix, is_total, total_type
    ) in (
        ('Label 1', 0, u"701", False, ""),
        ('Label 2', 0, u"701,702", False, ""),
        ('Label 3', 1, u"601", False, ""),
        ('Total partiel autres achats', 1, u"6,-601", True, "account_prefix"),
        ('Total produits et achats', 1, u"Produits,Achats", True, "categories"),
        ('Ratio produits et achats', 1, u"{Achats} * 100 / {Produits}", True,
         "complex_total"),
        (
            'Formule de test',
            1,
            u"({Label 1} + {Label 2} + {Label 3})",
            True,
            "complex_total"
        ),
    ):
        typ = IncomeStatementMeasureType(
            label=label,
            category_id=income_measure_type_categories[category_index].id,
            account_prefix=account_prefix,
            is_total=is_total,
            total_type=total_type,
        )
        dbsession.add(typ)
        typ.category = income_measure_type_categories[category_index]
        types.append(typ)
    return types
Exemple #3
0
 def test_get_categories(self, income_statement_measure_type_category):
     from autonomie.models.accounting.income_statement_measures import (
         IncomeStatementMeasureType,
     )
     type_ = IncomeStatementMeasureType(
         account_prefix="Wrong,label_1"
     )
     assert type_.get_categories() == [
         income_statement_measure_type_category
     ]
Exemple #4
0
 def test_match(self):
     from autonomie.models.accounting.income_statement_measures import (
         IncomeStatementMeasureType,
     )
     type_ = IncomeStatementMeasureType(
         account_prefix="7,-766,654"
     )
     assert type_.match('725')
     assert not type_.match('76666')
     assert not type_.match('1')
     assert type_.match('654')
Exemple #5
0
def income_measure_type(dbsession, income_measure_type_category):
    from autonomie.models.accounting.income_statement_measures import (
        IncomeStatementMeasureType, )
    typ = IncomeStatementMeasureType(
        label="Label 1",
        category_id=income_measure_type_category.id,
        account_prefix="701",
    )
    dbsession.add(typ)
    dbsession.flush()
    typ.category = income_measure_type_category
    return typ
Exemple #6
0
    def test_computed_total(self):
        from autonomie.models.accounting.income_statement_measures import (
            IncomeStatementMeasureType,
        )
        type_ = IncomeStatementMeasureType(
            is_total=True,
            total_type="account_prefix"
        )
        assert not type_.computed_total

        type_ = IncomeStatementMeasureType(
            is_total=True,
            total_type="complex_total"
        )
        assert type_.computed_total

        type_ = IncomeStatementMeasureType(
            is_total=True,
            total_type="categories"
        )
        assert type_.computed_total
Exemple #7
0
def income_statement_measure_type(dbsession, cat):
    from autonomie.models.accounting.income_statement_measures import (
        IncomeStatementMeasureType,
    )
    type_ = IncomeStatementMeasureType(
        order=1,
        category_id=cat.id,
        label=u"label",
        account_prefix="706",
    )
    dbsession.add(type_)
    dbsession.flush()
    return type_
Exemple #8
0
    def get_them(self, dbsession, cat):
        from autonomie.models.accounting.income_statement_measures import (
            IncomeStatementMeasureTypeCategory,
            IncomeStatementMeasureType,
        )
        cat2 = IncomeStatementMeasureTypeCategory(label='label_2', order=2)
        dbsession.add(cat2)
        dbsession.flush()

        types_ = [
            IncomeStatementMeasureType(
                order=i,
                label="label_%s" % i,
                category_id=cat.id
            )
            for i in range(5)
        ]
        types_[-1].category_id = cat2.id
        types_[-1].order = 1
        for type_ in types_:
            dbsession.add(type_)
        dbsession.flush()
        return types_