Skip to content

Commit 2a85d66

Browse files
committed
MsgHeader and Envelope attribute namespacing
1 parent 66724ea commit 2a85d66

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

finvoice/soap/envelope.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ def exportChildren(self, outfile, level, namespace_='SOAP-ENV:', name_='Body', f
10031003
else:
10041004
eol_ = ''
10051005
for obj_ in self.anytypeobjs_:
1006-
obj_.export(outfile, level, namespace_, pretty_print=pretty_print)
1006+
# Children can be of any namespace so don't include namespace
1007+
obj_.export(outfile, level, pretty_print=pretty_print)
10071008
def exportLiteral(self, outfile, level, name_='Body'):
10081009
level += 1
10091010
already_processed = set()

finvoice/soap/msgheader.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def gds_format_datetime(self, input_data, input_name=''):
182182
input_data.day,
183183
input_data.hour,
184184
input_data.minute,
185-
input_data.second
185+
input_data.second,
186186
)
187187
else:
188188
_svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % (
@@ -692,10 +692,10 @@ def export(self, outfile, level, namespace_='eb:', name_='Manifest', namespacede
692692
def exportAttributes(self, outfile, level, already_processed, namespace_='eb:', name_='Manifest'):
693693
if self.version is not None and 'version' not in already_processed:
694694
already_processed.add('version')
695-
outfile.write(' version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
695+
outfile.write(' eb:version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
696696
if self.id is not None and 'id' not in already_processed:
697697
already_processed.add('id')
698-
outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
698+
outfile.write(' eb:id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
699699
def exportChildren(self, outfile, level, namespace_='eb:', name_='Manifest', fromsubclass_=False, pretty_print=True):
700700
if pretty_print:
701701
eol_ = '\n'
@@ -886,13 +886,13 @@ def exportAttributes(self, outfile, level, already_processed, namespace_='eb:',
886886
outfile.write(' role=%s' % (self.gds_format_string(quote_attrib(self.role).encode(ExternalEncoding), input_name='role'), ))
887887
if self.href is not None and 'href' not in already_processed:
888888
already_processed.add('href')
889-
outfile.write(' href=%s' % (self.gds_format_string(quote_attrib(self.href).encode(ExternalEncoding), input_name='href'), ))
889+
outfile.write(' xlink:href=%s' % (self.gds_format_string(quote_attrib(self.href).encode(ExternalEncoding), input_name='href'), ))
890890
if self.type_ is not None and 'type_' not in already_processed:
891891
already_processed.add('type_')
892892
outfile.write(' type=%s' % (self.gds_format_string(quote_attrib(self.type_).encode(ExternalEncoding), input_name='type'), ))
893893
if self.id is not None and 'id' not in already_processed:
894894
already_processed.add('id')
895-
outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
895+
outfile.write(' eb:id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
896896
def exportChildren(self, outfile, level, namespace_='eb:', name_='Reference', fromsubclass_=False, pretty_print=True):
897897
if pretty_print:
898898
eol_ = '\n'
@@ -1053,10 +1053,10 @@ def export(self, outfile, level, namespace_='eb:', name_='Schema', namespacedef_
10531053
def exportAttributes(self, outfile, level, already_processed, namespace_='eb:', name_='Schema'):
10541054
if self.version is not None and 'version' not in already_processed:
10551055
already_processed.add('version')
1056-
outfile.write(' version=%s' % (quote_attrib(self.version), ))
1056+
outfile.write(' eb:version=%s' % (quote_attrib(self.version), ))
10571057
if self.location is not None and 'location' not in already_processed:
10581058
already_processed.add('location')
1059-
outfile.write(' location=%s' % (self.gds_format_string(quote_attrib(self.location).encode(ExternalEncoding), input_name='location'), ))
1059+
outfile.write(' eb:location=%s' % (self.gds_format_string(quote_attrib(self.location).encode(ExternalEncoding), input_name='location'), ))
10601060
def exportChildren(self, outfile, level, namespace_='eb:', name_='Schema', fromsubclass_=False, pretty_print=True):
10611061
pass
10621062
def exportLiteral(self, outfile, level, name_='Schema'):
@@ -1195,13 +1195,13 @@ def export(self, outfile, level, namespace_='eb:', name_='MessageHeader', namesp
11951195
def exportAttributes(self, outfile, level, already_processed, namespace_='eb:', name_='MessageHeader'):
11961196
if self.mustUnderstand is not None and 'mustUnderstand' not in already_processed:
11971197
already_processed.add('mustUnderstand')
1198-
outfile.write(' mustUnderstand=%s' % (self.gds_format_string(quote_attrib(self.mustUnderstand).encode(ExternalEncoding), input_name='mustUnderstand'), ))
1198+
outfile.write(' SOAP-ENV:mustUnderstand=%s' % (self.gds_format_string(quote_attrib(self.mustUnderstand).encode(ExternalEncoding), input_name='mustUnderstand'), ))
11991199
if self.version is not None and 'version' not in already_processed:
12001200
already_processed.add('version')
1201-
outfile.write(' version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
1201+
outfile.write(' eb:version=%s' % (self.gds_format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
12021202
if self.id is not None and 'id' not in already_processed:
12031203
already_processed.add('id')
1204-
outfile.write(' id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
1204+
outfile.write(' eb:id=%s' % (self.gds_format_string(quote_attrib(self.id).encode(ExternalEncoding), input_name='id'), ))
12051205
def exportChildren(self, outfile, level, namespace_='eb:', name_='MessageHeader', fromsubclass_=False, pretty_print=True):
12061206
if pretty_print:
12071207
eol_ = '\n'

samples/senderinfo.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727

2828
from finvoice.soap.envelope import Envelope, Header, Body
2929
from finvoice.soap.msgheader import MessageHeader, From, To, PartyId, Service, MessageData
30+
from finvoice.soap.msgheader import Manifest, Reference, Schema
31+
32+
from pytz import reference
3033

3134
# Date
32-
nowDate = date( "CCYYMMDD", datetime.datetime.today().date().strftime("%Y%m%d") )
35+
nowDate = date( "CCYYMMDD", datetime.datetime.now( reference.LocalTimezone() ).date().strftime("%Y%m%d") )
3336

3437
# Seller Postal Address
3538
# SellerStreetName=None, SellerTownName=None, SellerPostCodeIdentifier=None, CountryCode=None, CountryName=None, SellerPostOfficeBoxIdentifier=None
@@ -136,17 +139,29 @@
136139
messageHeader.set_Service( Service( None, "Routing" ) )
137140
messageHeader.set_Action( "ProcessInvoice" )
138141

139-
msgData = MessageData( _messageId, datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S%z") )
142+
_now = datetime.datetime.now( reference.LocalTimezone() )
143+
_nowS = datetime.datetime( _now.year, _now.month, _now.day, _now.hour, _now.minute, _now.second, 0, _now.tzinfo )
144+
msgData = MessageData( _messageId + '/1', _nowS )
140145

141146
messageHeader.set_MessageData( msgData )
142147

143148
# messageHeader.export( sys.stdout, 0, namespace_='eb:', name_='MessageHeader', namespacedef_='xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd msg-header-2_0.xsd"', pretty_print=True )
144149

145150
envelope.set_Header( header )
146151

152+
manifest = Manifest( "2.0", "Manifest" )
153+
reference = Reference( None, _messageId, None, "FinvoiceSenderInfo" )
154+
manifest.add_Reference( reference )
155+
reference.add_Schema( Schema( "2.0", "http://www.pankkiyhdistys.fi/verkkolasku/finvoice/FinvoiceSenderInfo.xsd" ) )
156+
157+
body = Body( )
158+
body.add_anytypeobjs_( manifest )
159+
160+
envelope.set_Body( body )
161+
147162
envelope.export( sys.stdout, 0, pretty_print=True )
148163

149164
encodingHeader = '<?xml version="1.0" encoding="' + ExternalEncoding + '" ?>\n'
150-
#sys.stdout.write( encodingHeader )
151-
#sys.stdout.write( '<?xml-stylesheet type="text/xsl" href="FinvoiceSenderInfo.xsl"?>\n' )
152-
#senderInfo.export( sys.stdout, 0, name_='FinvoiceSenderInfo', namespacedef_='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FinvoiceSenderInfo.xsd"', pretty_print=True )
165+
sys.stdout.write( encodingHeader )
166+
sys.stdout.write( '<?xml-stylesheet type="text/xsl" href="FinvoiceSenderInfo.xsl"?>\n' )
167+
senderInfo.export( sys.stdout, 0, name_='FinvoiceSenderInfo', namespacedef_='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FinvoiceSenderInfo.xsd"', pretty_print=True )

0 commit comments

Comments
 (0)