barbacompta/tests/test_facture.py

59 lines
2.1 KiB
Python

# barbacompta - invoicing for dummies
# Copyright (C) 2019-2020 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
from datetime import date
from decimal import Decimal
from eo_gestion.eo_facture.models import Client, Contrat, Facture
def test_contrat_montant_par_annee_percentage_per_year(db, django_user_model, freezer):
freezer.move_to('2021-06-01')
client = Client.objects.create(nom=str(uuid.uuid4()))
user = django_user_model.objects.all()[0]
contrat = Contrat.objects.create(
client=client,
creator=user,
intitule=str(uuid.uuid4()),
percentage_per_year=[(2020, Decimal(0.5)), (2021, Decimal(0.25)), (2022, Decimal(0.25))],
)
contrat.clean()
for i in range(10):
contrat.prestations.create(intitule=str(i), quantite=1, prix_unitaire_ht=1000)
facture = Facture.objects.create(
proforma=False,
client=client,
contrat=contrat,
emission=date(2020, 1, 1),
echeance=date(2020, 1, 16),
creator=user,
)
facture.lignes.create(prix_unitaire_ht=1000, quantite=1, order=1)
facture = Facture.objects.create(
proforma=False,
client=client,
contrat=contrat,
emission=date(2021, 1, 1),
echeance=date(2021, 1, 16),
creator=user,
)
facture.lignes.create(prix_unitaire_ht=1000, quantite=1, order=1)
assert sorted(list(contrat.montant_par_annee().items())) == [(2021, Decimal(5500)), (2022, Decimal(2500))]