Esempio n. 1
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
Esempio n. 2
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
     ]
Esempio n. 3
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
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
Esempio n. 5
0
 def test_insert(
     self, dbsession, income_statement_measure_type_category
 ):
     from autonomie.models.accounting.income_statement_measures import (
         IncomeStatementMeasureType,
     )
     types_ = self.get_them(
         dbsession, income_statement_measure_type_category
     )
     IncomeStatementMeasureType.insert(types_[0], 2)
     assert types_[1].order == 0
     assert types_[0].order == 2
     assert types_[2].order == 1
 def get_types(self):
     """
     Collect active income statement measure types
     """
     clause = IncomeStatementMeasureType.active == True
     return IncomeStatementMeasureType.query().filter(clause).order_by(
         IncomeStatementMeasureType.order).all()
Esempio n. 7
0
 def on_enable(self):
     """
     on enable we set order to 1
     """
     order = IncomeStatementMeasureType.get_next_order_by_category(
         self.context.category_id)
     self.context.order = order
     self.request.dbsession.merge(self.context)
Esempio n. 8
0
    def test_reorder(
        self, dbsession, income_statement_measure_type_category
    ):
        from autonomie.models.accounting.income_statement_measures import (
            IncomeStatementMeasureType,
        )
        types_ = self.get_them(
            dbsession, income_statement_measure_type_category
        )
        types_[2].order = 18
        IncomeStatementMeasureType.reorder(
            income_statement_measure_type_category.id
        )

        assert types_[2].order == 3
        assert types_[3].order == 2
        assert types_[-1].order == 1
 def on_enable(self):
     """
     on enable we set order to 1
     """
     order = IncomeStatementMeasureType.get_next_order_by_category(
         self.context.category_id
     )
     self.context.order = order
     self.request.dbsession.merge(self.context)
Esempio n. 10
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
Esempio n. 11
0
 def test_get_next_order_by_category(
     self, dbsession, income_statement_measure_type_category
 ):
     from autonomie.models.accounting.income_statement_measures import (
         IncomeStatementMeasureType,
     )
     self.get_them(
         dbsession, income_statement_measure_type_category
     )
     assert IncomeStatementMeasureType.get_next_order_by_category(
         income_statement_measure_type_category.id
     ) == 4
Esempio n. 12
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_
Esempio n. 13
0
def deferred_complexe_total_description(node, kw):
    categories = ",".join([
        i.label for i in IncomeStatementMeasureTypeCategory.get_categories(
            keys=('label', ))
    ])
    types = ",".join(
        (i.label
         for i in IncomeStatementMeasureType.get_types(keys=('label', ))))

    return u"""
Combiner plusieurs catégories et indicateurs au travers d'opérations
arithmétiques.
Les noms des variables (catégories ou indicateurs) doivent être encadrés de {}.
Exemple : {Salaires et Cotisations} + {Charges} / 100.
Liste des catégories : %s. Liste des indicateurs : %s""" % (categories, types)
Esempio n. 14
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')
Esempio n. 15
0
def deferred_complexe_total_description(node, kw):
    categories = ",".join(
        [i.label for i in
         IncomeStatementMeasureTypeCategory.get_categories(keys=('label',))
         ]
    )
    types = ",".join((
        i.label
        for i in IncomeStatementMeasureType.get_types(keys=('label',))
    ))

    return u"""
Combiner plusieurs catégories et indicateurs au travers d'opérations
arithmétiques.
Les noms des variables (catégories ou indicateurs) doivent être encadrés de {}.
Exemple : {Salaires et Cotisations} + {Charges} / 100.
Liste des catégories : %s. Liste des indicateurs : %s""" % (categories, types)
Esempio n. 16
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_
Esempio n. 17
0
 def __init__(self, *args, **kwargs):
     AdminCrudListView.__init__(self, *args, **kwargs)
     self.max_order = IncomeStatementMeasureType.get_next_order_by_category(
         self.context.id) - 1
Esempio n. 18
0
 def on_delete(self):
     """
     On disable we reset the order
     """
     IncomeStatementMeasureType.reorder(self.context.category_id)
 def __init__(self, *args, **kwargs):
     AdminCrudListView.__init__(self, *args, **kwargs)
     self.max_order = IncomeStatementMeasureType.get_next_order_by_category(
         self.context.id
     ) - 1
Esempio n. 20
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
 def on_delete(self):
     """
     On disable we reset the order
     """
     IncomeStatementMeasureType.reorder(self.context.category_id)