caluire-axel: desactivate online payement on obsolete invoices (#55803)
This commit is contained in:
parent
a11c5360e6
commit
9a9143edcc
|
@ -15,6 +15,12 @@
|
|||
# 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 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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue