Merge lp:~vauxoo/openerp-mexico-localization/7.0_l10n_mx_facturae_lib_raise_pakages_dev_carlos into lp:openerp-mexico-localization/7.0
- 7.0_l10n_mx_facturae_lib_raise_pakages_dev_carlos
- Merge into 7.0
Proposed by
Juan Carlos Hernandez
Status: | Merged |
---|---|
Merged at revision: | 333 |
Proposed branch: | lp:~vauxoo/openerp-mexico-localization/7.0_l10n_mx_facturae_lib_raise_pakages_dev_carlos |
Merge into: | lp:openerp-mexico-localization/7.0 |
Diff against target: |
338 lines (+89/-47) 5 files modified
l10n_mx_facturae/invoice.py (+15/-11) l10n_mx_facturae_lib/facturae_lib.py (+64/-31) l10n_mx_facturae_pac/invoice.py (+3/-3) l10n_mx_ir_attachment_facturae/__openerp__.py (+1/-0) l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py (+6/-2) |
To merge this branch: | bzr merge lp:~vauxoo/openerp-mexico-localization/7.0_l10n_mx_facturae_lib_raise_pakages_dev_carlos |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juan Carlos Hernandez (community) | Needs Resubmitting | ||
Isaac López Zúñiga | Pending | ||
Moisés López - http://www.vauxoo.com | Pending | ||
Review via email: mp+192773@code.launchpad.net |
Commit message
Description of the change
se agrego raise en el caso que no existan dichos paquetes instalados (xsltproc,
To post a comment you must log in.
Revision history for this message
Juan Carlos Hernandez (openerp1) wrote : | # |
review:
Needs Resubmitting
- 322. By Juan Carlos Hernandez
-
[IMP][l10n_
mx_facturae_ lib]change fron error to warning - 323. By Juan Carlos Hernandez
-
[IMP][l10n_
mx_facturae_ lib]comment raise and change from error to warning - 324. By Juan Carlos Hernandez
-
[IMP][l10n_
mx_facturae] add function library_ openssl_ xsltproc_ xmlstarlet - 325. By Juan Carlos Hernandez
-
[IMP][l10n_
mx_facturae_ pac]corrected warning of library - 326. By Isaac López Zúñiga
-
[MERGE] frm oml revno 929
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-10-10 01:02:59 +0000 |
3 | +++ l10n_mx_facturae/invoice.py 2013-11-14 19:53:26 +0000 |
4 | @@ -781,7 +781,7 @@ |
5 | nodeComprobante.setAttribute("sello", sign_str) |
6 | data_dict['Comprobante']['sello'] = sign_str |
7 | |
8 | - noCertificado = self._get_noCertificado(context['fname_cer']) |
9 | + noCertificado = self._get_noCertificado(cr, uid, ids, context['fname_cer']) |
10 | if not noCertificado: |
11 | raise osv.except_osv(_('Error in No. Certificate !'), _( |
12 | "Can't get the Certificate Number of the voucher.\nCkeck your configuration.\n%s") % (msg2)) |
13 | @@ -833,8 +833,8 @@ |
14 | # If dir is in path, save it on real_path |
15 | fname_scheme = my_path and os.path.join(my_path, 'l10n_mx_facturae', 'SAT', facturae_type + facturae_version + '.' + scheme_type) or '' |
16 | #fname_scheme = os.path.join(tools.config["addons_path"], u'l10n_mx_facturae', u'SAT', facturae_type + facturae_version + '.' + scheme_type ) |
17 | - fname_out = certificate_lib.b64str_to_tempfile( base64.encodestring(''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + '__schema_validation_result__' ) |
18 | - result = certificate_lib.check_xml_scheme(fname_data_xml, fname_scheme, fname_out) |
19 | + fname_out = certificate_lib.b64str_to_tempfile(cr, uid, ids, base64.encodestring(''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + '__schema_validation_result__' ) |
20 | + result = certificate_lib.check_xml_scheme(cr, uid, ids, fname_data_xml, fname_scheme, fname_out) |
21 | if result: #Valida el xml mediante el archivo xsd |
22 | raise osv.except_osv('Error al validar la estructura del xml!', 'Validación de XML versión %s:\n%s'%(facturae_version, result)) |
23 | return True |
24 | @@ -866,22 +866,26 @@ |
25 | self.write(cr, uid, [id], data, context=context) |
26 | return True |
27 | |
28 | - def _get_noCertificado(self, fname_cer, pem=True): |
29 | + def _get_noCertificado(self, cr, uid, ids, fname_cer, pem=True, context=None): |
30 | """ |
31 | @param fname_cer : Path more name of file created whit information |
32 | of certificate with suffix .pem |
33 | @param pem : Boolean that indicate if file is .pem |
34 | """ |
35 | + if context is None: |
36 | + context = {} |
37 | certificate_lib = self.pool.get('facturae.certificate.library') |
38 | - fname_serial = certificate_lib.b64str_to_tempfile(base64.encodestring( |
39 | + fname_serial = certificate_lib.b64str_to_tempfile(cr, uid, ids, base64.encodestring( |
40 | ''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + \ |
41 | '__serial__') |
42 | - result = certificate_lib._get_param_serial( |
43 | + result = certificate_lib._get_param_serial(cr, uid, ids, |
44 | fname_cer, fname_out=fname_serial, type='PEM') |
45 | return result |
46 | |
47 | - def _get_sello(self, cr=False, uid=False, ids=False, context={}): |
48 | + def _get_sello(self, cr=False, uid=False, ids=False, context=None): |
49 | # TODO: Put encrypt date dynamic |
50 | + if context is None: |
51 | + context = {} |
52 | fecha = context['fecha'] |
53 | year = float(time.strftime('%Y', time.strptime( |
54 | fecha, '%Y-%m-%dT%H:%M:%S'))) |
55 | @@ -890,20 +894,20 @@ |
56 | if year <= 2010: |
57 | encrypt = "md5" |
58 | certificate_lib = self.pool.get('facturae.certificate.library') |
59 | - fname_sign = certificate_lib.b64str_to_tempfile(base64.encodestring( |
60 | + fname_sign = certificate_lib.b64str_to_tempfile(cr, uid, ids, base64.encodestring( |
61 | ''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + \ |
62 | '__sign__') |
63 | - result = certificate_lib._sign(fname=context['fname_xml'], |
64 | + result = certificate_lib._sign(cr, uid, ids, fname=context['fname_xml'], |
65 | fname_xslt=context['fname_xslt'], fname_key=context['fname_key'], |
66 | fname_out=fname_sign, encrypt=encrypt, type_key='PEM') |
67 | return result |
68 | |
69 | def _xml2cad_orig(self, cr=False, uid=False, ids=False, context={}): |
70 | certificate_lib = self.pool.get('facturae.certificate.library') |
71 | - fname_tmp = certificate_lib.b64str_to_tempfile(base64.encodestring( |
72 | + fname_tmp = certificate_lib.b64str_to_tempfile(cr, uid, ids, base64.encodestring( |
73 | ''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + \ |
74 | '__cadorig__') |
75 | - cad_orig = certificate_lib._transform_xml(fname_xml=context['fname_xml'], |
76 | + cad_orig = certificate_lib._transform_xml(cr, uid, ids, fname_xml=context['fname_xml'], |
77 | fname_xslt=context['fname_xslt'], fname_out=fname_tmp) |
78 | return fname_tmp, cad_orig |
79 | |
80 | |
81 | === modified file 'l10n_mx_facturae_lib/facturae_lib.py' |
82 | --- l10n_mx_facturae_lib/facturae_lib.py 2013-10-10 01:02:59 +0000 |
83 | +++ l10n_mx_facturae_lib/facturae_lib.py 2013-11-14 19:53:26 +0000 |
84 | @@ -36,6 +36,7 @@ |
85 | import base64 |
86 | import logging |
87 | _logger = logging.getLogger(__name__) |
88 | +from l10n_mx_facturae_lib import facturae_lib |
89 | |
90 | all_paths = tools.config["addons_path"].split(",") |
91 | for my_path in all_paths: |
92 | @@ -63,26 +64,38 @@ |
93 | app_openssl = 'openssl' |
94 | app_xmlstarlet = 'xmlstarlet' |
95 | |
96 | -app_openssl_fullpath = os.path.join(openssl_path, app_openssl) |
97 | -if not os.path.isfile(app_openssl_fullpath): |
98 | - app_openssl_fullpath = tools.find_in_path(app_openssl) |
99 | +def library_openssl_xsltproc_xmlstarlet(self, cr, uid, ids, context=None): |
100 | + if context is None: |
101 | + context = {} |
102 | + msj = '' |
103 | + app_openssl_fullpath = os.path.join(openssl_path, app_openssl) |
104 | if not os.path.isfile(app_openssl_fullpath): |
105 | - app_openssl_fullpath = False |
106 | - _logger.warning("Failed to find in path 'openssl' app") |
107 | - |
108 | -app_xsltproc_fullpath = os.path.join(xsltproc_path, app_xsltproc) |
109 | -if not os.path.isfile(app_xsltproc_fullpath): |
110 | - app_xsltproc_fullpath = tools.find_in_path(app_xsltproc) |
111 | + app_openssl_fullpath = tools.find_in_path(app_openssl) |
112 | + if not os.path.isfile(app_openssl_fullpath): |
113 | + app_openssl_fullpath = False |
114 | + _logger.warning('Install openssl "sudo apt-get install openssl" to use l10n_mx_facturae_lib module.') |
115 | + msj += 'Install openssl "sudo apt-get install openssl" to use l10n_mx_facturae_lib module.' |
116 | + |
117 | + app_xsltproc_fullpath = os.path.join(xsltproc_path, app_xsltproc) or False |
118 | if not os.path.isfile(app_xsltproc_fullpath): |
119 | - app_xsltproc_fullpath = False |
120 | - _logger.warning("Failed to find in path 'xsltproc' app") |
121 | + app_xsltproc_fullpath = tools.find_in_path(app_xsltproc) or False |
122 | + try: |
123 | + if not os.path.isfile(app_xsltproc_fullpath): |
124 | + app_xsltproc_fullpath = False |
125 | + _logger.warning("Install xsltproc 'sudo apt-get install xsltproc' to use l10n_mx_facturae_lib module.") |
126 | + msj = "Install xsltproc 'sudo apt-get install xsltproc' to use l10n_mx_facturae_lib module." |
127 | + except Exception, e: |
128 | + _logger.warning("Install xsltproc 'sudo apt-get install xsltproc' to use l10n_mx_facturae_lib module.") |
129 | + msj += "Install xsltproc 'sudo apt-get install xsltproc' to use l10n_mx_facturae_lib module." |
130 | |
131 | -app_xmlstarlet_fullpath = os.path.join(xmlstarlet_path, app_xmlstarlet) |
132 | -if not os.path.isfile( app_xmlstarlet_fullpath ): |
133 | - app_xmlstarlet_fullpath = tools.find_in_path( app_xmlstarlet ) |
134 | - if not app_xmlstarlet_fullpath: |
135 | - app_xmlstarlet_fullpath = False |
136 | - _logger.warning("Failed to find in path 'xmlstarlet' app") |
137 | + app_xmlstarlet_fullpath = os.path.join(xmlstarlet_path, app_xmlstarlet) |
138 | + if not os.path.isfile( app_xmlstarlet_fullpath ): |
139 | + app_xmlstarlet_fullpath = tools.find_in_path( app_xmlstarlet ) |
140 | + if not app_xmlstarlet_fullpath: |
141 | + app_xmlstarlet_fullpath = False |
142 | + _logger.warning('Install xmlstarlet "sudo apt-get install xmlstarlet" to use l10n_mx_facturae_lib module.') |
143 | + msj += 'Install xmlstarlet "sudo apt-get install xmlstarlet" to use l10n_mx_facturae_lib module.' |
144 | + return msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath |
145 | |
146 | |
147 | class facturae_certificate_library(osv.Model): |
148 | @@ -90,7 +103,7 @@ |
149 | _auto = False |
150 | # Agregar find subpath |
151 | |
152 | - def b64str_to_tempfile(self, b64_str="", file_suffix="", file_prefix=""): |
153 | + def b64str_to_tempfile(self, cr, uid, ids, b64_str="", file_suffix="", file_prefix=""): |
154 | """ |
155 | @param b64_str : Text in Base_64 format for add in the file |
156 | @param file_suffix : Sufix of the file |
157 | @@ -153,24 +166,29 @@ |
158 | output.close() |
159 | return result |
160 | |
161 | - def _get_param_serial(self, fname, fname_out=None, type='DER'): |
162 | + def _get_param_serial(self, cr, uid, ids, fname, fname_out=None, type='DER', context=None): |
163 | """ |
164 | @param fname : File.PEM with the information of the certificate |
165 | @param fname_out : File.xml that is send |
166 | """ |
167 | - result = self._get_params(fname, params=[ |
168 | - 'serial'], fname_out=fname_out, type=type) |
169 | + if context is None: |
170 | + context = {} |
171 | + result = self._get_params(cr, uid, ids, fname, params=['serial'], |
172 | + fname_out=fname_out, type=type) |
173 | result = result and result.replace('serial=', '').replace( |
174 | '33', 'B').replace('3', '').replace('B', '3').replace( |
175 | ' ', '').replace('\r', '').replace('\n', '').replace('\r\n', '') or '' |
176 | return result |
177 | |
178 | - def _transform_xml(self, fname_xml, fname_xslt, fname_out): |
179 | + def _transform_xml(self, cr, uid, ids, fname_xml, fname_xslt, fname_out, context=None): |
180 | """ |
181 | @param fname_xml : Path and name of the XML of Facturae |
182 | @param fname_xslt : Path where is located the file 'Cadena Original'.xslt |
183 | @param fname_out : Path and name of the file.xml that is send to sign |
184 | """ |
185 | + if context is None: |
186 | + context = {} |
187 | + msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context) |
188 | if not app_xsltproc_fullpath: |
189 | raise osv.except_osv(_("Error!"), _( |
190 | "Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"%(app_xsltproc) )) |
191 | @@ -183,15 +201,17 @@ |
192 | output.close() |
193 | return result |
194 | |
195 | - def _get_param_dates(self, fname, fname_out=None, |
196 | - date_fmt_return='%Y-%m-%d %H:%M:%S', type='DER'): |
197 | + def _get_param_dates(self, cr, uid, ids, fname, fname_out=None, |
198 | + date_fmt_return='%Y-%m-%d %H:%M:%S', type='DER', context=None): |
199 | """ |
200 | @param fname : File.cer with the information of the certificate |
201 | @params fname_out : Path and name of the file.txt with info encrypted |
202 | @param date_fmt_return : Format of the date used |
203 | @param type : Type of file |
204 | """ |
205 | - result_dict = self._get_params_dict(fname, params=[ |
206 | + if context is None: |
207 | + context = {} |
208 | + result_dict = self._get_params_dict(cr, uid, ids, fname, params=[ |
209 | 'dates'], fname_out=fname_out, type=type) |
210 | translate_key = { |
211 | 'notAfter': 'enddate', |
212 | @@ -207,14 +227,16 @@ |
213 | result2[translate_key[key]] = date_fmt |
214 | return result2 |
215 | |
216 | - def _get_params_dict(self, fname, params=None, fname_out=None, type='DER'): |
217 | + def _get_params_dict(self, cr, uid, ids, fname, params=None, fname_out=None, type='DER', context=None): |
218 | """ |
219 | @param fname : File.cer with the information of the certificate |
220 | @param params : List of params used for this function |
221 | @param fname_out : Path and name of the file.txt with info encrypted |
222 | @param type : Type of file |
223 | """ |
224 | - result = self._get_params(fname, params, fname_out, type) |
225 | + if context is None: |
226 | + context = {} |
227 | + result = self._get_params(cr, uid, ids, fname, params, fname_out, type) |
228 | result = result.replace('\r\n', '\n').replace( |
229 | '\r', '\n') # .replace('\n', '\n) |
230 | result = result.rstrip('\n').lstrip('\n').rstrip(' ').lstrip(' ') |
231 | @@ -226,11 +248,14 @@ |
232 | params_dict[key] = value |
233 | return params_dict |
234 | |
235 | - def _get_params(self, fname, params=None, fname_out=None, type='DER'): |
236 | + def _get_params(self, cr, uid, ids, fname, params=None, fname_out=None, type='DER', context=None): |
237 | """ |
238 | @params: list [noout serial startdate enddate subject issuer dates] |
239 | @type: str DER or PEM |
240 | """ |
241 | + if context is None: |
242 | + context = {} |
243 | + msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context) |
244 | if not app_openssl_fullpath: |
245 | raise osv.except_osv(_("Error!"), _( |
246 | "Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"%(app_openssl) )) |
247 | @@ -246,8 +271,8 @@ |
248 | output.close() |
249 | return result |
250 | |
251 | - def _sign(self, fname, fname_xslt, fname_key, fname_out, encrypt='sha1', |
252 | - type_key='PEM'): |
253 | + def _sign(self, cr, uid, ids, fname, fname_xslt, fname_key, fname_out, encrypt='sha1', |
254 | + type_key='PEM', context=None): |
255 | """ |
256 | @params fname : Path and name of the XML of Facturae |
257 | @params fname_xslt : Path where is located the file 'Cadena Original'.xslt |
258 | @@ -256,6 +281,10 @@ |
259 | @params encrypt : Type of encryptation for file |
260 | @params type_key : Type of KEY |
261 | """ |
262 | + if context is None: |
263 | + context = {} |
264 | + msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = \ |
265 | + facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context) |
266 | result = "" |
267 | cmd = '' |
268 | if type_key == 'PEM': |
269 | @@ -275,8 +304,12 @@ |
270 | output.close() |
271 | return result |
272 | |
273 | - def check_xml_scheme(self, fname_xml, fname_scheme, fname_out, type_scheme="xsd"): |
274 | + def check_xml_scheme(self, cr, uid, ids, fname_xml, fname_scheme, fname_out, type_scheme="xsd", |
275 | + context=None): |
276 | #xmlstarlet val -e --xsd cfdv2.xsd cfd_example.xml |
277 | + if context is None: |
278 | + context = {} |
279 | + msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context) |
280 | if app_xmlstarlet_fullpath: |
281 | cmd = '' |
282 | if type_scheme == 'xsd': |
283 | |
284 | === modified file 'l10n_mx_facturae_pac/invoice.py' |
285 | --- l10n_mx_facturae_pac/invoice.py 2013-10-10 01:02:59 +0000 |
286 | +++ l10n_mx_facturae_pac/invoice.py 2013-11-14 19:53:26 +0000 |
287 | @@ -172,7 +172,7 @@ |
288 | nodeComprobante.setAttribute("sello", sign_str) |
289 | data_dict[comprobante]['sello'] = sign_str |
290 | |
291 | - noCertificado = self._get_noCertificado(context['fname_cer']) |
292 | + noCertificado = self._get_noCertificado(cr, uid, ids, context['fname_cer']) |
293 | if not noCertificado: |
294 | raise osv.except_osv(_('Error in No. Certificate !'), _( |
295 | "Can't get the Certificate Number of the voucher.\nCkeck your configuration.\n%s") % (msg2)) |
296 | @@ -231,8 +231,8 @@ |
297 | # If dir is in path, save it on real_path |
298 | fname_scheme = my_path and os.path.join(my_path, 'l10n_mx_facturae', 'SAT', facturae_type + facturae_version + '.' + scheme_type) or '' |
299 | #fname_scheme = os.path.join(tools.config["addons_path"], u'l10n_mx_facturae', u'SAT', facturae_type + facturae_version + '.' + scheme_type ) |
300 | - fname_out = certificate_lib.b64str_to_tempfile( base64.encodestring(''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + '__schema_validation_result__' ) |
301 | - result = certificate_lib.check_xml_scheme(fname_data_xml, fname_scheme, fname_out) |
302 | + fname_out = certificate_lib.b64str_to_tempfile(cr, uid, ids, base64.encodestring(''), file_suffix='.txt', file_prefix='openerp__' + (False or '') + '__schema_validation_result__' ) |
303 | + result = certificate_lib.check_xml_scheme(cr, uid, ids, fname_data_xml, fname_scheme, fname_out) |
304 | if result: #Valida el xml mediante el archivo xsd |
305 | raise osv.except_osv('Error al validar la estructura del xml!', 'Validación de XML versión %s:\n%s'%(facturae_version, result)) |
306 | return True |
307 | |
308 | === modified file 'l10n_mx_ir_attachment_facturae/__openerp__.py' |
309 | --- l10n_mx_ir_attachment_facturae/__openerp__.py 2013-08-16 18:47:52 +0000 |
310 | +++ l10n_mx_ir_attachment_facturae/__openerp__.py 2013-11-14 19:53:26 +0000 |
311 | @@ -36,6 +36,7 @@ |
312 | "email_template_multicompany", |
313 | "l10n_mx_facturae_groups", |
314 | "account_cancel", |
315 | + "l10n_mx_facturae_lib", |
316 | ], |
317 | "demo" : ["demo/l10n_mx_facturae_email_demo.xml", |
318 | ], |
319 | |
320 | === modified file 'l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py' |
321 | --- l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py 2013-11-13 00:00:34 +0000 |
322 | +++ l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py 2013-11-14 19:53:26 +0000 |
323 | @@ -117,9 +117,13 @@ |
324 | return True |
325 | |
326 | def signal_confirm(self, cr, uid, ids, context=None): |
327 | + if context is None: |
328 | + context = {} |
329 | + from l10n_mx_facturae_lib import facturae_lib |
330 | + msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context) |
331 | + if msj: |
332 | + raise osv.except_osv(_('Warning'),_(msj)) |
333 | try: |
334 | - if context is None: |
335 | - context = {} |
336 | invoice_obj = self.pool.get('account.invoice') |
337 | attach = '' |
338 | msj = '' |
se agregó raise en el caso que no existan dichos paquetes instalados (xsltproc, openssl, xmlstarlet)