Projet

Général

Profil

0001-caluire-axel-desactivate-online-payement-on-obsolete.patch

Nicolas Roche, 23 juillet 2021 18:03

Télécharger (4,57 ko)

Voir les différences:

Subject: [PATCH] caluire-axel: desactivate online payement on obsolete
 invoices (#55803)

 passerelle/contrib/caluire_axel/utils.py | 12 +++++++++++-
 tests/test_caluire_axel.py               |  4 +++-
 2 files changed, 14 insertions(+), 2 deletions(-)
passerelle/contrib/caluire_axel/utils.py
10 10
# This program is distributed in the hope that it will be useful,
11 11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 13
# GNU Affero General Public License for more details.
14 14
#
15 15
# You should have received a copy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18
import datetime
19

  
20
from django.utils.timezone import localtime, now
21

  
22
from passerelle.contrib.utils import axel
23

  
18 24

  
19 25
def get_reference_year_from_date(booking_date):
20 26
    if booking_date.month <= 8:
21 27
        # between january and august, reference year is the year just before
22 28
        return booking_date.year - 1
23 29
    return booking_date.year
24 30

  
25 31

  
......
43 49
        data.update(
44 50
            {
45 51
                'amount': 0,
46 52
                'pay_limit_date': '',
47 53
                'online_payment': False,
48 54
            }
49 55
        )
50 56
    else:
57
        date_now = localtime(now()).date()
58
        date_pay_limit = datetime.datetime.strptime(invoice['ECHEANCE'], axel.json_date_format).date()
51 59
        data.update(
52 60
            {
53 61
                'amount': max(0, invoice['MONTANT'] - invoice['ENCAISSE']),
54 62
                'amount_paid': invoice['ENCAISSE'],
55 63
                'pay_limit_date': invoice['ECHEANCE'],
56
                'online_payment': bool(invoice['MONTANT'] - invoice['ENCAISSE'] > 0),
64
                'online_payment': bool(
65
                    invoice['MONTANT'] - invoice['ENCAISSE'] > 0 and date_now <= date_pay_limit
66
                ),
57 67
            }
58 68
        )
59 69
    return data
tests/test_caluire_axel.py
2773 2773
    </GETFACTURESAPAYER>
2774 2774
</PORTAIL>'''
2775 2775
    with mock_data(content, 'GetFacturesaPayer'):
2776 2776
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoices?NameID=yyy')
2777 2777
    assert resp.json['err'] == 0
2778 2778
    assert resp.json['data'] == []
2779 2779

  
2780 2780

  
2781
@freezegun.freeze_time('2019-12-05')
2781 2782
def test_invoices_endpoint(app, resource):
2782 2783
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
2783 2784
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
2784 2785
    with open(filepath) as xml:
2785 2786
        content = (
2786 2787
            '''
2787 2788
<PORTAIL>
2788 2789
  <GETFACTURESAPAYER>
......
2797 2798
    assert resp.json['data'] == [
2798 2799
        {
2799 2800
            'id': 'XXX-42',
2800 2801
            'display_id': '42',
2801 2802
            'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
2802 2803
            'amount': '4.94',
2803 2804
            'total_amount': '44.94',
2804 2805
            'amount_paid': '40.00',
2805
            'online_payment': True,
2806
            'online_payment': False,
2806 2807
            'created': '2019-11-12',
2807 2808
            'pay_limit_date': '2019-12-04',
2808 2809
            'has_pdf': True,
2809 2810
            'paid': False,
2810 2811
            'vendor': {
2811 2812
                'caluire-axel': {
2812 2813
                    'IDFACTURE': 42,
2813 2814
                    'MONTANT': '44.94',
......
3030 3031
        % invoices
3031 3032
    )
3032 3033
    with mock_data(content, 'GetListFactures'):
3033 3034
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-44?NameID=yyy')
3034 3035
    assert resp.json['err_desc'] == "Invoice not found"
3035 3036
    assert resp.json['err'] == 'not-found'
3036 3037

  
3037 3038

  
3039
@freezegun.freeze_time('2019-12-04')
3038 3040
def test_invoice_endpoint(app, resource):
3039 3041
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
3040 3042
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
3041 3043
    with open(filepath) as xml:
3042 3044
        invoices = xml.read()
3043 3045
    content = (
3044 3046
        '''<PORTAIL>
3045 3047
  <GETFACTURESAPAYER>
3046
-