diff --git a/passerelle/contrib/caluire_axel/utils.py b/passerelle/contrib/caluire_axel/utils.py index 12a78354..63da6c1e 100644 --- a/passerelle/contrib/caluire_axel/utils.py +++ b/passerelle/contrib/caluire_axel/utils.py @@ -15,6 +15,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import datetime + +from django.utils.timezone import localtime + +from passerelle.contrib.utils import axel + def get_reference_year_from_date(booking_date): if booking_date.month <= 8: @@ -48,12 +54,16 @@ def normalize_invoice(invoice, family_id, historical=False, vendor_base=None): } ) else: + date_now = localtime().date() + date_pay_limit = datetime.datetime.strptime(invoice['ECHEANCE'], axel.json_date_format).date() data.update( { 'amount': max(0, invoice['MONTANT'] - invoice['ENCAISSE']), 'amount_paid': invoice['ENCAISSE'], 'pay_limit_date': invoice['ECHEANCE'], - 'online_payment': bool(invoice['MONTANT'] - invoice['ENCAISSE'] > 0), + 'online_payment': bool( + invoice['MONTANT'] - invoice['ENCAISSE'] > 0 and date_now <= date_pay_limit + ), } ) return data diff --git a/tests/test_caluire_axel.py b/tests/test_caluire_axel.py index c524d08a..e2eb53d7 100644 --- a/tests/test_caluire_axel.py +++ b/tests/test_caluire_axel.py @@ -2778,6 +2778,7 @@ def test_invoices_endpoint_no_invoice(app, resource): assert resp.json['data'] == [] +@freezegun.freeze_time('2019-12-05') def test_invoices_endpoint(app, resource): Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42') filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml') @@ -2802,7 +2803,7 @@ def test_invoices_endpoint(app, resource): 'amount': '4.94', 'total_amount': '44.94', 'amount_paid': '40.00', - 'online_payment': True, + 'online_payment': False, 'created': '2019-11-12', 'pay_limit_date': '2019-12-04', 'has_pdf': True, @@ -3035,6 +3036,7 @@ def test_invoice_endpoint_no_result(app, resource): assert resp.json['err'] == 'not-found' +@freezegun.freeze_time('2019-12-04') def test_invoice_endpoint(app, resource): Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42') filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')