Merge lp:~vauxoo/openerp-mexico-localization/7.0-l10n_mx_facturae_mx-remove_cr_commit_dev_carlos-ref-moy into lp:~vauxoo/openerp-mexico-localization/7.0-l10n_mx_facturae_mx-remove_cr_commit_dev_carlos

Proposed by Moisés López - http://www.vauxoo.com
Status: Merged
Merged at revision: 280
Proposed branch: lp:~vauxoo/openerp-mexico-localization/7.0-l10n_mx_facturae_mx-remove_cr_commit_dev_carlos-ref-moy
Merge into: lp:~vauxoo/openerp-mexico-localization/7.0-l10n_mx_facturae_mx-remove_cr_commit_dev_carlos
Diff against target: 1511 lines (+652/-409) (has conflicts)
12 files modified
l10n_mx_facturae/invoice.py (+2/-2)
l10n_mx_facturae/test/account_invoice_cfd.yml (+69/-12)
l10n_mx_facturae_cbb/test/account_invoice_cbb.yml (+67/-9)
l10n_mx_facturae_pac/invoice.py (+2/-2)
l10n_mx_facturae_pac_sf/demo/l10n_mx_facturae_seq_demo.xml (+1/-1)
l10n_mx_facturae_pac_sf/invoice.py (+2/-218)
l10n_mx_facturae_pac_sf/ir_attachment_facturae.py (+259/-5)
l10n_mx_facturae_pac_sf/ir_sequence_approval.py (+1/-1)
l10n_mx_facturae_pac_sf/test/account_invoice_cfdi_pac_sf.yml (+74/-2)
l10n_mx_facturae_report/report/invoice_facturae_html.mako (+6/-6)
l10n_mx_ir_attachment_facturae/invoice.py (+39/-44)
l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py (+130/-107)
Text conflict in l10n_mx_facturae_pac_sf/test/account_invoice_cfdi_pac_sf.yml
To merge this branch: bzr merge lp:~vauxoo/openerp-mexico-localization/7.0-l10n_mx_facturae_mx-remove_cr_commit_dev_carlos-ref-moy
Reviewer Review Type Date Requested Status
Vauxoo Pending
Review via email: mp+181982@code.launchpad.net

Description of the change

Refactory and changes for multi-driver and test

To post a comment you must log in.

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-08-16 19:13:46 +0000
3+++ l10n_mx_facturae/invoice.py 2013-08-25 06:44:24 +0000
4@@ -457,7 +457,7 @@
5 cr, uid, sequence_app_id[0], context=context).type
6 if invoice_datetime < '2012-07-01 00:00:00':
7 return file_globals
8- elif type_inv == 'cfd22':
9+ elif 'cfd' in type_inv and not 'cfdi' in type_inv:
10 # Search char "," for addons_path, now is multi-path
11 all_paths = tools.config["addons_path"].split(",")
12 for my_path in all_paths:
13@@ -467,7 +467,7 @@
14 my_path, 'l10n_mx_facturae', 'SAT',
15 'cadenaoriginal_2_2_l.xslt') or ''
16 break
17- elif type_inv == 'cfdi32':
18+ elif 'cfdi' in type_inv:
19 # Search char "," for addons_path, now is multi-path
20 all_paths = tools.config["addons_path"].split(",")
21 for my_path in all_paths:
22
23=== modified file 'l10n_mx_facturae/test/account_invoice_cfd.yml'
24--- l10n_mx_facturae/test/account_invoice_cfd.yml 2013-08-23 23:07:47 +0000
25+++ l10n_mx_facturae/test/account_invoice_cfd.yml 2013-08-25 06:44:24 +0000
26@@ -11,7 +11,7 @@
27 name: 'Test cfd Customer Invoice'
28 invoice_line:
29 - product_id: product.product_product_5
30- quantity: 20.0
31+ quantity: 22.0
32 -
33 I rewrite the journal field (BUG I need overwrite two times this field for done! only in test yaml)
34 -
35@@ -40,12 +40,39 @@
36 I confirm l10n_mx attachment facturae cfd by clicking on confirm button
37 -
38 !python {model: ir.attachment.facturae.mx}: |
39- import netsvc
40+ import netsvc, tools, os, base64
41 wf_service = netsvc.LocalService("workflow")
42 cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
43 cfd_id = cfd_ids and cfd_ids[0] or False
44 if cfd_id:
45- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cfd_id, 'action_confirm', cr)
46+ cfd = self.browse(cr, uid, [cfd_id])[0]
47+ self.signal_confirm(cr, uid , cfd_ids ,context=context)
48+ print "cfd_state",cfd.state
49+ print "cfd_msj",cfd.msj
50+ state = cfd.state
51+-
52+ I check that the state in l10n_mx attachment facturae cfd is "Confirmed"
53+-
54+ !python {model: ir.attachment.facturae.mx}: |
55+ import netsvc, tools, os, base64
56+ cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
57+ cfd_id = cfd_ids and cfd_ids[0] or False
58+ state = 'no attach file'
59+ if cfd_id:
60+ cfd = self.browse(cr, uid, [cfd_id])[0]
61+ print "cfd_state",cfd.state
62+ print "cfd_msj",cfd.msj
63+ state = cfd.state
64+ ir_attach_facturae_mx = cfd.file_input and cfd.file_input or False
65+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
66+ if fdata:
67+ if tools.config['test_report_directory']:
68+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae' + '_' + \
69+ 'account_invoice_cfd0' + '_' + 'confirmed' + '-' + ir_attach_facturae_mx.datas_fname)\
70+ , 'wb+').write( base64.decodestring( fdata ) )
71+ else:
72+ state = 'no data in attach file'
73+ assert state=='confirmed', 'No confirmed state l10n_mx attachment facturae cfd'
74 -
75 I sign l10n_mx attachment facturae cfd by clicking on sign button
76 -
77@@ -55,17 +82,33 @@
78 cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
79 cfd_id = cfd_ids and cfd_ids[0] or False
80 if cfd_id:
81- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cfd_id, 'action_sign', cr)
82+ cfd = self.browse(cr, uid, [cfd_id], context=context)[0]
83+ self.signal_sign(cr, uid, cfd_ids, context=context)
84+ print "cfd_state",cfd.state
85+ print "cfd_msj",cfd.msj
86+ state = cfd.state
87 -
88 I check that the state in l10n_mx attachment facturae cfd is "Signed"
89 -
90 !python {model: ir.attachment.facturae.mx}: |
91+ import netsvc, tools, os, base64
92 cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
93- cfd_id = cfd_ids and cfd_ids[0] or False
94- state = None
95+ cfd_id = len(cfd_ids) and cfd_ids[0] or False
96+ state = 'no attach file'
97 if cfd_id:
98- cfd = self.browse(cr, uid, [cfd_id])[0]
99+ cfd = self.browse(cr, uid, [cfd_id], context=context)[0]
100 state = cfd.state
101+ ir_attach_facturae_mx = cfd.file_xml_sign and cfd.file_xml_sign or False
102+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
103+ if fdata:
104+ state = cfd.state
105+ if tools.config['test_report_directory']:
106+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae' + '_' + \
107+ 'account_invoice_cfd0' + '_' + 'signed' + '-' + ir_attach_facturae_mx.datas_fname),\
108+ 'wb+').write( base64.decodestring( fdata ) )
109+ else:
110+ state = 'no data in attach file'
111+ print "state",state
112 assert state=='signed', 'No signed state l10n_mx attachment facturae cfd'
113 -
114 I generate a printable l10n_mx attachment facturae cfd by clicking on printable button
115@@ -76,17 +119,32 @@
116 cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
117 cfd_id = cfd_ids and cfd_ids[0] or False
118 if cfd_id:
119- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cfd_id, 'action_printable', cr)
120+ cfd = self.browse(cr, uid, [cfd_id])[0]
121+ self.signal_printable(cr, uid , cfd_ids ,context=context)
122+ print "cfd_state",cfd.state
123+ print "cfd_msj",cfd.msj
124+ state = cfd.state
125 -
126 I check that the state in l10n_mx attachment facturae cfd is Printable
127 -
128 !python {model: ir.attachment.facturae.mx}: |
129+ import netsvc, tools, os, base64
130 cfd_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfd0") ), ('state', '<>', 'cancel')], limit=1)
131 cfd_id = cfd_ids and cfd_ids[0] or False
132 state = None
133+ state = 'no attach file'
134 if cfd_id:
135- cfd = self.browse(cr, uid, [cfd_id])[0]
136- state = cfd.state
137+ cfd = self.browse(cr, uid, [cfd_id], context=context)[0]
138+ ir_attach_facturae_mx = cfd.file_pdf and cfd.file_pdf or False
139+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
140+ if fdata:
141+ state = cfd.state
142+ if tools.config['test_report_directory']:
143+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae' + '_' + \
144+ 'account_invoice_cfd0' + '_' + 'printable' + '-' + ir_attach_facturae_mx.datas_fname),\
145+ 'wb+').write( base64.decodestring( fdata ) )
146+ else:
147+ state = 'no data in attach file'
148 assert state=='printable', 'No printable state l10n_mx attachment facturae cfd'
149 -
150 I added update_posted in journal
151@@ -102,7 +160,7 @@
152 cfd_id = cfd_ids and cfd_ids[0] or False
153 if cfd_id:
154 self.signal_cancel(cr, uid , cfd_ids ,context=context)
155- cfd= self.browse(cr, uid, [cfd_id])[0]
156+ cfd = self.browse(cr, uid, [cfd_id])[0]
157 state = cfd.state
158 assert state=='cancel', 'No cancel state l10n_mx attachment facturae cfd'
159 -
160@@ -115,4 +173,3 @@
161 -
162 !assert {model: account.invoice, id: account_invoice_cfd0}:
163 - move_id.name == None
164-
165
166=== modified file 'l10n_mx_facturae_cbb/test/account_invoice_cbb.yml'
167--- l10n_mx_facturae_cbb/test/account_invoice_cbb.yml 2013-08-23 23:07:47 +0000
168+++ l10n_mx_facturae_cbb/test/account_invoice_cbb.yml 2013-08-25 06:44:24 +0000
169@@ -1,5 +1,5 @@
170 -
171- To test the Mexican Electronic Invoice CBB
172+ To test the Mexican Electronic Invoice cbb
173 -
174 I create a cbb customer invoice
175 -
176@@ -40,12 +40,40 @@
177 I confirm l10n_mx attachment facturae cbb by clicking on confirm button
178 -
179 !python {model: ir.attachment.facturae.mx}: |
180- import netsvc
181+ import netsvc, tools, os, base64
182 wf_service = netsvc.LocalService("workflow")
183 cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
184 cbb_id = cbb_ids and cbb_ids[0] or False
185 if cbb_id:
186- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cbb_id, 'action_confirm', cr)
187+ cbb = self.browse(cr, uid, [cbb_id])[0]
188+ self.signal_confirm(cr, uid , cbb_ids ,context=context)
189+ print "cbb_state",cbb.state
190+ print "cbb_msj",cbb.msj
191+ state = cbb.state
192+-
193+ I check that the state in l10n_mx attachment facturae cbb is "Confirmed"
194+-
195+ !python {model: ir.attachment.facturae.mx}: |
196+ import netsvc, tools, os, base64
197+ cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
198+ cbb_id = cbb_ids and cbb_ids[0] or False
199+ state = 'no attach file'
200+ if cbb_id:
201+ cbb = self.browse(cr, uid, [cbb_id])[0]
202+ print "cbb_state",cbb.state
203+ print "cbb_msj",cbb.msj
204+ state = cbb.state
205+ #This state no generate a new attch
206+ #ir_attach_facturae_mx = cbb.file_input and cbb.file_input or False
207+ #fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
208+ #if fdata:
209+ #if tools.config['test_report_directory']:
210+ #open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_cbb' + '_' + \
211+ #'account_invoice_cbb0' + '_' + 'confirmed' + '-' + ir_attach_facturae_mx.datas_fname)\
212+ #, 'wb+').write( base64.decodestring( fdata ) )
213+ #else:
214+ #state = 'no data in attach file'
215+ assert state=='confirmed', 'No confirmed state l10n_mx attachment facturae cbb'
216 -
217 I sign l10n_mx attachment facturae cbb by clicking on sign button
218 -
219@@ -55,17 +83,32 @@
220 cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
221 cbb_id = cbb_ids and cbb_ids[0] or False
222 if cbb_id:
223- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cbb_id, 'action_sign', cr)
224+ cbb = self.browse(cr, uid, [cbb_id], context=context)[0]
225+ self.signal_sign(cr, uid, cbb_ids, context=context)
226+ print "cbb_state",cbb.state
227+ print "cbb_msj",cbb.msj
228+ state = cbb.state
229 -
230 I check that the state in l10n_mx attachment facturae cbb is "Signed"
231 -
232 !python {model: ir.attachment.facturae.mx}: |
233+ import netsvc, tools, os, base64
234 cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
235- cbb_id = cbb_ids and cbb_ids[0] or False
236- state = None
237+ cbb_id = len(cbb_ids) and cbb_ids[0] or False
238+ state = 'no attach file'
239 if cbb_id:
240- cbb = self.browse(cr, uid, [cbb_id])[0]
241+ cbb = self.browse(cr, uid, [cbb_id], context=context)[0]
242 state = cbb.state
243+ ir_attach_facturae_mx = cbb.file_xml_sign and cbb.file_xml_sign or False
244+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
245+ #~ if fdata:
246+ #~ if tools.config['test_report_directory']:
247+ #~ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_cbb' + '_' + \
248+ #~ 'account_invoice_cbb0' + '_' + 'signed' + '-' + ir_attach_facturae_mx.datas_fname),\
249+ #~ 'wb+').write( base64.decodestring( fdata ) )
250+ #~ else:
251+ #~ state = 'no data in attach file'
252+ print "state",state
253 assert state=='signed', 'No signed state l10n_mx attachment facturae cbb'
254 -
255 I generate a printable l10n_mx attachment facturae cbb by clicking on printable button
256@@ -76,17 +119,32 @@
257 cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
258 cbb_id = cbb_ids and cbb_ids[0] or False
259 if cbb_id:
260- wf_service.trg_validate(uid, 'ir.attachment.facturae.mx', cbb_id, 'action_printable', cr)
261+ cbb = self.browse(cr, uid, [cbb_id])[0]
262+ self.signal_printable(cr, uid , cbb_ids ,context=context)
263+ print "cbb_state",cbb.state
264+ print "cbb_msj",cbb.msj
265+ state = cbb.state
266 -
267 I check that the state in l10n_mx attachment facturae cbb is Printable
268 -
269 !python {model: ir.attachment.facturae.mx}: |
270+ import netsvc, tools, os, base64
271 cbb_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cbb0") ), ('state', '<>', 'cancel')], limit=1)
272 cbb_id = cbb_ids and cbb_ids[0] or False
273 state = None
274+ state = 'no attach file'
275 if cbb_id:
276- cbb = self.browse(cr, uid, [cbb_id])[0]
277+ cbb = self.browse(cr, uid, [cbb_id], context=context)[0]
278+ ir_attach_facturae_mx = cbb.file_pdf and cbb.file_pdf or False
279+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
280 state = cbb.state
281+ if fdata:
282+ if tools.config['test_report_directory']:
283+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_cbb' + '_' + \
284+ 'account_invoice_cbb0' + '_' + 'printable' + '-' + ir_attach_facturae_mx.datas_fname),\
285+ 'wb+').write( base64.decodestring( fdata ) )
286+ else:
287+ state = 'no data in attach file'
288 assert state=='printable', 'No printable state l10n_mx attachment facturae cbb'
289 -
290 I added update_posted in journal
291
292=== modified file 'l10n_mx_facturae_pac/invoice.py'
293--- l10n_mx_facturae_pac/invoice.py 2013-07-18 23:34:53 +0000
294+++ l10n_mx_facturae_pac/invoice.py 2013-08-25 06:44:24 +0000
295@@ -55,7 +55,7 @@
296 type_inv = ir_seq_app_obj.browse(
297 cr, uid, sequence_app_id[0], context=context).type
298 for data in datas:
299- if type_inv == 'cfdi32':
300+ if 'cfdi' in type_inv:
301 comprobante = data['Comprobante']
302 rfc = comprobante['Emisor']['rfc']
303 nombre = comprobante['Emisor']['nombre']
304@@ -113,7 +113,7 @@
305 if sequence_app_id:
306 type_inv = ir_seq_app_obj.browse(
307 cr, uid, sequence_app_id[0], context=context).type
308- if type_inv == 'cfdi32':
309+ if 'cfdi' in type_inv:
310 comprobante = 'cfdi:Comprobante'
311 emisor = 'cfdi:Emisor'
312 receptor = 'cfdi:Receptor'
313
314=== modified file 'l10n_mx_facturae_pac_sf/demo/l10n_mx_facturae_seq_demo.xml'
315--- l10n_mx_facturae_pac_sf/demo/l10n_mx_facturae_seq_demo.xml 2013-08-24 21:10:22 +0000
316+++ l10n_mx_facturae_pac_sf/demo/l10n_mx_facturae_seq_demo.xml 2013-08-25 06:44:24 +0000
317@@ -19,7 +19,7 @@
318 <field name="approval_year" eval="time.strftime('%Y')"/>
319 <field name="number_start">1</field>
320 <field name="number_end">9999</field>
321- <field name="type">cfdi32</field>
322+ <field name="type">cfdi32_pac_sf</field>
323 </record>
324
325 <record id="l10n_mx_cfdi_pac_sf_journal_0" model="account.journal">
326
327=== modified file 'l10n_mx_facturae_pac_sf/invoice.py'
328--- l10n_mx_facturae_pac_sf/invoice.py 2013-08-16 15:09:57 +0000
329+++ l10n_mx_facturae_pac_sf/invoice.py 2013-08-25 06:44:24 +0000
330@@ -48,11 +48,6 @@
331 import pytz
332 import time
333 from datetime import datetime, timedelta
334-try:
335- from SOAPpy import WSDL
336-except:
337- print "Package SOAPpy missed"
338- pass
339 import time
340
341
342@@ -243,7 +238,7 @@
343 if sequence_app_id:
344 type_inv = ir_seq_app_obj.browse(
345 cr, uid, sequence_app_id[0], context=context).type
346- if type_inv == 'cfdi32':
347+ if 'cfdi' in type_inv:
348 comprobante = 'cfdi:Comprobante'
349 else:
350 comprobante = 'Comprobante'
351@@ -268,144 +263,7 @@
352 a = timezone_original + ((
353 timezone_present + timezone_original)*-1)
354 return a
355-
356- def _upload_ws_file(self, cr, uid, inv_ids, fdata=None, context={}):
357- """
358- @params fdata : File.xml codification in base64
359- """
360- comprobante = self._get_type_sequence(
361- cr, uid, inv_ids, context=context)
362- pac_params_obj = self.pool.get('params.pac')
363- cfd_data = base64.decodestring(fdata or self.fdata)
364- xml_res_str = xml.dom.minidom.parseString(cfd_data)
365- xml_res_addenda = self.add_addenta_xml(
366- cr, uid, xml_res_str, comprobante, context=context)
367- xml_res_str_addenda = xml_res_addenda.toxml('UTF-8')
368- compr = xml_res_addenda.getElementsByTagName(comprobante)[0]
369- date = compr.attributes['fecha'].value
370- date_format = datetime.strptime(
371- date, '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d')
372- context['date'] = date_format
373- invoice_ids = inv_ids
374- invoice = self.browse(cr, uid, invoice_ids, context=context)[0]
375- currency = invoice.currency_id.name
376- currency_enc = currency.encode('UTF-8', 'strict')
377- rate = invoice.currency_id.rate and (1.0/invoice.currency_id.rate) or 1
378- file = False
379- msg = ''
380- cfdi_xml = False
381- pac_params_ids = pac_params_obj.search(cr, uid, [
382- ('method_type', '=', 'pac_sf_firmar'), (
383- 'company_id', '=', invoice.company_emitter_id.id), (
384- 'active', '=', True)], limit=1, context=context)
385- if pac_params_ids:
386- pac_params = pac_params_obj.browse(
387- cr, uid, pac_params_ids, context)[0]
388- user = pac_params.user
389- password = pac_params.password
390- wsdl_url = pac_params.url_webservice
391- namespace = pac_params.namespace
392- url = 'https://solucionfactible.com/ws/services/Timbrado'
393- testing_url = 'http://testing.solucionfactible.com/ws/services/Timbrado'
394- if (wsdl_url == url) or (wsdl_url == testing_url):
395- pass
396- else:
397- raise osv.except_osv(_('Warning'), _('Web Service URL \
398- o PAC incorrect'))
399- if namespace == 'http://timbrado.ws.cfdi.solucionfactible.com':
400- pass
401- else:
402- raise osv.except_osv(_('Warning'), _(
403- 'Namespace of PAC incorrect'))
404- if 'testing' in wsdl_url:
405- msg += _(u'WARNING, SIGNED IN TEST!!!!\n\n')
406- wsdl_client = WSDL.SOAPProxy(wsdl_url, namespace)
407- if True: # if wsdl_client:
408- file_globals = self._get_file_globals(
409- cr, uid, invoice_ids, context=context)
410- fname_cer_no_pem = file_globals['fname_cer']
411- cerCSD = fname_cer_no_pem and base64.encodestring(
412- open(fname_cer_no_pem, "r").read()) or ''
413- fname_key_no_pem = file_globals['fname_key']
414- keyCSD = fname_key_no_pem and base64.encodestring(
415- open(fname_key_no_pem, "r").read()) or ''
416- cfdi = base64.encodestring(
417- xml_res_str_addenda.replace(codecs.BOM_UTF8, ''))
418- zip = False # Validar si es un comprimido zip, con la extension del archivo
419- contrasenaCSD = file_globals.get('password', '')
420- params = [
421- user, password, cfdi, zip]
422- wsdl_client.soapproxy.config.dumpSOAPOut = 0
423- wsdl_client.soapproxy.config.dumpSOAPIn = 0
424- wsdl_client.soapproxy.config.debug = 0
425- wsdl_client.soapproxy.config.dict_encoding = 'UTF-8'
426- resultado = wsdl_client.timbrar(*params)
427- htz = int(self._get_time_zone(
428- cr, uid, inv_ids, context=context))
429- mensaje = _(tools.ustr(resultado['mensaje']))
430- resultados_mensaje = resultado['resultados'] and \
431- resultado['resultados']['mensaje'] or ''
432- folio_fiscal = resultado['resultados'] and \
433- resultado['resultados']['uuid'] or ''
434- codigo_timbrado = resultado['status'] or ''
435- codigo_validacion = resultado['resultados'] and \
436- resultado['resultados']['status'] or ''
437- if codigo_timbrado == '311' or codigo_validacion == '311':
438- raise osv.except_osv(_('Warning'), _(
439- 'Unauthorized.\nCode 311'))
440- elif codigo_timbrado == '312' or codigo_validacion == '312':
441- raise osv.except_osv(_('Warning'), _(
442- 'Failed to consult the SAT.\nCode 312'))
443- elif codigo_timbrado == '200' and codigo_validacion == '200':
444- fecha_timbrado = resultado[
445- 'resultados']['fechaTimbrado'] or False
446- fecha_timbrado = fecha_timbrado and time.strftime(
447- '%Y-%m-%d %H:%M:%S', time.strptime(
448- fecha_timbrado[:19], '%Y-%m-%dT%H:%M:%S')) or False
449- fecha_timbrado = fecha_timbrado and datetime.strptime(
450- fecha_timbrado, '%Y-%m-%d %H:%M:%S') + timedelta(
451- hours=htz) or False
452- cfdi_data = {
453- 'cfdi_cbb': resultado['resultados']['qrCode'] or False, # ya lo regresa en base64
454- 'cfdi_sello': resultado['resultados'][
455- 'selloSAT'] or False,
456- 'cfdi_no_certificado': resultado['resultados'][
457- 'certificadoSAT'] or False,
458- 'cfdi_cadena_original': resultado['resultados'][
459- 'cadenaOriginal'] or False,
460- 'cfdi_fecha_timbrado': fecha_timbrado,
461- 'cfdi_xml': base64.decodestring(resultado[
462- 'resultados']['cfdiTimbrado'] or ''), # este se necesita en uno que no es base64
463- 'cfdi_folio_fiscal': resultado['resultados']['uuid'] or '',
464- }
465- msg += mensaje + "." + resultados_mensaje + \
466- " Folio Fiscal: " + folio_fiscal + "."
467- msg += _(
468- u"\nMake Sure to the file really has generated correctly to the SAT\nhttps://www.consulta.sat.gob.mx/sicofi_web/moduloECFD_plus/ValidadorCFDI/Validador%20cfdi.html")
469- if cfdi_data.get('cfdi_xml', False):
470- url_pac = '</"%s"><!--Para validar el XML CFDI puede descargar el certificado del PAC desde la siguiente liga: https://solucionfactible.com/cfdi/00001000000102699425.zip-->' % (
471- comprobante)
472- cfdi_data['cfdi_xml'] = cfdi_data[
473- 'cfdi_xml'].replace('</"%s">' % (comprobante), url_pac)
474- file = base64.encodestring(
475- cfdi_data['cfdi_xml'] or '')
476- # self.cfdi_data_write(cr, uid, [invoice.id],
477- # cfdi_data, context=context)
478- cfdi_xml = cfdi_data.pop('cfdi_xml')
479- if cfdi_xml:
480- self.write(cr, uid, inv_ids, cfdi_data)
481- cfdi_data['cfdi_xml'] = cfdi_xml
482- else:
483- msg += _(u"Can't extract the file XML of PAC")
484- else:
485- raise orm.except_orm(_('Warning'), _('Stamped Code: %s.-Validation code %s.-Folio Fiscal: %s.-Stamped Message: %s.-Validation Message: %s.') % (
486- codigo_timbrado, codigo_validacion, folio_fiscal, mensaje, resultados_mensaje))
487- else:
488- msg += 'Not found information from web services of PAC, verify that the configuration of PAC is correct'
489- raise osv.except_osv(_('Warning'), _(
490- 'Not found information from web services of PAC, verify that the configuration of PAC is correct'))
491- return {'file': file, 'msg': msg, 'cfdi_xml': cfdi_xml}
492-
493+
494 def _get_file_cancel(self, cr, uid, inv_ids, context={}):
495 inv_ids = inv_ids[0]
496 atta_obj = self.pool.get('ir.attachment')
497@@ -421,80 +279,6 @@
498 "This invoice hasn't stamped, so that not possible cancel."))
499 return {'file': inv_xml}
500
501- def sf_cancel(self, cr, uid, inv_ids, context=None):
502- msg = ''
503- context_id = inv_ids[0]
504- company_obj = self.pool.get('res.company.facturae.certificate')
505- pac_params_obj = self.pool.get('params.pac')
506- invoice_brw = self.browse(cr, uid, context_id, context)
507- company_brw = company_obj.browse(cr, uid, [
508- invoice_brw.company_id.id], context)[0]
509- pac_params_srch = pac_params_obj.search(cr, uid, [(
510- 'method_type', '=', 'pac_sf_cancelar'), ('company_id', '=',
511- invoice_brw.company_emitter_id.id), (
512- 'active', '=', True)],
513- context=context)
514- if pac_params_srch:
515- pac_params_brw = pac_params_obj.browse(
516- cr, uid, pac_params_srch, context)[0]
517- user = pac_params_brw.user
518- password = pac_params_brw.password
519- wsdl_url = pac_params_brw.url_webservice
520- namespace = pac_params_brw.namespace
521- #---------constantes
522- #~ user = 'testing@solucionfactible.com'
523- #~ password = 'timbrado.SF.16672'
524- #~ wsdl_url = 'http://testing.solucionfactible.com/ws/services/Timbrado?wsdl'
525- #~ namespace = 'http://timbrado.ws.cfdi.solucionfactible.com'
526- wsdl_client = False
527- wsdl_client = WSDL.SOAPProxy(wsdl_url, namespace)
528- if True: # if wsdl_client:
529- file_globals = self._get_file_globals(
530- cr, uid, [context_id], context=context)
531- fname_cer_no_pem = file_globals['fname_cer']
532- cerCSD = fname_cer_no_pem and base64.encodestring(
533- open(fname_cer_no_pem, "r").read()) or ''
534- fname_key_no_pem = file_globals['fname_key']
535- keyCSD = fname_key_no_pem and base64.encodestring(
536- open(fname_key_no_pem, "r").read()) or ''
537- zip = False # Validar si es un comprimido zip, con la extension del archivo
538- contrasenaCSD = file_globals.get('password', '')
539- uuids = invoice_brw.cfdi_folio_fiscal # cfdi_folio_fiscal
540- params = [
541- user, password, uuids, cerCSD, keyCSD, contrasenaCSD]
542- wsdl_client.soapproxy.config.dumpSOAPOut = 0
543- wsdl_client.soapproxy.config.dumpSOAPIn = 0
544- wsdl_client.soapproxy.config.debug = 0
545- wsdl_client.soapproxy.config.dict_encoding = 'UTF-8'
546- result = wsdl_client.cancelar(*params)
547- codigo_cancel = result['status'] or ''
548- status_cancel = result['resultados'] and result[
549- 'resultados']['status'] or ''
550- uuid_nvo = result['resultados'] and result[
551- 'resultados']['uuid'] or ''
552- mensaje_cancel = _(tools.ustr(result['mensaje']))
553- msg_nvo = result['resultados'] and result[
554- 'resultados']['mensaje'] or ''
555- status_uuid = result['resultados'] and result[
556- 'resultados']['statusUUID'] or ''
557- folio_cancel = result['resultados'] and result[
558- 'resultados']['uuid'] or ''
559- if codigo_cancel == '200' and status_cancel == '200' and\
560- status_uuid == '201':
561- msg += mensaje_cancel + _('\n- The process of cancellation\
562- has completed correctly.\n- The uuid cancelled is:\
563- ') + folio_cancel
564- self.write(cr, uid, context_id, {
565- 'cfdi_fecha_cancelacion': time.strftime(
566- '%Y-%m-%d %H:%M:%S')})
567- else:
568- raise orm.except_orm(_('Warning'), _('Cancel Code: %s.-Status code %s.-Status UUID: %s.-Folio Cancel: %s.-Cancel Message: %s.-Answer Message: %s.') % (
569- codigo_cancel, status_cancel, status_uuid, folio_cancel, mensaje_cancel, msg_nvo))
570- else:
571- msg = _(
572- 'Not found information of webservices of PAC, verify that the configuration of PAC is correct')
573- return {'message': msg, 'status_uuid': status_uuid}
574-
575 def write_cfd_data(self, cr, uid, ids, cfd_datas, context={}):
576 """
577 @param cfd_datas : Dictionary with data that is used in facturae CFDI
578
579=== modified file 'l10n_mx_facturae_pac_sf/ir_attachment_facturae.py'
580--- l10n_mx_facturae_pac_sf/ir_attachment_facturae.py 2013-07-25 00:23:58 +0000
581+++ l10n_mx_facturae_pac_sf/ir_attachment_facturae.py 2013-08-25 06:44:24 +0000
582@@ -25,9 +25,35 @@
583 #
584 ##############################################################################
585
586-from openerp.osv import fields, osv
587-from openerp.tools.translate import _
588-
589+from openerp.tools.translate import _
590+from openerp.osv import fields, osv, orm
591+from openerp import tools
592+from openerp import netsvc
593+from openerp.tools.misc import ustr
594+import wizard
595+import base64
596+import xml.dom.minidom
597+import time
598+import StringIO
599+import csv
600+import tempfile
601+import os
602+import sys
603+import codecs
604+from xml.dom import minidom
605+import urllib
606+import pooler
607+from openerp.tools.translate import _
608+from datetime import datetime, timedelta
609+from pytz import timezone
610+import pytz
611+import time
612+from openerp import tools
613+try:
614+ from SOAPpy import WSDL
615+except:
616+ print "Package SOAPpy missed"#TODO: Warning message
617+ pass
618
619 class ir_attachment_facturae_mx(osv.Model):
620 _inherit = 'ir.attachment.facturae.mx'
621@@ -36,12 +62,240 @@
622 types = super(ir_attachment_facturae_mx, self)._get_type(
623 cr, uid, ids, context=context)
624 types.extend([
625- ('cfdi32', 'CFDI 3.2 Solución Factible'),
626+ ('cfdi32_pac_sf', 'CFDI 3.2 Solución Factible'),
627 ])
628 return types
629-
630+
631+ def get_driver_fc_sign(self):
632+ factura_mx_type__fc = super(ir_attachment_facturae_mx, self).get_driver_fc_sign()
633+ if factura_mx_type__fc == None:
634+ factura_mx_type__fc = {}
635+ factura_mx_type__fc.update({'cfdi32_pac_sf': self._upload_ws_file})
636+ return factura_mx_type__fc
637+
638+ def get_driver_fc_cancel(self):
639+ factura_mx_type__fc = super(ir_attachment_facturae_mx, self).get_driver_fc_cancel()
640+ if factura_mx_type__fc == None:
641+ factura_mx_type__fc = {}
642+ factura_mx_type__fc.update({'cfdi32_pac_sf': self.sf_cancel})
643+ return factura_mx_type__fc
644+
645 _columns = {
646 'type': fields.selection(_get_type, 'Type', type='char', size=64,
647 required=True, readonly=True, help="Type of Electronic Invoice"),
648 }
649+
650+ def sf_cancel(self, cr, uid, ids, context=None):
651+ msg = ''
652+ certificate_obj = self.pool.get('res.company.facturae.certificate')
653+ pac_params_obj = self.pool.get('params.pac')
654+ invoice_obj = self.pool.get('account.invoice')
655+ for ir_attachment_facturae_mx_id in self.browse(cr, uid, ids, context=context):
656+ status = False
657+ invoice = ir_attachment_facturae_mx_id.invoice_id
658+ pac_params_ids = pac_params_obj.search(cr, uid, [
659+ ('method_type', '=', 'pac_sf_cancelar'),
660+ ('company_id', '=', invoice.company_emitter_id.id),
661+ ('active', '=', True),
662+ ], limit=1, context=context)
663+ pac_params_id = pac_params_ids and pac_params_ids[0] or False
664+ if pac_params_id:
665+ file_globals = invoice_obj._get_file_globals(
666+ cr, uid, [invoice.id], context=context)
667+ pac_params_brw = pac_params_obj.browse(
668+ cr, uid, [pac_params_id], context=context)[0]
669+ user = pac_params_brw.user
670+ password = pac_params_brw.password
671+ wsdl_url = pac_params_brw.url_webservice
672+ namespace = pac_params_brw.namespace
673+ wsdl_client = False
674+ wsdl_client = WSDL.SOAPProxy(wsdl_url, namespace)
675+ fname_cer_no_pem = file_globals['fname_cer']
676+ cerCSD = fname_cer_no_pem and base64.encodestring(
677+ open(fname_cer_no_pem, "r").read()) or ''
678+ fname_key_no_pem = file_globals['fname_key']
679+ keyCSD = fname_key_no_pem and base64.encodestring(
680+ open(fname_key_no_pem, "r").read()) or ''
681+ zip = False # Validar si es un comprimido zip, con la extension del archivo
682+ contrasenaCSD = file_globals.get('password', '')
683+ uuids = invoice.cfdi_folio_fiscal # cfdi_folio_fiscal
684+ params = [
685+ user, password, uuids, cerCSD, keyCSD, contrasenaCSD]
686+ wsdl_client.soapproxy.config.dumpSOAPOut = 0
687+ wsdl_client.soapproxy.config.dumpSOAPIn = 0
688+ wsdl_client.soapproxy.config.debug = 0
689+ wsdl_client.soapproxy.config.dict_encoding = 'UTF-8'
690+ result = wsdl_client.cancelar(*params)
691+ codigo_cancel = result['status'] or ''
692+ status_cancel = result['resultados'] and result[
693+ 'resultados']['status'] or ''
694+ uuid_nvo = result['resultados'] and result[
695+ 'resultados']['uuid'] or ''
696+ mensaje_cancel = _(tools.ustr(result['mensaje']))
697+ msg_nvo = result['resultados'] and result[
698+ 'resultados']['mensaje'] or ''
699+ status_uuid = result['resultados'] and result[
700+ 'resultados']['statusUUID'] or ''
701+ folio_cancel = result['resultados'] and result[
702+ 'resultados']['uuid'] or ''
703+ if codigo_cancel == '200' and status_cancel == '200' and\
704+ status_uuid == '201':
705+ msg += mensaje_cancel + _('\n- The process of cancellation\
706+ has completed correctly.\n- The uuid cancelled is:\
707+ ') + folio_cancel
708+ invoice_obj.write(cr, uid, [invoice.id], {
709+ 'cfdi_fecha_cancelacion': time.strftime(
710+ '%Y-%m-%d %H:%M:%S')
711+ })
712+ status = True
713+ else:
714+ raise orm.except_orm(_('Warning'), _('Cancel Code: %s.-Status code %s.-Status UUID: %s.-Folio Cancel: %s.-Cancel Message: %s.-Answer Message: %s.') % (
715+ codigo_cancel, status_cancel, status_uuid, folio_cancel, mensaje_cancel, msg_nvo))
716+ else:
717+ msg = _(
718+ 'Not found information of webservices of PAC, verify that the configuration of PAC is correct')
719+ return {'message': msg, 'status_uuid': status_uuid, 'status': status}
720+
721+ def _upload_ws_file(self, cr, uid, ids, fdata=None, context={}):
722+ """
723+ @params fdata : File.xml codification in base64
724+ """
725+ invoice_obj = self.pool.get('account.invoice')
726+ pac_params_obj = invoice_obj.pool.get('params.pac')
727+ for ir_attachment_facturae_mx_id in self.browse(cr, uid, ids, context=context):
728+ invoice = ir_attachment_facturae_mx_id.invoice_id
729+ comprobante = invoice_obj._get_type_sequence(
730+ cr, uid, [invoice.id], context=context)
731+ cfd_data = base64.decodestring(fdata or invoice_obj.fdata)
732+ xml_res_str = xml.dom.minidom.parseString(cfd_data)
733+ xml_res_addenda = invoice_obj.add_addenta_xml(
734+ cr, uid, xml_res_str, comprobante, context=context)
735+ xml_res_str_addenda = xml_res_addenda.toxml('UTF-8')
736+ xml_res_str_addenda = xml_res_str_addenda.replace(codecs.BOM_UTF8, '')
737+
738+ if tools.config['test_report_directory']:#TODO: Add if test-enabled:
739+ ir_attach_facturae_mx_file_input = ir_attachment_facturae_mx_id.file_input and ir_attachment_facturae_mx_id.file_input or False
740+ fname_suffix = ir_attach_facturae_mx_file_input and ir_attach_facturae_mx_file_input.datas_fname or ''
741+ open( os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_pac_sf' + '_' + \
742+ 'before_upload' + '-' + fname_suffix), 'wb+').write( xml_res_str_addenda )
743+ compr = xml_res_addenda.getElementsByTagName(comprobante)[0]
744+ date = compr.attributes['fecha'].value
745+ date_format = datetime.strptime(
746+ date, '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d')
747+ context['date'] = date_format
748+ invoice_ids = [invoice.id]
749+ file = False
750+ msg = ''
751+ cfdi_xml = False
752+ pac_params_ids = pac_params_obj.search(cr, uid, [
753+ ('method_type', '=', 'pac_sf_firmar'), (
754+ 'company_id', '=', invoice.company_emitter_id.id), (
755+ 'active', '=', True)], limit=1, context=context)
756+ if pac_params_ids:
757+ pac_params = pac_params_obj.browse(
758+ cr, uid, pac_params_ids, context)[0]
759+ user = pac_params.user
760+ password = pac_params.password
761+ wsdl_url = pac_params.url_webservice
762+ namespace = pac_params.namespace
763+ url = 'https://solucionfactible.com/ws/services/Timbrado'
764+ testing_url = 'http://testing.solucionfactible.com/ws/services/Timbrado'
765+ if (wsdl_url == url) or (wsdl_url == testing_url):
766+ pass
767+ else:
768+ raise osv.except_osv(_('Warning'), _('Web Service URL \
769+ o PAC incorrect'))
770+ if namespace == 'http://timbrado.ws.cfdi.solucionfactible.com':
771+ pass
772+ else:
773+ raise osv.except_osv(_('Warning'), _(
774+ 'Namespace of PAC incorrect'))
775+ if 'testing' in wsdl_url:
776+ msg += _(u'WARNING, SIGNED IN TEST!!!!\n\n')
777+ wsdl_client = WSDL.SOAPProxy(wsdl_url, namespace)
778+ if True: # if wsdl_client:
779+ file_globals = invoice_obj._get_file_globals(
780+ cr, uid, invoice_ids, context=context)
781+ fname_cer_no_pem = file_globals['fname_cer']
782+ cerCSD = fname_cer_no_pem and base64.encodestring(
783+ open(fname_cer_no_pem, "r").read()) or ''
784+ fname_key_no_pem = file_globals['fname_key']
785+ keyCSD = fname_key_no_pem and base64.encodestring(
786+ open(fname_key_no_pem, "r").read()) or ''
787+ cfdi = base64.encodestring(xml_res_str_addenda)
788+ zip = False # Validar si es un comprimido zip, con la extension del archivo
789+ contrasenaCSD = file_globals.get('password', '')
790+ params = [
791+ user, password, cfdi, zip]
792+ wsdl_client.soapproxy.config.dumpSOAPOut = 0
793+ wsdl_client.soapproxy.config.dumpSOAPIn = 0
794+ wsdl_client.soapproxy.config.debug = 0
795+ wsdl_client.soapproxy.config.dict_encoding = 'UTF-8'
796+ resultado = wsdl_client.timbrar(*params)
797+ htz = int(invoice_obj._get_time_zone(
798+ cr, uid, [ir_attachment_facturae_mx_id.invoice_id.id], context=context))
799+ mensaje = _(tools.ustr(resultado['mensaje']))
800+ resultados_mensaje = resultado['resultados'] and \
801+ resultado['resultados']['mensaje'] or ''
802+ folio_fiscal = resultado['resultados'] and \
803+ resultado['resultados']['uuid'] or ''
804+ codigo_timbrado = resultado['status'] or ''
805+ codigo_validacion = resultado['resultados'] and \
806+ resultado['resultados']['status'] or ''
807+ if codigo_timbrado == '311' or codigo_validacion == '311':
808+ raise osv.except_osv(_('Warning'), _(
809+ 'Unauthorized.\nCode 311'))
810+ elif codigo_timbrado == '312' or codigo_validacion == '312':
811+ raise osv.except_osv(_('Warning'), _(
812+ 'Failed to consult the SAT.\nCode 312'))
813+ elif codigo_timbrado == '200' and codigo_validacion == '200':
814+ fecha_timbrado = resultado[
815+ 'resultados']['fechaTimbrado'] or False
816+ fecha_timbrado = fecha_timbrado and time.strftime(
817+ '%Y-%m-%d %H:%M:%S', time.strptime(
818+ fecha_timbrado[:19], '%Y-%m-%dT%H:%M:%S')) or False
819+ fecha_timbrado = fecha_timbrado and datetime.strptime(
820+ fecha_timbrado, '%Y-%m-%d %H:%M:%S') + timedelta(
821+ hours=htz) or False
822+ cfdi_data = {
823+ 'cfdi_cbb': resultado['resultados']['qrCode'] or False, # ya lo regresa en base64
824+ 'cfdi_sello': resultado['resultados'][
825+ 'selloSAT'] or False,
826+ 'cfdi_no_certificado': resultado['resultados'][
827+ 'certificadoSAT'] or False,
828+ 'cfdi_cadena_original': resultado['resultados'][
829+ 'cadenaOriginal'] or False,
830+ 'cfdi_fecha_timbrado': fecha_timbrado,
831+ 'cfdi_xml': base64.decodestring(resultado[
832+ 'resultados']['cfdiTimbrado'] or ''), # este se necesita en uno que no es base64
833+ 'cfdi_folio_fiscal': resultado['resultados']['uuid'] or '',
834+ }
835+ msg += mensaje + "." + resultados_mensaje + \
836+ " Folio Fiscal: " + folio_fiscal + "."
837+ msg += _(
838+ u"\nMake Sure to the file really has generated correctly to the SAT\nhttps://www.consulta.sat.gob.mx/sicofi_web/moduloECFD_plus/ValidadorCFDI/Validador%20cfdi.html")
839+ if cfdi_data.get('cfdi_xml', False):
840+ url_pac = '</"%s"><!--Para validar el XML CFDI puede descargar el certificado del PAC desde la siguiente liga: https://solucionfactible.com/cfdi/00001000000102699425.zip-->' % (
841+ comprobante)
842+ cfdi_data['cfdi_xml'] = cfdi_data[
843+ 'cfdi_xml'].replace('</"%s">' % (comprobante), url_pac)
844+ file = base64.encodestring(
845+ cfdi_data['cfdi_xml'] or '')
846+ # invoice_obj.cfdi_data_write(cr, uid, [invoice.id],
847+ # cfdi_data, context=context)
848+ cfdi_xml = cfdi_data.pop('cfdi_xml')
849+ if cfdi_xml:
850+ invoice_obj.write(cr, uid, [invoice.id], cfdi_data)
851+ cfdi_data['cfdi_xml'] = cfdi_xml
852+ else:
853+ msg += _(u"Can't extract the file XML of PAC")
854+ else:
855+ raise orm.except_orm(_('Warning'), _('Stamped Code: %s.-Validation code %s.-Folio Fiscal: %s.-Stamped Message: %s.-Validation Message: %s.') % (
856+ codigo_timbrado, codigo_validacion, folio_fiscal, mensaje, resultados_mensaje))
857+ else:
858+ msg += 'Not found information from web services of PAC, verify that the configuration of PAC is correct'
859+ raise osv.except_osv(_('Warning'), _(
860+ 'Not found information from web services of PAC, verify that the configuration of PAC is correct'))
861+ return {'file': file, 'msg': msg, 'cfdi_xml': cfdi_xml}
862+
863 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
864
865=== modified file 'l10n_mx_facturae_pac_sf/ir_sequence_approval.py'
866--- l10n_mx_facturae_pac_sf/ir_sequence_approval.py 2013-07-31 00:21:50 +0000
867+++ l10n_mx_facturae_pac_sf/ir_sequence_approval.py 2013-08-25 06:44:24 +0000
868@@ -35,7 +35,7 @@
869 types = super(ir_sequence_approval, self)._get_type(
870 cr, uid, ids, context=context)
871 types.extend([
872- ('cfdi32', 'CFDI 3.2 Solución Factible'),
873+ ('cfdi32_pac_sf', 'CFDI 3.2 Solución Factible'),
874 ])
875 return types
876
877
878=== modified file 'l10n_mx_facturae_pac_sf/test/account_invoice_cfdi_pac_sf.yml'
879--- l10n_mx_facturae_pac_sf/test/account_invoice_cfdi_pac_sf.yml 2013-08-25 03:08:26 +0000
880+++ l10n_mx_facturae_pac_sf/test/account_invoice_cfdi_pac_sf.yml 2013-08-25 06:44:24 +0000
881@@ -1,7 +1,7 @@
882 -
883 To test the Mexican Electronic Invoice CFDI PAC SF
884 -
885- I create cfdi_pac_sf a customer invoice
886+ I create a cfdi_pac_sf customer invoice
887 -
888 !record {model: account.invoice, id: account_invoice_cfdi_pac_sf0, view: account.invoice_form}:
889 payment_term: account.account_payment_term_advance
890@@ -11,7 +11,7 @@
891 name: 'Test cfdi_pac_sf Customer Invoice'
892 invoice_line:
893 - product_id: product.product_product_5
894- quantity: 30.0
895+ quantity: 32.0
896 -
897 I rewrite the journal field (BUG I need overwrite two times this field for done! only in test yaml)
898 -
899@@ -47,6 +47,7 @@
900 if cfdi_pac_sf_id:
901 cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id])[0]
902 self.signal_confirm(cr, uid , cfdi_pac_sf_ids ,context=context)
903+<<<<<<< TREE
904 print "cfdi_pac_sf_state",cfdi_pac_sf.state
905 print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
906 state = cfdi_pac_sf.state
907@@ -71,6 +72,34 @@
908 else:
909 state = 'no data in attach file'
910 assert state=='confirmed', 'No confirmed state l10n_mx attachment facturae cfdi_pac_sf'
911+=======
912+ print "cfdi_pac_sf_state",cfdi_pac_sf.state
913+ print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
914+ state = cfdi_pac_sf.state
915+-
916+ I check that the state in l10n_mx attachment facturae cfdi_pac_sf is "Confirmed"
917+-
918+ !python {model: ir.attachment.facturae.mx}: |
919+ import netsvc, tools, os, base64
920+ cfdi_pac_sf_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfdi_pac_sf0") ), ('state', '<>', 'cancel')], limit=1)
921+ cfdi_pac_sf_id = cfdi_pac_sf_ids and cfdi_pac_sf_ids[0] or False
922+ state = 'no attach file'
923+ if cfdi_pac_sf_id:
924+ cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id])[0]
925+ print "cfdi_pac_sf_state",cfdi_pac_sf.state
926+ print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
927+ state = cfdi_pac_sf.state
928+ ir_attach_facturae_mx = cfdi_pac_sf.file_input and cfdi_pac_sf.file_input or False
929+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
930+ if fdata:
931+ if tools.config['test_report_directory']:
932+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_pac_sf' + '_' + \
933+ 'account_invoice_cfdi_pac_sf0' + '_' + 'confirmed' + '-' + ir_attach_facturae_mx.datas_fname)\
934+ , 'wb+').write( base64.decodestring( fdata ) )
935+ else:
936+ state = 'no data in attach file'
937+ assert state=='confirmed', 'No confirmed state l10n_mx attachment facturae cfdi_pac_sf'
938+>>>>>>> MERGE-SOURCE
939 -
940 I sign l10n_mx attachment facturae cfdi_pac_sf by clicking on sign button upload pac
941 -
942@@ -80,10 +109,17 @@
943 cfdi_pac_sf_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfdi_pac_sf0") ), ('state', '<>', 'cancel')], limit=1)
944 cfdi_pac_sf_id = cfdi_pac_sf_ids and cfdi_pac_sf_ids[0] or False
945 if cfdi_pac_sf_id:
946+<<<<<<< TREE
947 cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id])[0]
948 self.signal_sign(cr, uid, cfdi_pac_sf_ids, context=context)
949 print "cfdi_pac_sf_state",cfdi_pac_sf.state
950 print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
951+=======
952+ cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id], context=context)[0]
953+ self.signal_sign(cr, uid, cfdi_pac_sf_ids, context=context)
954+ print "cfdi_pac_sf_state",cfdi_pac_sf.state
955+ print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
956+>>>>>>> MERGE-SOURCE
957 state = cfdi_pac_sf.state
958 -
959 I check that the state in l10n_mx attachment facturae cfdi_pac_sf is "Signed"
960@@ -91,9 +127,15 @@
961 !python {model: ir.attachment.facturae.mx}: |
962 import netsvc, tools, os, base64
963 cfdi_pac_sf_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfdi_pac_sf0") ), ('state', '<>', 'cancel')], limit=1)
964+<<<<<<< TREE
965 cfdi_pac_sf_id = cfdi_pac_sf_ids and cfdi_pac_sf_ids[0] or False
966 state = 'no attach file'
967+=======
968+ cfdi_pac_sf_id = len(cfdi_pac_sf_ids) and cfdi_pac_sf_ids[0] or False
969+ state = 'no attach file'
970+>>>>>>> MERGE-SOURCE
971 if cfdi_pac_sf_id:
972+<<<<<<< TREE
973 cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id])[0]
974 print "cfdi_pac_sf_state",cfdi_pac_sf.state
975 print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
976@@ -104,6 +146,20 @@
977 file(os.path.join(tools.config['test_report_directory'], __name__ + 'account_invoice_cfdi_pac_sf0_signed.xml'), 'wb+').write( fdata )
978 else:
979 state = 'no data in attach file'
980+=======
981+ cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id], context=context)[0]
982+ ir_attach_facturae_mx = cfdi_pac_sf.file_xml_sign and cfdi_pac_sf.file_xml_sign or False
983+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
984+ if fdata:
985+ state = cfdi_pac_sf.state
986+ if tools.config['test_report_directory']:
987+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_pac_sf' + '_' + \
988+ 'account_invoice_cfdi_pac_sf0' + '_' + 'signed' + '-' + ir_attach_facturae_mx.datas_fname),\
989+ 'wb+').write( base64.decodestring( fdata ) )
990+ else:
991+ state = 'no data in attach file'
992+ print "state",state
993+>>>>>>> MERGE-SOURCE
994 assert state=='signed', 'No signed state l10n_mx attachment facturae cfdi_pac_sf'
995 -
996 I generate a printable l10n_mx attachment facturae cfdi_pac_sf by clicking on printable button
997@@ -123,14 +179,30 @@
998 I check that the state in l10n_mx attachment facturae cfdi_pac_sf is Printable
999 -
1000 !python {model: ir.attachment.facturae.mx}: |
1001+ import netsvc, tools, os, base64
1002 cfdi_pac_sf_ids = self.search(cr, uid, [('invoice_id', '=', ref("account_invoice_cfdi_pac_sf0") ), ('state', '<>', 'cancel')], limit=1)
1003 cfdi_pac_sf_id = cfdi_pac_sf_ids and cfdi_pac_sf_ids[0] or False
1004 state = None
1005+ state = 'no attach file'
1006 if cfdi_pac_sf_id:
1007+<<<<<<< TREE
1008 cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id])[0]
1009 state = cfdi_pac_sf.state
1010 print "cfdi_pac_sf_state",cfdi_pac_sf.state
1011 print "cfdi_pac_sf_msj",cfdi_pac_sf.msj
1012+=======
1013+ cfdi_pac_sf = self.browse(cr, uid, [cfdi_pac_sf_id], context=context)[0]
1014+ ir_attach_facturae_mx = cfdi_pac_sf.file_pdf and cfdi_pac_sf.file_pdf or False
1015+ fdata = ir_attach_facturae_mx and ir_attach_facturae_mx.db_datas or False
1016+ if fdata:
1017+ state = cfdi_pac_sf.state
1018+ if tools.config['test_report_directory']:
1019+ open(os.path.join(tools.config['test_report_directory'], 'l10n_mx_facturae_pac_sf' + '_' + \
1020+ 'account_invoice_cfdi_pac_sf0' + '_' + 'printable' + '-' + ir_attach_facturae_mx.datas_fname),\
1021+ 'wb+').write( base64.decodestring( fdata ) )
1022+ else:
1023+ state = 'no data in attach file'
1024+>>>>>>> MERGE-SOURCE
1025 assert state=='printable', 'No printable state l10n_mx attachment facturae cfdi_pac_sf'
1026 -
1027 I added update_posted in journal
1028
1029=== modified file 'l10n_mx_facturae_report/report/invoice_facturae_html.mako'
1030--- l10n_mx_facturae_report/report/invoice_facturae_html.mako 2013-06-30 06:23:55 +0000
1031+++ l10n_mx_facturae_report/report/invoice_facturae_html.mako 2013-08-25 06:44:24 +0000
1032@@ -247,12 +247,12 @@
1033 </table>
1034 <br clear="all"/>
1035 <!--code for cfd-->
1036- %if o.invoice_sequence_id.approval_id.type == 'cfd22':
1037+ %if 'cfdi' in o.invoice_sequence_id.approval_id.type:
1038+ <font class="font">“Este documento es una representacion impresa de un CFDI”
1039+ <br/>CFDI, Comprobante Fiscal Digital por Internet</font>
1040+ %elif 'cfd' in o.invoice_sequence_id.approval_id.type:
1041 ${_('“Este documento es una representacion impresa de un CFD”')}<br/>
1042 ${_('CFD, Comprobante Fiscal Digital')}
1043- %elif o.invoice_sequence_id.approval_id.type == 'cfdi32':
1044- <font class="font">“Este documento es una representacion impresa de un CFDI”
1045- <br/>CFDI, Comprobante Fiscal Digital por Internet</font>
1046 %endif
1047 <!-- bank info-->
1048 %if o.company_emitter_id.partner_id.bank_ids:
1049@@ -284,7 +284,7 @@
1050 <tr><td class="center_td">${ get_text_promissory(o.company_id, o.partner_id, o) or ''|entity }</td></tr>
1051 </table>
1052 <!--code for cfd 3.2-->
1053- %if o.invoice_sequence_id.approval_id.type == 'cfdi32':
1054+ %if 'cfdi' in o.invoice_sequence_id.approval_id.type:
1055 <table class="basic_table" rules="cols" style="border:1.5px solid grey;">
1056 <tr>
1057 <th width="33%"> ${_('Certificado del SAT')}</th>
1058@@ -367,7 +367,7 @@
1059 </div>
1060 %endif
1061 <!--code for cfd32-->
1062- %if o.invoice_sequence_id.approval_id.type == 'cfdi32':
1063+ %if 'cfdi' in o.invoice_sequence_id.approval_id.type:
1064 <div style="page-break-inside:avoid; border:1.5px solid grey;">
1065 <table width="100%" class="datos_fiscales">
1066 <%data_certificate=get_data_certificate(o.id)%>
1067
1068=== modified file 'l10n_mx_ir_attachment_facturae/invoice.py'
1069--- l10n_mx_ir_attachment_facturae/invoice.py 2013-08-22 01:36:32 +0000
1070+++ l10n_mx_ir_attachment_facturae/invoice.py 2013-08-25 06:44:24 +0000
1071@@ -32,65 +32,60 @@
1072 _inherit = 'account.invoice'
1073
1074 def action_cancel(self, cr, uid, ids, context=None):
1075- ir_attach_obj = self.pool.get('ir.attachment.facturae.mx')
1076- id_attach = ir_attach_obj.search(
1077- cr, uid, [('invoice_id', '=', ids[0])], context={})
1078+ ir_attach_facturae_mx_obj = self.pool.get('ir.attachment.facturae.mx')
1079 inv_type_facturae = {
1080 'out_invoice': True,
1081 'out_refund': True,
1082 'in_invoice': False,
1083 'in_refund': False}
1084- if id_attach:
1085- res = super(account_invoice,
1086- self).action_cancel(cr, uid, ids, context)
1087- else:
1088- res = super(account_invoice,
1089- self).action_cancel(cr, uid, ids, context)
1090- for inv in self.browse(cr, uid, ids):
1091+ for inv in self.browse(cr, uid, ids, context=context):
1092 if inv_type_facturae.get(inv.type, False):
1093- for attach in ir_attach_obj.browse(cr, uid, id_attach):
1094+ ir_attach_facturae_mx_ids = ir_attach_facturae_mx_obj.search(
1095+ cr, uid, [('invoice_id', '=', inv.id)], context=context)
1096+ for attach in ir_attach_facturae_mx_obj.browse(cr, uid, ir_attach_facturae_mx_ids, context=context):
1097 if attach.state <> 'cancel':
1098- self.write(cr, uid, ids, {'date_invoice_cancel': time.strftime('%Y-%m-%d %H:%M:%S')})
1099- ir_attach_obj.signal_cancel(cr, uid, [attach.id], context=context)
1100+ ir_attach_facturae_mx_obj.signal_cancel(cr, uid, [attach.id], context=context)
1101+ res = super(account_invoice, self).action_cancel(cr, uid, ids, context=context)
1102+ self.write(cr, uid, ids, {'date_invoice_cancel': time.strftime('%Y-%m-%d %H:%M:%S')})
1103 return res
1104
1105 def create_ir_attachment_facturae(self, cr, uid, ids, context=None):
1106 attach = ''
1107 ir_attach_obj = self.pool.get('ir.attachment.facturae.mx')
1108- invoice = self.browse(cr, uid, ids, context={})[0]
1109+ ir_model_data_obj = self.pool.get('ir.model.data')
1110+ attach_ids = []
1111 inv_type_facturae = {
1112 'out_invoice': True,
1113 'out_refund': True,
1114 'in_invoice': False,
1115 'in_refund': False}
1116- for inv in self.browse(cr, uid, ids):
1117- if inv_type_facturae.get(inv.type, False) and invoice.journal_id.sequence_id.id:
1118- if invoice.invoice_sequence_id and invoice.invoice_sequence_id.approval_id:
1119- attach = ir_attach_obj.create(cr, uid, {
1120- 'name': invoice.fname_invoice, 'invoice_id': ids[0],
1121- 'type': invoice.invoice_sequence_id.approval_id.type},
1122- context={})
1123- ir_model_data = self.pool.get('ir.model.data')
1124- form_res = ir_model_data.get_object_reference(
1125- cr, uid, 'l10n_mx_ir_attachment_facturae',
1126- 'view_ir_attachment_facturae_mx_form')
1127- form_id = form_res and form_res[1] or False
1128-
1129- tree_res = ir_model_data.get_object_reference(
1130- cr, uid, 'l10n_mx_ir_attachment_facturae',
1131- 'view_ir_attachment_facturae_mx_tree')
1132- tree_id = tree_res and tree_res[1] or False
1133-
1134- return {
1135- 'name': _('Attachment Factura E MX'),
1136- 'view_type': 'form',
1137- 'view_mode': 'form,tree',
1138- 'res_model': 'ir.attachment.facturae.mx',
1139- 'res_id': attach,
1140- 'view_id': False,
1141- 'views': [(form_id, 'form'), (tree_id, 'tree')],
1142- 'type': 'ir.actions.act_window',
1143- }
1144- else:
1145- raise orm.except_orm(_('Warning'), _('Folios Invalid Approval'))
1146+ for invoice in self.browse(cr, uid, ids, context=context):
1147+ if inv_type_facturae.get(invoice.type, False):
1148+ approval_id = invoice.invoice_sequence_id and invoice.invoice_sequence_id.approval_id or False
1149+ if approval_id:
1150+ attach_ids.append( ir_attach_obj.create(cr, uid, {
1151+ 'name': invoice.fname_invoice, 'invoice_id': invoice.id,
1152+ 'type': invoice.invoice_sequence_id.approval_id.type},
1153+ context=context)
1154+ )
1155+ form_res = ir_model_data_obj.get_object_reference(
1156+ cr, uid, 'l10n_mx_ir_attachment_facturae',
1157+ 'view_ir_attachment_facturae_mx_form')
1158+ form_id = form_res and form_res[1] or False
1159+
1160+ tree_res = ir_model_data_obj.get_object_reference(
1161+ cr, uid, 'l10n_mx_ir_attachment_facturae',
1162+ 'view_ir_attachment_facturae_mx_tree')
1163+ tree_id = tree_res and tree_res[1] or False
1164+
1165+ return {
1166+ 'name': _('Attachment Factura E MX'),
1167+ 'view_type': 'form',
1168+ 'view_mode': 'form,tree',
1169+ 'res_model': 'ir.attachment.facturae.mx',
1170+ 'res_id': attach_ids[0],
1171+ 'view_id': False,
1172+ 'views': [(form_id, 'form'), (tree_id, 'tree')],
1173+ 'type': 'ir.actions.act_window',
1174+ }
1175 return True
1176
1177=== modified file 'l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py'
1178--- l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py 2013-08-22 01:00:27 +0000
1179+++ l10n_mx_ir_attachment_facturae/ir_attachment_facturae.py 2013-08-25 06:44:24 +0000
1180@@ -38,6 +38,14 @@
1181 def _get_type(self, cr, uid, ids=None, context=None):
1182 types = []
1183 return types
1184+
1185+ def get_driver_fc_sign(self):
1186+ """function to inherit from module driver of pac and add particular function"""
1187+ return {}
1188+
1189+ def get_driver_fc_cancel(self):
1190+ """function to inherit from module driver of pac and add particular function"""
1191+ return {}
1192
1193 _columns = {
1194 'name': fields.char('Name', size=128, required=True, readonly=True,
1195@@ -89,17 +97,17 @@
1196 def create_ir_attachment_facturae(self, cr, uid, ids, context=None):
1197 if context is None:
1198 context = {}
1199- if not self.signal_confirm(cr, uid, ids, context={}):
1200- return False
1201- if not self.signal_sign(cr, uid, ids, context={}):
1202- return False
1203- if not self.signal_printable(cr, uid, ids, context={}):
1204- return False
1205- if not self.signal_send_customer(cr, uid, ids, context={}):
1206- return False
1207- if not self.signal_send_backup(cr, uid, ids, context={}):
1208- return False
1209- if not self.signal_done(cr, uid, ids, context={}):
1210+ if not self.signal_confirm(cr, uid, ids, context=context):
1211+ return False
1212+ if not self.signal_sign(cr, uid, ids, context=context):
1213+ return False
1214+ if not self.signal_printable(cr, uid, ids, context=context):
1215+ return False
1216+ if not self.signal_send_customer(cr, uid, ids, context=context):
1217+ return False
1218+ if not self.signal_send_backup(cr, uid, ids, context=context):
1219+ return False
1220+ if not self.signal_done(cr, uid, ids, context=context):
1221 return False
1222 return True
1223
1224@@ -107,52 +115,65 @@
1225 try:
1226 if context is None:
1227 context = {}
1228+ invoice_obj = self.pool.get('account.invoice')
1229 attach = ''
1230 msj = ''
1231 index_xml = ''
1232- invoice = self.browse(cr, uid, ids)[0].invoice_id
1233- invoice_obj = self.pool.get('account.invoice')
1234- type = self.browse(cr, uid, ids)[0].type
1235+ attach = self.browse(cr, uid, ids[0])
1236+ invoice = attach.invoice_id
1237+ type = attach.type
1238 wf_service = netsvc.LocalService("workflow")
1239- if type == 'cbb':
1240+ save_attach = None
1241+ if 'cbb' in type:
1242 msj = _("Confirmed")
1243- if type == 'cfd22':
1244+ save_attach = False
1245+ elif 'cfdi' in type:
1246+ fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
1247+ '_V3_2.xml' or ''
1248+ fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
1249+ cr, uid, [invoice.id], context=context)
1250+ attach = self.pool.get('ir.attachment').create(cr, uid, {
1251+ 'name': fname_invoice,
1252+ 'datas': base64.encodestring(xml_data),
1253+ 'datas_fname': fname_invoice,
1254+ 'res_model': 'account.invoice',
1255+ 'res_id': invoice.id,
1256+ }, context=context)
1257+ msj = _("Attached Successfully XML CFDI 3.2\n")
1258+ save_attach = True
1259+ elif 'cfd' in type:
1260 fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
1261 '.xml' or ''
1262 fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
1263- cr, uid, [invoice.id], context={})
1264+ cr, uid, [invoice.id], context=context)
1265 attach = self.pool.get('ir.attachment').create(cr, uid, {
1266 'name': fname_invoice,
1267 'datas': base64.encodestring(xml_data),
1268 'datas_fname': fname_invoice,
1269 'res_model': 'account.invoice',
1270 'res_id': invoice.id,
1271- }, context={})
1272+ }, context=context)
1273 if attach:
1274 index_xml = self.pool.get('ir.attachment').browse(cr, uid, attach).index_content
1275 msj = _("Attached Successfully XML CFD 2.2")
1276- if type == 'cfdi32':
1277- fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
1278- '_V3_2.xml' or ''
1279- fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
1280- cr, uid, [invoice.id], context=context)
1281- attach = self.pool.get('ir.attachment').create(cr, uid, {
1282- 'name': fname_invoice,
1283- 'datas': base64.encodestring(xml_data),
1284- 'datas_fname': fname_invoice,
1285- 'res_model': 'account.invoice',
1286- #'res_id': invoice.id,
1287- }, context={})
1288- msj = _("Attached Successfully XML CFDI 3.2\n")
1289- self.write(cr, uid, ids,
1290- {'file_input': attach or False,
1291- 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1292- 'msj': msj,
1293- 'file_xml_sign_index': index_xml }, context=context)
1294+ save_attach = True
1295+ else:
1296+ raise osv.except_osv(_("Type Electronic Invoice Unknow!"), _(
1297+ "The Type Electronic Invoice:"+(type or '')) )
1298+ if save_attach:
1299+ self.write(cr, uid, ids,
1300+ {'file_input': attach or False,
1301+ 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1302+ 'msj': msj,
1303+ 'file_xml_sign_index': index_xml }, context=context)
1304 wf_service.trg_validate(uid, self._name, ids[0], 'action_confirm', cr)
1305 return True
1306 except Exception, e:
1307- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1308+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1309+ import traceback, sys
1310+ traceback.print_stack()
1311+ #traceback_str = repr(traceback.extract_stack())
1312+ #print traceback_str
1313 return False
1314
1315 def action_confirm(self, cr, uid, ids, context=None):
1316@@ -170,40 +191,47 @@
1317 attachment_obj = self.pool.get('ir.attachment')
1318 type = self.browse(cr, uid, ids)[0].type
1319 wf_service = netsvc.LocalService("workflow")
1320- if type == 'cbb':
1321+ if 'cbb' in type:
1322 msj = _("Signed")
1323- if type == 'cfd22':
1324+ if 'cfd' in type and not 'cfdi' in type:
1325 attach = self.browse(cr, uid, ids)[0].file_input.id or False
1326 index_xml = self.browse(cr, uid, ids)[0].file_xml_sign_index or False
1327 msj = _("Attached Successfully XML CFD 2.2\n")
1328- if type == 'cfdi32':
1329- fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
1330- '.xml' or ''
1331- fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
1332- cr, uid, [invoice.id], context=context)
1333- fdata = base64.encodestring(xml_data)
1334- res = invoice_obj._upload_ws_file(
1335- cr, uid, [invoice.id], fdata, context=context)
1336- msj = tools.ustr(res.get('msg', False))
1337- index_xml = res.get('cfdi_xml', False)
1338- data_attach = {
1339- 'name': fname_invoice,
1340- 'datas': base64.encodestring(res.get('cfdi_xml', False)),
1341- 'datas_fname': fname_invoice,
1342- 'description': 'Factura-E XML CFD-I SIGN',
1343- 'res_model': 'account.invoice',
1344- 'res_id': invoice.id,
1345- }
1346- attach = attachment_obj.create(cr, uid, data_attach, context={})
1347+ if 'cfdi' in type:
1348+ #upload file in custom module for pac
1349+ type__fc = self.get_driver_fc_sign()
1350+ if type in type__fc.keys():
1351+ fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
1352+ '.xml' or ''
1353+ fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
1354+ cr, uid, [invoice.id], context=context)
1355+ fdata = base64.encodestring(xml_data)
1356+ res = type__fc[type](
1357+ cr, uid, [ids[0]], fdata, context=context)
1358+ msj = tools.ustr(res.get('msg', False))
1359+ index_xml = res.get('cfdi_xml', False)
1360+ data_attach = {
1361+ 'name': fname_invoice,
1362+ 'datas': base64.encodestring(res.get('cfdi_xml', False)),
1363+ 'datas_fname': fname_invoice,
1364+ 'description': 'Factura-E XML CFD-I SIGN',
1365+ 'res_model': 'account.invoice',
1366+ #'res_id': invoice.id,
1367+ }
1368+ attach = attachment_obj.create(cr, uid, data_attach, context=context)
1369+ else:
1370+ msj += _("Unknow driver for %s"%(type))
1371 self.write(cr, uid, ids,
1372- {'file_xml_sign': attach or False,
1373- 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1374- 'msj': msj,
1375- 'file_xml_sign_index': index_xml}, context=context)
1376+ {'file_xml_sign': attach or False,
1377+ 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1378+ 'msj': msj,
1379+ 'file_xml_sign_index': index_xml}, context=context)
1380 wf_service.trg_validate(uid, self._name, ids[0], 'action_sign', cr)
1381 return True
1382 except Exception, e:
1383- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1384+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1385+ import traceback, sys
1386+ traceback.print_stack()
1387 return False
1388
1389 def action_sign(self, cr, uid, ids, context=None):
1390@@ -239,11 +267,11 @@
1391 'file_pdf': aids or False,
1392 'msj': msj,
1393 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1394- 'file_pdf_index': index_pdf }, context={})
1395+ 'file_pdf_index': index_pdf }, context=context)
1396 wf_service.trg_validate(uid, self._name, ids[0], 'action_printable', cr)
1397 return True
1398 except Exception, e:
1399- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1400+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1401 return False
1402
1403 def action_printable(self, cr, uid, ids, context=None):
1404@@ -347,7 +375,7 @@
1405 wf_service.trg_validate(uid, self._name, ids[0], 'action_send_customer', cr)
1406 return True
1407 except Exception, e:
1408- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1409+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1410 return False
1411
1412 def action_send_customer(self, cr, uid, ids, context=None):
1413@@ -365,7 +393,7 @@
1414 wf_service.trg_validate(uid, self._name, ids[0], 'action_send_backup', cr)
1415 return True
1416 except Exception, e:
1417- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1418+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1419 return False
1420
1421 def action_send_backup(self, cr, uid, ids, context=None):
1422@@ -383,54 +411,49 @@
1423 wf_service.trg_validate(uid, self._name, ids[0], 'action_done', cr)
1424 return True
1425 except Exception, e:
1426- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1427+ self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context=context)
1428 return False
1429
1430 def action_done(self, cr, uid, ids, context=None):
1431 return self.write(cr, uid, ids, {'state': 'done'}, context=context)
1432-
1433+
1434 def signal_cancel(self, cr, uid, ids, context=None):
1435- try:
1436+ invoice_obj = self.pool.get('account.invoice')
1437+ attach_obj = self.pool.get('ir.attachment')
1438+ wf_service = netsvc.LocalService("workflow")
1439+ inv_cancel_status = False
1440+ for ir_attach_facturae_mx_id in self.browse(cr, uid, ids, context=context):
1441 msj = ''
1442- invoice_obj = self.pool.get('account.invoice')
1443- attach_obj = self.pool.get('ir.attachment')
1444- type = self.browse(cr, uid, ids)[0].type
1445- state = self.browse(cr, uid, ids)[0].state
1446- invoice = self.browse(cr, uid, ids)[0].invoice_id
1447- invoice_state = self.browse(cr, uid, ids)[0].invoice_id.state
1448- wf_service = netsvc.LocalService("workflow")
1449- if invoice_state in ['cancel']:
1450- if type == 'cbb':
1451- wf_service.trg_validate(uid, self._name, ids[0], 'action_cancel', cr)
1452- msj = _('Cancel\n')
1453- if type == 'cfd22':
1454- wf_service.trg_validate(uid, self._name, ids[0], 'action_cancel', cr)
1455- msj = _('Cancel\n')
1456- if type == 'cfdi32':
1457- if state in ['cancel', 'draft', 'confirmed']:
1458- wf_service.trg_validate(uid, self._name, ids[0], 'action_cancel', cr)
1459- msj = _('Cancel\n')
1460+ invoice = ir_attach_facturae_mx_id.invoice_id
1461+ if 'cfdi' in ir_attach_facturae_mx_id.type:
1462+ if not ir_attach_facturae_mx_id.state in ['cancel', 'draft', 'confirmed']:
1463+ type__fc = self.get_driver_fc_cancel()
1464+ if ir_attach_facturae_mx_id.type in type__fc.keys():
1465+ cfdi_cancel = res = type__fc[ir_attach_facturae_mx_id.type](
1466+ cr, uid, [ir_attach_facturae_mx_id.id], context=context
1467+ )
1468+ msj += tools.ustr(cfdi_cancel.get('message', False))
1469+ if cfdi_cancel.get('status', True):#TODO, validate cfdi_cancel True or False
1470+ wf_service.trg_validate(uid, self._name, ir_attach_facturae_mx_id.id, 'action_cancel', cr)
1471+ if invoice.state <> 'cancel':
1472+ inv_cancel_status = invoice_obj.action_cancel(cr, uid, [invoice.id], context=context)
1473+ else:
1474+ inv_cancel_status = True
1475 else:
1476- sf_cancel = invoice_obj.sf_cancel(
1477- cr, uid, [invoice.id], context=context)
1478- wf_service.trg_validate(uid, self._name, ids[0], 'action_cancel', cr)
1479- msj += tools.ustr(sf_cancel.get('message', False))
1480- #Para que no aparescan los adjuntos en facturas canceladas
1481- ##adjuntos = attach_obj.search(cr, uid, [(
1482- ##'res_model', '=', 'account.invoice'),
1483- ##('res_id', '=', invoice)])
1484- ##for attachment in self.browse(cr, uid, adjuntos, context):
1485- ##ids2 = attach_obj.write(cr, uid, [attachment.id], {
1486- ##'res_id': False, }, context=context)
1487+ msj += _("Unknow cfdi driver for %s"%(ir_attach_facturae_mx_id.type))
1488 else:
1489- invoice_obj.action_cancel(cr, uid, [invoice.id], context)
1490- self.write(cr, uid, ids,
1491- {'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1492- 'msj': msj})
1493- return True
1494- except Exception, e:
1495- self.write(cr, uid, ids, {'msj': tools.ustr(e)}, context={})
1496- return False
1497+ wf_service.trg_validate(uid, self._name, ir_attach_facturae_mx_id.id, 'action_cancel', cr)
1498+ if invoice.state <> 'cancel':
1499+ inv_cancel_status = invoice_obj.action_cancel(cr, uid, [invoice.id], context=context)
1500+ else:
1501+ inv_cancel_status = True
1502+ msj = 'cancelled'
1503+
1504+ self.write(cr, uid, ids, {
1505+ 'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
1506+ 'msj': msj,
1507+ })
1508+ return inv_cancel_status
1509
1510 def action_cancel(self, cr, uid, ids, context=None):
1511 return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)

Subscribers

People subscribed via source and target branches