the error :
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo9/custom-addons/alwen_targa/controllers/main.py", line 70, in report_download
filename = self.get_name_pdf(nom_complet,filename)
File "/opt/odoo9/custom-addons/alwen_targa/controllers/main.py", line 21, in get_name_pdf
num=nom_complet.split('/')[1]
IndexError: list index out of range
******************
source :
class Extension_ReportController(openerp.addons.report.controllers.main.ReportController):
def get_name_pdf(self,nom_complet,filename):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
res=filename
type=nom_complet.split('.')[0]
num=nom_complet.split('/')[1]
if type == 'sale':
sale_obj = pool['sale.order']
sale = sale_obj.browse(cr, uid, int(num), context=context)
if sale.state not in ['sale','done']:
res='Devis '+num+' '+sale.partner_id.name+'.pdf'
else :
res='Bons de commande '+num+' '+sale.partner_id.name+'.pdf'
if type == 'account':
account_obj = pool['account.invoice']
account = account_obj.browse(cr, uid, int(num), context=context)
if account.state not in ['draft','proforma','proforma2']:
res='Facture '+account.number.split('/')[2]+' '+account.partner_id.name+'.pdf'
elif str(account.state) in ['proforma','proforma2']:
res='Facture pro-forma.pdf'
else :
res='Facture en brouillon.pdf'
return res
@route(['/report/download'], type='http', auth="user")
def report_download(self, data, token):
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
a pdf/controller report.
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = json.loads(data)
url, type = requestcontent[0], requestcontent[1]
try:
if type == 'qweb-pdf':
reportname = url.split('/report/pdf/')[1].split('?')[0]
nom_complet=reportname
docids = None
if '/' in reportname:
reportname, docids = reportname.split('/')
if docids:
# Generic report:
response = self.report_routes(reportname, docids=docids, converter='pdf')
else:
# Particular report:
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
response = self.report_routes(reportname, converter='pdf', **dict(data))
cr, uid = request.cr, request.uid
report = request.registry['report']._get_report_from_name(cr, uid, reportname)
filename = "%s.%s" % (report.name, "pdf")
filename = self.get_name_pdf(nom_complet,filename)
response.headers.add('Content-Disposition', content_disposition(filename))
response.set_cookie('fileToken', token)
return response
elif type =='controller':
reqheaders = Headers(request.httprequest.headers)
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
response.set_cookie('fileToken', token)
return response
else:
return
except Exception, e:
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return request.make_response(html_escape(json.dumps(error)))