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
=== modified file 'l10n_mx_facturae/invoice.py'
--- l10n_mx_facturae/invoice.py 2013-12-10 01:11:31 +0000
+++ l10n_mx_facturae/invoice.py 2014-02-08 01:16:19 +0000
@@ -118,6 +118,9 @@
118class account_invoice(osv.Model):118class account_invoice(osv.Model):
119 _inherit = 'account.invoice'119 _inherit = 'account.invoice'
120120
121 def string_to_xml_format(self, cr, uid, ids, text):
122 return text.encode('utf-8', 'xmlcharrefreplace')
123
121 def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):124 def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
122 """125 """
123 @param report_name : Name of report with the name of object more type126 @param report_name : Name of report with the name of object more type
@@ -700,7 +703,7 @@
700 key_item_sort.append([key_too, data_dict[key_too]])703 key_item_sort.append([key_too, data_dict[key_too]])
701 return key_item_sort704 return key_item_sort
702705
703 def dict2xml(self, data_dict, node=False, doc=False):706 def dict2xml(self, cr, uid, ids, data_dict, node=False, doc=False):
704 """707 """
705 @param data_dict : Dictionary of attributes for add in the XML 708 @param data_dict : Dictionary of attributes for add in the XML
706 that will be generated709 that will be generated
@@ -717,24 +720,23 @@
717 if isinstance(attribute, dict):720 if isinstance(attribute, dict):
718 if not parent:721 if not parent:
719 node = doc.createElement(element)722 node = doc.createElement(element)
720 self.dict2xml(attribute, node, doc)723 self.dict2xml(cr, uid, ids, attribute, node, doc)
721 else:724 else:
722 child = doc.createElement(element)725 child = doc.createElement(element)
723 self.dict2xml(attribute, child, doc)726 self.dict2xml(cr, uid, ids, attribute, child, doc)
724 node.appendChild(child)727 node.appendChild(child)
725 elif isinstance(attribute, list):728 elif isinstance(attribute, list):
726 child = doc.createElement(element)729 child = doc.createElement(element)
727 for attr in attribute:730 for attr in attribute:
728 if isinstance(attr, dict):731 if isinstance(attr, dict):
729 self.dict2xml(attr, child, doc)732 self.dict2xml(cr, uid, ids, attr, child, doc)
730 node.appendChild(child)733 node.appendChild(child)
731 else:734 else:
732 if isinstance(attribute, str) or isinstance(attribute, unicode):735 if isinstance(attribute, str) or isinstance(attribute, unicode):
733 attribute = conv_ascii(attribute)736 attribute = self.string_to_xml_format(cr, uid, ids, attribute)
734 else:737 else:
735 attribute = str(attribute)738 attribute = str(attribute)
736 node.setAttribute(element, attribute)739 node.setAttribute(element, attribute)
737 # print "attribute",unicode( attribute, 'UTF-8')
738 if not parent:740 if not parent:
739 doc.appendChild(node)741 doc.appendChild(node)
740 return doc742 return doc
@@ -744,7 +746,7 @@
744 context = {}746 context = {}
745 data_dict = self._get_facturae_invoice_dict_data(747 data_dict = self._get_facturae_invoice_dict_data(
746 cr, uid, ids, context=context)[0]748 cr, uid, ids, context=context)[0]
747 doc_xml = self.dict2xml({749 doc_xml = self.dict2xml(cr, uid, ids, {
748 'Comprobante': data_dict.get('Comprobante')})750 'Comprobante': data_dict.get('Comprobante')})
749 invoice_number = "sn"751 invoice_number = "sn"
750 (fileno_xml, fname_xml) = tempfile.mkstemp(752 (fileno_xml, fname_xml) = tempfile.mkstemp(
@@ -812,12 +814,13 @@
812 return data_dict814 return data_dict
813 if context.get('type_data') == 'xml_obj':815 if context.get('type_data') == 'xml_obj':
814 return doc_xml816 return doc_xml
815 data_xml = doc_xml.toxml('UTF-8')817 data_xml = doc_xml.toxml()
816 data_xml = codecs.BOM_UTF8 + data_xml818 data_xml = codecs.BOM_UTF8 + data_xml
817 fname_xml = (data_dict['Comprobante']['Emisor']['rfc'] or '') + '_' + (819 fname_xml = (data_dict['Comprobante']['Emisor']['rfc'] or '') + '_' + (
818 data_dict['Comprobante'].get('serie', '') or '') + '_' + (820 data_dict['Comprobante'].get('serie', '') or '') + '_' + (
819 data_dict['Comprobante'].get('folio', '') or '') + '.xml'821 data_dict['Comprobante'].get('folio', '') or '') + '.xml'
820 data_xml = data_xml.replace('<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')822 data_xml = data_xml.replace('<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
823 data_xml = data_xml.replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
821 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 False824 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
822 facturae_version = '2.2'825 facturae_version = '2.2'
823 if date_invoice and date_invoice < '2012-07-01':826 if date_invoice and date_invoice < '2012-07-01':
824827
=== modified file 'l10n_mx_facturae_pac/invoice.py'
--- l10n_mx_facturae_pac/invoice.py 2013-11-20 23:20:47 +0000
+++ l10n_mx_facturae_pac/invoice.py 2014-02-08 01:16:19 +0000
@@ -133,7 +133,7 @@
133 facturae_version = '2.2'133 facturae_version = '2.2'
134 data_dict = self._get_facturae_invoice_dict_data(134 data_dict = self._get_facturae_invoice_dict_data(
135 cr, uid, ids, context=context)[0]135 cr, uid, ids, context=context)[0]
136 doc_xml = self.dict2xml({comprobante: data_dict.get(comprobante)})136 doc_xml = self.dict2xml(cr, uid, ids, {comprobante: data_dict.get(comprobante)})
137 invoice_number = "sn"137 invoice_number = "sn"
138 (fileno_xml, fname_xml) = tempfile.mkstemp(138 (fileno_xml, fname_xml) = tempfile.mkstemp(
139 '.xml', 'openerp_' + (invoice_number or '') + '__facturae__')139 '.xml', 'openerp_' + (invoice_number or '') + '__facturae__')
@@ -204,13 +204,15 @@
204 return data_dict204 return data_dict
205 if context.get('type_data') == 'xml_obj':205 if context.get('type_data') == 'xml_obj':
206 return doc_xml206 return doc_xml
207 data_xml = doc_xml.toxml('UTF-8')207 data_xml = doc_xml.toxml()
208 data_xml = codecs.BOM_UTF8 + data_xml208 data_xml = codecs.BOM_UTF8 + data_xml
209 fname_xml = (data_dict[comprobante][emisor]['rfc'] or '') + '_' + (209 fname_xml = (data_dict[comprobante][emisor]['rfc'] or '') + '_' + (
210 data_dict[comprobante].get('serie', '') or '') + '_' + (210 data_dict[comprobante].get('serie', '') or '') + '_' + (
211 data_dict[comprobante].get('folio', '') or '') + '.xml'211 data_dict[comprobante].get('folio', '') or '') + '.xml'
212 data_xml = data_xml.replace(212 data_xml = data_xml.replace(
213 '<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')213 '<?xml version="1.0" encoding="UTF-8"?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
214 data_xml = data_xml.replace(
215 '<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>\n')
214 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 False216 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
215 if date_invoice and date_invoice < '2012-07-01':217 if date_invoice and date_invoice < '2012-07-01':
216 facturae_version = '2.0'218 facturae_version = '2.0'