Projet

Général

Profil

0001-ods-consider-0-as-number-65184.patch

Frédéric Péters, 12 mai 2022 18:49

Télécharger (2,44 ko)

Voir les différences:

Subject: [PATCH] ods: consider 0 as number (#65184)

 tests/backoffice_pages/test_export.py | 14 ++++++++++++++
 wcs/qommon/ods.py                     |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)
tests/backoffice_pages/test_export.py
595 595
            type='string',
596 596
            display_locations=['validation', 'summary', 'listings'],
597 597
        ),
598
        fields.StringField(
599
            id='12',
600
            label='number field with zero',
601
            type='string',
602
            display_locations=['validation', 'summary', 'listings'],
603
        ),
598 604
    ]
599 605
    formdef.workflow_roles = {'_receiver': 1}
600 606
    formdef.store()
......
618 624
        '9': 'plop\npl\x1dop',  # with control characters
619 625
        '10': ' 123,45',
620 626
        '11': '1_000_000',
627
        '12': '0',
621 628
    }
622 629
    formdata.data['4'].receive([b'hello world'])
623 630
    formdata.just_created()
......
654 661
    string_column = all_texts.index('string field')
655 662
    comma_number_column = all_texts.index('number with comma field')
656 663
    not_number_column = all_texts.index('not a number, with underscore')
664
    zero_number_column = all_texts.index('number field with zero')
657 665

  
658 666
    for row in ods_sheet.findall('.//{%s}table-row' % ods.NS['table']):
659 667
        if (
......
734 742
        ]
735 743
        == 'string'
736 744
    )
745
    assert (
746
        row.findall('.//{%s}table-cell' % ods.NS['table'])[zero_number_column].attrib[
747
            '{%s}value' % ods.NS['office']
748
        ]
749
        == '0'
750
    )
737 751

  
738 752

  
739 753
def test_backoffice_header_line(pub):
wcs/qommon/ods.py
49 49

  
50 50

  
51 51
def is_number(value):
52
    if value and (value.startswith('0') or value.startswith('+')):
52
    if value and value.strip() != '0' and (value.startswith('0') or value.startswith('+')):
53 53
        # avoid phone numbers
54 54
        return False
55 55
    if isinstance(value, str):
56
-