Merge lp:~vauxoo/openerp-mexico-localization/characters_specials-dev-jc into lp:openerp-mexico-localization/7.0

Proposed by Juan Carlos Hernandez
Status: Needs review
Proposed branch: lp:~vauxoo/openerp-mexico-localization/characters_specials-dev-jc
Merge into: lp:openerp-mexico-localization/7.0
Diff against target: 106 lines (+16/-11)
2 files modified
l10n_mx_facturae/invoice.py (+12/-9)
l10n_mx_facturae_pac/invoice.py (+4/-2)
To merge this branch: bzr merge lp:~vauxoo/openerp-mexico-localization/characters_specials-dev-jc
Reviewer Review Type Date Requested Status
Julio Serna-http://www.vauxoo.com Pending
Juan Carlos Hernandez Pending
Jorge Angel Naranjo Rogel - http://www.vauxoo.com Pending
Review via email: mp+205463@code.launchpad.net

Description of the change

se agregó la siguiente función para caracteres especiales como (® ½ & > < ' " ´ ©) y mas caracteres especiales.
def string_to_xml_format(self, cr, uid, ids, text):
       return text.encode('utf-8', 'xmlcharrefreplace')

To post a comment you must log in.

Unmerged revisions

352. By Juan Carlos Hernandez

[IMP][l10n_mx_facturae]add function string_to_xml_format() for characters ® & > < ' " ´ and more characters

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_mx_facturae/invoice.py'
2--- l10n_mx_facturae/invoice.py 2013-12-10 01:11:31 +0000
3+++ l10n_mx_facturae/invoice.py 2014-02-08 01:16:19 +0000
4@@ -118,6 +118,9 @@
5 class account_invoice(osv.Model):
6 _inherit = 'account.invoice'
7
8+ def string_to_xml_format(self, cr, uid, ids, text):
9+ return text.encode('utf-8', 'xmlcharrefreplace')
10+
11 def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
12 """
13 @param report_name : Name of report with the name of object more type
14@@ -700,7 +703,7 @@
15 key_item_sort.append([key_too, data_dict[key_too]])
16 return key_item_sort
17
18- def dict2xml(self, data_dict, node=False, doc=False):
19+ def dict2xml(self, cr, uid, ids, data_dict, node=False, doc=False):
20 """
21 @param data_dict : Dictionary of attributes for add in the XML
22 that will be generated
23@@ -717,24 +720,23 @@
24 if isinstance(attribute, dict):
25 if not parent:
26 node = doc.createElement(element)
27- self.dict2xml(attribute, node, doc)
28+ self.dict2xml(cr, uid, ids, attribute, node, doc)
29 else:
30 child = doc.createElement(element)
31- self.dict2xml(attribute, child, doc)
32+ self.dict2xml(cr, uid, ids, attribute, child, doc)
33 node.appendChild(child)
34 elif isinstance(attribute, list):
35 child = doc.createElement(element)
36 for attr in attribute:
37 if isinstance(attr, dict):
38- self.dict2xml(attr, child, doc)
39+ self.dict2xml(cr, uid, ids, attr, child, doc)
40 node.appendChild(child)
41 else:
42 if isinstance(attribute, str) or isinstance(attribute, unicode):
43- attribute = conv_ascii(attribute)
44+ attribute = self.string_to_xml_format(cr, uid, ids, attribute)
45 else:
46- attribute = str(attribute)
47+ attribute = str(attribute)
48 node.setAttribute(element, attribute)
49- # print "attribute",unicode( attribute, 'UTF-8')
50 if not parent:
51 doc.appendChild(node)
52 return doc
53@@ -744,7 +746,7 @@
54 context = {}
55 data_dict = self._get_facturae_invoice_dict_data(
56 cr, uid, ids, context=context)[0]
57- doc_xml = self.dict2xml({
58+ doc_xml = self.dict2xml(cr, uid, ids, {
59 'Comprobante': data_dict.get('Comprobante')})
60 invoice_number = "sn"
61 (fileno_xml, fname_xml) = tempfile.mkstemp(
62@@ -812,12 +814,13 @@
63 return data_dict
64 if context.get('type_data') == 'xml_obj':
65 return doc_xml
66- data_xml = doc_xml.toxml('UTF-8')
67+ data_xml = doc_xml.toxml()
68 data_xml = codecs.BOM_UTF8 + data_xml
69 fname_xml = (data_dict['Comprobante']['Emisor']['rfc'] or '') + '_' + (
70 data_dict['Comprobante'].get('serie', '') or '') + '_' + (
71 data_dict['Comprobante'].get('folio', '') or '') + '.xml'
72 data_xml = data_xml.replace('<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
73+ data_xml = data_xml.replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
74 date_invoice = data_dict.get('Comprobante',{}) and datetime.strptime( data_dict.get('Comprobante',{}).get('fecha',{}), '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d') or False
75 facturae_version = '2.2'
76 if date_invoice and date_invoice < '2012-07-01':
77
78=== modified file 'l10n_mx_facturae_pac/invoice.py'
79--- l10n_mx_facturae_pac/invoice.py 2013-11-20 23:20:47 +0000
80+++ l10n_mx_facturae_pac/invoice.py 2014-02-08 01:16:19 +0000
81@@ -133,7 +133,7 @@
82 facturae_version = '2.2'
83 data_dict = self._get_facturae_invoice_dict_data(
84 cr, uid, ids, context=context)[0]
85- doc_xml = self.dict2xml({comprobante: data_dict.get(comprobante)})
86+ doc_xml = self.dict2xml(cr, uid, ids, {comprobante: data_dict.get(comprobante)})
87 invoice_number = "sn"
88 (fileno_xml, fname_xml) = tempfile.mkstemp(
89 '.xml', 'openerp_' + (invoice_number or '') + '__facturae__')
90@@ -204,13 +204,15 @@
91 return data_dict
92 if context.get('type_data') == 'xml_obj':
93 return doc_xml
94- data_xml = doc_xml.toxml('UTF-8')
95+ data_xml = doc_xml.toxml()
96 data_xml = codecs.BOM_UTF8 + data_xml
97 fname_xml = (data_dict[comprobante][emisor]['rfc'] or '') + '_' + (
98 data_dict[comprobante].get('serie', '') or '') + '_' + (
99 data_dict[comprobante].get('folio', '') or '') + '.xml'
100 data_xml = data_xml.replace(
101 '<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
102+ data_xml = data_xml.replace(
103+ '<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
104 date_invoice = data_dict.get('Comprobante',{}) and datetime.strptime( data_dict.get('Comprobante',{}).get('fecha',{}), '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d') or False
105 if date_invoice and date_invoice < '2012-07-01':
106 facturae_version = '2.0'