Skip to content

Commit

Permalink
[ADD] fill nr_rg and modello37 tags whit 0 if len < 6 due of siamm sp…
Browse files Browse the repository at this point in the history
…ec requirement.
  • Loading branch information
gigidn committed Feb 2, 2016
1 parent 19b3005 commit 26cd8ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
17 changes: 13 additions & 4 deletions PyFePA/siamm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,21 @@ def validateprot(value):
try:
if len(value) <= 11 and len(value.split('/')) == 2 \
and value.split('/')[0].isdigit() \
and value.split('/')[1].isdigit():
and value.split('/')[1].isdigit() and len(value.split('/')[1]) == 4:
return True
except:
return False
return False

def fillprot(value):

if value:
part1 = '%06d' % int(value.split('/')[0])
return part1+'/'+value.split('/')[1]
else:
return value



def is_number(s):
try:
Expand All @@ -66,7 +75,7 @@ def validate(value):

err = ''

if 'beneficiario' not in value:
if 'beneficiario' not in value or value['beneficiario'] is None:
err = err + 'Volore errato per beneficiario '
elif 'tipopagamento' not in value or value['tipopagamento'] not in TP:
err = err + 'Volore errato per tipopagamento '
Expand Down Expand Up @@ -118,7 +127,7 @@ def _siam_serialize(value):
"{:%Y-%m-%dT%H:%M:%S}".format(value['datainizioprestazione'])
(etree.SubElement(intercettazioni, 'DATAFINEPRESTAZIONE')).text = \
"{:%Y-%m-%dT%H:%M:%S}".format(value['datafineprestazione'])
(etree.SubElement(intercettazioni, 'NR_RG')).text = value['nr_rg'] if 'nr_rg' in value else None
(etree.SubElement(intercettazioni, 'NR_RG')).text = fillprot(value['nr_rg']) if 'nr_rg' in value else None
(etree.SubElement(intercettazioni, 'REGISTRO')).text = value['registro'].upper()
(etree.SubElement(intercettazioni, 'SEDE')).text = value['sede'].upper()
(etree.SubElement(intercettazioni, 'IMPORTOTOTALE')).text = \
Expand All @@ -130,7 +139,7 @@ def _siam_serialize(value):
"{:%Y-%m-%dT%H:%M:%S}".format(value['datafattura'])
if not value['tipointercettazione'] == 'GPS':
(etree.SubElement(intercettazioni, 'NUMEROMODELLO37')).text = \
value['numeromodello37'] if 'numeromodello37' in value else None
fillprot(value['numeromodello37']) if 'numeromodello37' in value else None
(etree.SubElement(intercettazioni, 'TIPOINTERCETTAZIONE')).text = value['tipointercettazione'].upper()
(etree.SubElement(intercettazioni, 'NOMEMAGISTRATO')).text = unicode(value['nomemagistrato']).upper()
(etree.SubElement(intercettazioni, 'COGNOMEMAGISTRATO')).text = unicode(value['cognomemagistrato']).upper()
Expand Down
10 changes: 10 additions & 0 deletions PyFePA/test/test_siamm.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ def testvalidateprot(self):
prot = siamm.validateprot('124/2014')
self.assertEqual(True,prot)

def testvalidateprot2(self):
"""validateprot should fail"""
prot = siamm.validateprot('124/14')
self.assertEqual(False,prot)

def testfillprot(self):
"""validateprot should not fail"""
prot = siamm.fillprot('124/2014')
self.assertEqual('000124/2014',prot)

def testSerializationOptional(self):
"""validate serialization whit opts None"""
errordata = testdata.copy()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
setup(
name = 'PyFePA',
packages = ['PyFePA'],
version = '1.0.4',
version = '1.0.5',
description = 'Python object of italian FatturaPA, serialize, deserialize and verify',
author = 'Luigi Di Naro',
author_email = '[email protected]',
url = 'https://github.com/ktecsrl/PyFePA',
download_url = 'https://github.com/ktecsrl/PyFePA/tarball/1.0.4',
download_url = 'https://github.com/ktecsrl/PyFePA/tarball/1.0.5',
keywords = ['FatturaPA', 'financial', 'utils'],
platforms= 'OSX, *unix, win',
package_data = {'PyFePA' : files },
Expand Down

0 comments on commit 26cd8ed

Please sign in to comment.