1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
34
from mx.DateTime import *
36
from lxml import etree
41
invoices_form = '''<?xml version="1.0"?>
42
<form string="Select the invoices to ReGenerate" width="800" height="250" >
43
<field name="invoice_ids" domain = "[('state','in',('open','paid')), ('type', 'in', ('out_invoice','out_refund'))]" width="800" height="250" />
44
<field name="keep_date" />
49
'invoice_ids': {'string': 'Invoices', 'type': 'many2many', 'relation': 'account.invoice',},
50
'keep_date': {'string': 'Keep same Date?', 'type': 'boolean', }
53
done_form = '''<?xml version="1.0"?>
54
<form string="Regeneration Done!!!">
55
<separator string="Regeneration Done!!!"/>
63
class wizard_redo_einvoice(wizard.interface):
66
def _get_new_xml(self, cr, uid, data, context):
67
pool = pooler.get_pool(cr.dbname)
68
invoice_obj = pool.get('account.invoice')
69
attach_obj = pool.get('ir.attachment')
71
for inv_id in data['ids']:
72
if not data['form']['keep_date']:
75
date = invoice_obj.browse(cr, uid, inv_id).sign_date
76
date = date.split(' ')
77
same_date = date[0] + 'T' + date[1]
78
context['date'] = same_date
79
cfe= invoice_obj.create_xml(cr, uid, [inv_id], context)
80
cfe_str = etree.tostring(cfe, pretty_print=True, encoding='utf-8')
81
attachment_ids = attach_obj.search(cr, uid, [('res_id','=',inv_id),('res_model','=', 'account.invoice')])
82
attach_brw_ids = attach_obj.browse(cr, uid, attachment_ids)
83
for attach_brw in attach_brw_ids:
84
attach_name = attach_brw.name
85
attach_name = attach_name + '.old'
86
query = "UPDATE ir_attachment set name='%s' where id=%s"%(attach_name, attach_brw.id)
87
cr.execute("UPDATE ir_attachment set name='%s' where id=%s"%(attach_name, attach_brw.id))
88
invoice_obj.attach_xml(cr, uid, inv_id, cfe_str)
91
def _get_defaults(self, cr, uid, data, context):
92
data['form'] = {'invoice_ids': data['ids']}
95
def _get_all_md5(self, cr, uid, data, context):
96
pool = pooler.get_pool(cr.dbname)
97
cr.execute("SELECT id from account_invoice where sign_date between '2010-01-01 00:00:00' and '2011-03-01 00:00:00'")
98
all_ids = cr.fetchall()
99
all_ids = [a[0] for a in all_ids]
101
for inv_brw in pool.get('account.invoice').browse(cr, uid, all_ids):
102
cadena = inv_brw.cadena
103
sello = inv_brw.digital_signature
104
certfname = os.path.join(tools.config['root_path'], 'filestore/%s/%s'%(cr.dbname, inv_brw.company_id.certificate.store_fname))
105
verify = pool.get('account.invoice').cfdutil_verifySello(cadena, certfname, sello)
107
ids.append(inv_brw.id)
108
data['form'] = {'invoice_ids': ids}
114
'actions': [_get_defaults],
115
'result': {'type':'form',
116
'arch':invoices_form,
117
'fields':invoices_fields,
118
'state':[('end','Cancel'),('md5','MD5 to SHA1'),('export','Export')]}
121
'actions' : [_get_new_xml],
122
'result' : {'type' : 'form',
124
'fields' : done_fields,
125
'state' : [('close', 'Ok','gtk-ok') ]}
128
'actions': [_get_all_md5],
129
'result': {'type':'form',
130
'arch':invoices_form,
131
'fields':invoices_fields,
132
'state':[('end','Cancel'),('md5','MD5 to SHA1'),('export','Export')]}
136
'result': {'type': 'state', 'state':'end'}
140
wizard_redo_einvoice('account.invoice.redo.einvoice')