nanterre: adapt state of invoices with passed payment deadline (#31829)

Tests use freezegun to fix current time, a new invoice is added whose
payment deadline has passed.

We reuse state "dépassée" from SAGA web-service specifications.
This commit is contained in:
Benjamin Dauvergne 2019-03-28 17:52:16 +01:00
parent 526a17c33c
commit 59ad8d8fc2
3 changed files with 22 additions and 6 deletions

View File

@ -16,7 +16,9 @@ def test_utils(db):
assert utils.get_next_saga_sequence() == 42
def test_tiers_saga(app, settings, nanterre_classic_family):
def test_tiers_saga(app, settings, nanterre_classic_family, freezer):
freezer.move_to('2017-10-20')
settings.ZOO_NANTERRE_APPLICATIONS['saga']['url'] = 'http://saga.example.com/ws/'
settings.ZOO_NANTERRE_APPLICATIONS['saga']['base_uri'] = 'foobar'
settings.ZOO_NANTERRE_APPLICATIONS['saga']['num_service'] = '69'
@ -86,6 +88,13 @@ def test_tiers_saga(app, settings, nanterre_classic_family):
<creance imputation="1234" montant="1.2" libelle="PISCINE" num_creance="123"/>
</creances>
</facture>
<facture date_facture="10/10/2017" date_limite_recouvrement="18/10/2017"
etat="en cours" incident_paiement="paiement" montant_initial="10.00"
reste_a_payer="1.0" num="34">
<creances>
<creance imputation="1234" montant="1.2" libelle="PISCINE" num_creance="123"/>
</creances>
</facture>
<facture date_facture="10/10/2017" date_limite_recouvrement="20/10/2017"
etat="soldée" incident_paiement="paiement" montant_initial="10.00"
reste_a_payer="2.0" num="35">
@ -145,7 +154,7 @@ def test_tiers_saga(app, settings, nanterre_classic_family):
'identifier': f['jean'].id,
}))
assert response.json['err'] == 0
assert len(response.json['data']) == 8
assert len(response.json['data']) == 10
assert response.json['data'][0]['extra']['redevable']
num = response.json['data'][0]['num']
num2 = response.json['data'][1]['num']
@ -154,7 +163,7 @@ def test_tiers_saga(app, settings, nanterre_classic_family):
'identifier': f['jean'].id,
}) + '?' + urlencode({'etats': u'tresorerie'}))
assert response.json['err'] == 0
assert len(response.json['data']) == 4
assert len(response.json['data']) == 6
response = app.get(reverse('rsu-api-saga-factures', kwargs={
'identifier': f['jean'].id,

View File

@ -39,5 +39,6 @@ deps =
httmock
pytz
faker
pytest-freezegun
commands =
py.test {env:FAST:} {env:COVERAGE:} {env:FLAKES:} {posargs:tests}

View File

@ -5,7 +5,7 @@ import decimal
import xml.etree.ElementTree as ET
from django.conf import settings
from django.utils import six
from django.utils import six, timezone
import requests
@ -162,10 +162,16 @@ class Saga(object):
def parse_date(d):
return datetime.datetime.strptime(d, '%d/%m/%Y').date()
etat = a['etat']
date_limite_recouvrement = parse_date(a['date_limite_recouvrement'])
if timezone.now().date() > date_limite_recouvrement:
etat = u'dépassée'
facture = Facture(
date_facture=parse_date(a['date_facture']),
date_limite_recouvrement=parse_date(a['date_limite_recouvrement']),
etat=a['etat'],
date_limite_recouvrement=date_limite_recouvrement,
etat=etat,
incident_paiement=a['incident_paiement'] != 'non',
montant_initial=decimal.Decimal(a['montant_initial']),
num=a['num'],