toulouse-maelis: correct for-payment parameter usage (#77110)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5cd1e3aacc
commit
979e531b3a
|
@ -4204,7 +4204,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
for i in self.get_invoices(family_id, regie_id)
|
||||
if i.status() in ['paid', 'notified']
|
||||
]
|
||||
return {'data': invoices}
|
||||
return {'has_invoice_for_payment': True, 'data': invoices}
|
||||
|
||||
def get_invoice(self, regie_id, invoice_id):
|
||||
real_invoice_id = invoice_id.split('-')[-1]
|
||||
|
@ -4226,16 +4226,17 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
parameters={
|
||||
'regie_id': {'description': 'Identifiant de la régie', 'example_value': '102'},
|
||||
'invoice_id': {'description': 'Identifiant de facture', 'example_value': 'IDFAM-42'},
|
||||
'for_payment': {
|
||||
'payment': {
|
||||
'description': "Si présent, annuler la facture panier à l'expiration du delai maximum de paiement depuis la date de l'appel"
|
||||
},
|
||||
},
|
||||
)
|
||||
def invoice(self, request, regie_id, invoice_id, for_payment=None, **kwargs):
|
||||
def invoice(self, request, regie_id, invoice_id, payment=None, **kwargs):
|
||||
invoice = self.get_invoice(regie_id, invoice_id)
|
||||
if invoice.status() == 'cancelled':
|
||||
raise APIError('Invoice cancelled')
|
||||
if for_payment is not None:
|
||||
|
||||
if payment is not None and invoice.status() in ['created']:
|
||||
invoice.start_payment_date = now()
|
||||
invoice.save()
|
||||
if invoice.status() == 'cancelling':
|
||||
|
|
|
@ -10137,7 +10137,6 @@ def test_cancel_basket_invoice_cron_having_for_payment_date(
|
|||
request_check=request_check,
|
||||
)
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
assert con.cancel_invoice_delay == 30
|
||||
assert con.max_payment_delay == 20
|
||||
|
||||
# invoice created on validate basket
|
||||
|
@ -10151,32 +10150,46 @@ def test_cancel_basket_invoice_cron_having_for_payment_date(
|
|||
assert invoice.basket_generation_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:30:00'
|
||||
assert invoice.maelis_cancel_notification_date is None
|
||||
|
||||
# invoice is payable
|
||||
resp = app.get(get_endpoint('regie/109/invoices') + '?family_id=1312')
|
||||
assert resp.json['err'] == 0
|
||||
assert '1312-18' in [x['id'] for x in resp.json['data']]
|
||||
assert resp.json['data'][0]['online_payment'] is True
|
||||
|
||||
# notificate payment starts
|
||||
freezer.move_to('2023-03-03 18:40:00')
|
||||
resp = app.get(get_endpoint('regie/109/invoice/1312-18') + '?for_payment')
|
||||
freezer.move_to('2023-03-03 18:35:00')
|
||||
resp = app.get(get_endpoint('regie/109/invoice/1312-18') + '?payment')
|
||||
assert resp.json['err'] == 0
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.start_payment_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:40:00'
|
||||
assert invoice.start_payment_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:35:00'
|
||||
|
||||
# invoice is still displayed before cancellation order is sent to maelis
|
||||
# (but no more payable)
|
||||
con.cancel_basket_invoices()
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.status() == 'for_payment'
|
||||
assert invoice.maelis_cancel_notification_date is None
|
||||
|
||||
# invoice is no more payable
|
||||
resp = app.get(get_endpoint('regie/109/invoices') + '?family_id=1312')
|
||||
assert resp.json['err'] == 0
|
||||
assert '1312-18' in [x['id'] for x in resp.json['data']]
|
||||
assert resp.json['data'][0]['online_payment'] is False
|
||||
|
||||
# start payment date is not updated on furter invoice call providing '?payment'
|
||||
freezer.move_to('2023-03-03 18:40:00')
|
||||
resp = app.get(get_endpoint('regie/109/invoice/1312-18') + '?payment')
|
||||
assert resp.json['err'] == 0
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.start_payment_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:35:00'
|
||||
|
||||
# cancellation order is now sent to maelis
|
||||
freezer.move_to('2023-03-03 19:10:00')
|
||||
freezer.move_to('2023-03-03 18:55:00')
|
||||
con.cancel_basket_invoices()
|
||||
assert caplog.records[-1].levelno == logging.INFO
|
||||
assert caplog.records[-1].message == 'Annulation de <Invoice "109/18"> sur la famille \'1312\''
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.status() == 'cancelled'
|
||||
assert invoice.maelis_cancel_notification_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 19:10:00'
|
||||
assert invoice.maelis_cancel_notification_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:55:00'
|
||||
|
||||
|
||||
def test_cancel_basket_invoice_cron_keep_paid_invoices(
|
||||
|
@ -10735,6 +10748,7 @@ def test_invoices_history(invoice_service, con, app):
|
|||
|
||||
resp = app.get(url + '?NameID=local')
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['has_invoice_for_payment'] is True
|
||||
for invoice in resp.json['data']:
|
||||
assert invoice['display_id']
|
||||
assert invoice['label']
|
||||
|
@ -10911,7 +10925,7 @@ def test_invoice_for_payment(activity_service, invoice_service, con, app, freeze
|
|||
)
|
||||
invoice_service.add_soap_response('readInvoices', get_xml_file('R_read_invoices_regie_109.xml'))
|
||||
url = get_endpoint('regie/109/invoice/1312-18')
|
||||
assert con.cancel_invoice_delay == 30
|
||||
assert con.max_payment_delay == 20
|
||||
|
||||
# invoice created on validate basket
|
||||
freezer.move_to('2023-03-03 18:30:00')
|
||||
|
@ -10920,15 +10934,22 @@ def test_invoice_for_payment(activity_service, invoice_service, con, app, freeze
|
|||
)
|
||||
assert resp.json['err'] == 0
|
||||
|
||||
resp = app.get(url + '?NameID=ignored&for_payment')
|
||||
# invoice is payable
|
||||
resp = app.get(get_endpoint('regie/109/invoices') + '?family_id=1312')
|
||||
assert resp.json['err'] == 0
|
||||
assert '1312-18' in [x['id'] for x in resp.json['data']]
|
||||
assert resp.json['data'][0]['online_payment'] is True
|
||||
|
||||
# notificate payment starts
|
||||
freezer.move_to('2023-03-03 18:35:00')
|
||||
resp = app.get(url + '?NameID=ignored&payment')
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data']['display_id'] == '18'
|
||||
assert resp.json['data']['label'] == 'DSBL TEST'
|
||||
|
||||
# basket invoice is still returned but is no more payable
|
||||
freezer.move_to('2023-03-03 18:50:00')
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.start_payment_date is not None
|
||||
assert invoice.start_payment_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:35:00'
|
||||
assert invoice.status() == 'for_payment'
|
||||
resp = app.get(url + '?NameID=local')
|
||||
assert resp.json['err'] == 0
|
||||
|
@ -10937,7 +10958,21 @@ def test_invoice_for_payment(activity_service, invoice_service, con, app, freeze
|
|||
assert resp.json['data']['online_payment'] is False
|
||||
assert resp.json['data']['no_online_payment_reason'] == 'Transation de payement en cours'
|
||||
|
||||
# invoice is no more payable
|
||||
resp = app.get(get_endpoint('regie/109/invoices') + '?family_id=1312')
|
||||
assert resp.json['err'] == 0
|
||||
assert '1312-18' in [x['id'] for x in resp.json['data']]
|
||||
assert resp.json['data'][0]['online_payment'] is False
|
||||
|
||||
# start payment date is not updated on furter invoice call providing '?payment'
|
||||
freezer.move_to('2023-03-03 18:40:00')
|
||||
resp = app.get(get_endpoint('regie/109/invoice/1312-18') + '?payment')
|
||||
assert resp.json['err'] == 0
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.start_payment_date.strftime('%Y-%m-%d %H:%M:%S') == '2023-03-03 18:35:00'
|
||||
|
||||
# basket invoice is no more returned since cancellation order sent to maelis
|
||||
freezer.move_to('2023-03-03 18:55:00')
|
||||
con.cancel_basket_invoices()
|
||||
invoice = con.invoice_set.get(regie_id=109, invoice_id=18)
|
||||
assert invoice.status() == 'cancelled'
|
||||
|
|
Loading…
Reference in New Issue