Skip to content

Commit 26cd8ed

Browse files
committed
[ADD] fill nr_rg and modello37 tags whit 0 if len < 6 due of siamm spec requirement.
1 parent 19b3005 commit 26cd8ed

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

PyFePA/siamm.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ def validateprot(value):
4747
try:
4848
if len(value) <= 11 and len(value.split('/')) == 2 \
4949
and value.split('/')[0].isdigit() \
50-
and value.split('/')[1].isdigit():
50+
and value.split('/')[1].isdigit() and len(value.split('/')[1]) == 4:
5151
return True
5252
except:
5353
return False
5454
return False
5555

56+
def fillprot(value):
57+
58+
if value:
59+
part1 = '%06d' % int(value.split('/')[0])
60+
return part1+'/'+value.split('/')[1]
61+
else:
62+
return value
63+
64+
5665

5766
def is_number(s):
5867
try:
@@ -66,7 +75,7 @@ def validate(value):
6675

6776
err = ''
6877

69-
if 'beneficiario' not in value:
78+
if 'beneficiario' not in value or value['beneficiario'] is None:
7079
err = err + 'Volore errato per beneficiario '
7180
elif 'tipopagamento' not in value or value['tipopagamento'] not in TP:
7281
err = err + 'Volore errato per tipopagamento '
@@ -118,7 +127,7 @@ def _siam_serialize(value):
118127
"{:%Y-%m-%dT%H:%M:%S}".format(value['datainizioprestazione'])
119128
(etree.SubElement(intercettazioni, 'DATAFINEPRESTAZIONE')).text = \
120129
"{:%Y-%m-%dT%H:%M:%S}".format(value['datafineprestazione'])
121-
(etree.SubElement(intercettazioni, 'NR_RG')).text = value['nr_rg'] if 'nr_rg' in value else None
130+
(etree.SubElement(intercettazioni, 'NR_RG')).text = fillprot(value['nr_rg']) if 'nr_rg' in value else None
122131
(etree.SubElement(intercettazioni, 'REGISTRO')).text = value['registro'].upper()
123132
(etree.SubElement(intercettazioni, 'SEDE')).text = value['sede'].upper()
124133
(etree.SubElement(intercettazioni, 'IMPORTOTOTALE')).text = \
@@ -130,7 +139,7 @@ def _siam_serialize(value):
130139
"{:%Y-%m-%dT%H:%M:%S}".format(value['datafattura'])
131140
if not value['tipointercettazione'] == 'GPS':
132141
(etree.SubElement(intercettazioni, 'NUMEROMODELLO37')).text = \
133-
value['numeromodello37'] if 'numeromodello37' in value else None
142+
fillprot(value['numeromodello37']) if 'numeromodello37' in value else None
134143
(etree.SubElement(intercettazioni, 'TIPOINTERCETTAZIONE')).text = value['tipointercettazione'].upper()
135144
(etree.SubElement(intercettazioni, 'NOMEMAGISTRATO')).text = unicode(value['nomemagistrato']).upper()
136145
(etree.SubElement(intercettazioni, 'COGNOMEMAGISTRATO')).text = unicode(value['cognomemagistrato']).upper()

PyFePA/test/test_siamm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ def testvalidateprot(self):
138138
prot = siamm.validateprot('124/2014')
139139
self.assertEqual(True,prot)
140140

141+
def testvalidateprot2(self):
142+
"""validateprot should fail"""
143+
prot = siamm.validateprot('124/14')
144+
self.assertEqual(False,prot)
145+
146+
def testfillprot(self):
147+
"""validateprot should not fail"""
148+
prot = siamm.fillprot('124/2014')
149+
self.assertEqual('000124/2014',prot)
150+
141151
def testSerializationOptional(self):
142152
"""validate serialization whit opts None"""
143153
errordata = testdata.copy()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
setup(
2323
name = 'PyFePA',
2424
packages = ['PyFePA'],
25-
version = '1.0.4',
25+
version = '1.0.5',
2626
description = 'Python object of italian FatturaPA, serialize, deserialize and verify',
2727
author = 'Luigi Di Naro',
2828
author_email = 'Luigi.DiNaro@ktec.it',
2929
url = 'https://github.com/ktecsrl/PyFePA',
30-
download_url = 'https://github.com/ktecsrl/PyFePA/tarball/1.0.4',
30+
download_url = 'https://github.com/ktecsrl/PyFePA/tarball/1.0.5',
3131
keywords = ['FatturaPA', 'financial', 'utils'],
3232
platforms= 'OSX, *unix, win',
3333
package_data = {'PyFePA' : files },

0 commit comments

Comments
 (0)