[FIX] fixed the report type 'controller', fixed the report_vat_xls route
bzr revid: sle@openerp.com-20140321183649-rg8wrlvcrzvv0d29
This commit is contained in:
parent
8581b1847f
commit
1b6b320445
|
@ -53,23 +53,23 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
'based_on': self._get_basedon(data),
|
||||
'period_from': self.get_start_period(data),
|
||||
'period_to': self.get_end_period(data),
|
||||
'taxlines': self._get_lines(self._get_basedon(data), company_id=data['form']['company_id']),
|
||||
'taxlines': self._get_lines(self._get_basedon(data), company_id=data['form']['company_id'], cr=cr, uid=uid),
|
||||
}
|
||||
return report_obj.render(self.cr, self.uid, [], 'account.report_vat', docargs, context=context)
|
||||
|
||||
def _get_basedon(self, form):
|
||||
return form['form']['based_on']
|
||||
|
||||
def _get_lines(self, based_on, company_id=False, parent=False, level=0, context=None):
|
||||
def _get_lines(self, based_on, company_id=False, parent=False, level=0, context=None, cr=None, uid=None):
|
||||
period_list = self.period_ids
|
||||
res = self._get_codes(based_on, company_id, parent, level, period_list, context=context)
|
||||
res = self._get_codes(based_on, company_id, parent, level, period_list, cr=cr, uid=uid, context=context)
|
||||
if period_list:
|
||||
res = self._add_codes(based_on, res, period_list, context=context)
|
||||
else:
|
||||
self.cr.execute ("select id from account_fiscalyear")
|
||||
fy = self.cr.fetchall()
|
||||
self.cr.execute ("select id from account_period where fiscalyear_id = %s",(fy[0][0],))
|
||||
periods = self.cr.fetchall()
|
||||
cr.execute ("select id from account_fiscalyear")
|
||||
fy = cr.fetchall()
|
||||
cr.execute ("select id from account_period where fiscalyear_id = %s",(fy[0][0],))
|
||||
periods = cr.fetchall()
|
||||
for p in periods:
|
||||
period_list.append(p[0])
|
||||
res = self._add_codes(based_on, res, period_list, context=context)
|
||||
|
@ -89,7 +89,7 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
}
|
||||
|
||||
top_result.append(res_dict)
|
||||
res_general = self._get_general(res[i][1].id, period_list, company_id, based_on, context=context)
|
||||
res_general = self._get_general(res[i][1].id, period_list, company_id, based_on, cr=cr, uid=uid, context=context)
|
||||
ind_general = 0
|
||||
while ind_general < len(res_general):
|
||||
res_general[ind_general]['type'] = 2
|
||||
|
@ -100,14 +100,14 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
i+=1
|
||||
return top_result
|
||||
|
||||
def _get_general(self, tax_code_id, period_list, company_id, based_on, context=None):
|
||||
def _get_general(self, tax_code_id, period_list, company_id, based_on, cr=None, uid=None, context=None):
|
||||
if not self.display_detail:
|
||||
return []
|
||||
res = []
|
||||
obj_account = self.pool.get('account.account')
|
||||
periods_ids = tuple(period_list)
|
||||
if based_on == 'payments':
|
||||
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
|
||||
cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
|
||||
SUM(line.debit) AS debit, \
|
||||
SUM(line.credit) AS credit, \
|
||||
COUNT(*) AS count, \
|
||||
|
@ -131,7 +131,7 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
company_id, periods_ids, 'paid',))
|
||||
|
||||
else:
|
||||
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
|
||||
cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
|
||||
SUM(line.debit) AS debit, \
|
||||
SUM(line.credit) AS credit, \
|
||||
COUNT(*) AS count, \
|
||||
|
@ -148,23 +148,21 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
AND account.active \
|
||||
GROUP BY account.id,account.name,account.code', ('draft', tax_code_id,
|
||||
company_id, periods_ids,))
|
||||
res = self.cr.dictfetchall()
|
||||
res = cr.dictfetchall()
|
||||
|
||||
i = 0
|
||||
while i<len(res):
|
||||
res[i]['account'] = obj_account.browse(self.cr, self.uid, res[i]['account_id'], context=context)
|
||||
res[i]['account'] = obj_account.browse(cr, uid, res[i]['account_id'], context=context)
|
||||
i+=1
|
||||
return res
|
||||
|
||||
def _get_codes(self, based_on, company_id, parent=False, level=0, period_list=None, context=None):
|
||||
def _get_codes(self, based_on, company_id, parent=False, level=0, period_list=None, cr=None, uid=None, context=None):
|
||||
obj_tc = self.pool.get('account.tax.code')
|
||||
ids = obj_tc.search(self.cr, self.uid, [('parent_id','=',parent),('company_id','=',company_id)], order='sequence', context=context)
|
||||
|
||||
ids = obj_tc.search(cr, uid, [('parent_id', '=', parent), ('company_id', '=', company_id)], order='sequence', context=context)
|
||||
res = []
|
||||
for code in obj_tc.browse(self.cr, self.uid, ids, {'based_on': based_on}):
|
||||
for code in obj_tc.browse(cr, uid, ids, {'based_on': based_on}):
|
||||
res.append(('.'*2*level, code))
|
||||
|
||||
res += self._get_codes(based_on, company_id, code.id, level+1, context=context)
|
||||
res += self._get_codes(based_on, company_id, code.id, level+1, cr=cr, uid=uid, context=context)
|
||||
return res
|
||||
|
||||
def _add_codes(self, based_on, account_list=None, period_list=None, context=None):
|
||||
|
@ -186,9 +184,6 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
res.append((account[0], code))
|
||||
return res
|
||||
|
||||
def _get_currency(self, form, context=None):
|
||||
return self.pool.get('res.company').browse(self.cr, self.uid, form['company_id'], context=context).currency_id.name
|
||||
|
||||
def sort_result(self, accounts, context=None):
|
||||
result_accounts = []
|
||||
ind=0
|
||||
|
@ -205,7 +200,8 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
bcl_rup_ind = ind - 1
|
||||
|
||||
while (bcl_current_level >= int(accounts[bcl_rup_ind]['level']) and bcl_rup_ind >= 0 ):
|
||||
res_tot = { 'code': accounts[bcl_rup_ind]['code'],
|
||||
res_tot = {
|
||||
'code': accounts[bcl_rup_ind]['code'],
|
||||
'name': '',
|
||||
'debit': 0,
|
||||
'credit': 0,
|
||||
|
@ -228,25 +224,23 @@ class tax_report(osv.AbstractModel, common_report_header):
|
|||
|
||||
return result_accounts
|
||||
|
||||
|
||||
class tax_report_xls(http.Controller):
|
||||
|
||||
@http.route(['/report/account.report_vat_xls'], type='http', auth='user', website=True, multilang=True)
|
||||
def report_account_tax_xls(self, **data):
|
||||
report_obj = request.registry['report']
|
||||
self.cr, self.uid, self.pool = request.cr, request.uid, request.registry
|
||||
|
||||
data = report_obj.eval_params(data)
|
||||
# Very ugly lines, only for the proof of concept of 'controller' report
|
||||
taxreport_obj = request.registry['report.account.report_vat']
|
||||
from openerp.addons.report.controllers.main import ReportController
|
||||
eval_params = ReportController()._eval_params
|
||||
|
||||
res = {}
|
||||
self.period_ids = []
|
||||
period_obj = self.pool.get('account.period')
|
||||
self.display_detail = data['form']['display_detail']
|
||||
res['periods'] = ''
|
||||
res['fiscalyear'] = data['form'].get('fiscalyear_id', False)
|
||||
cr, uid = request.cr, request.uid
|
||||
data = eval_params(data)
|
||||
data = {'form': data}
|
||||
|
||||
if data['form'].get('period_from', False) and data['form'].get('period_to', False):
|
||||
self.period_ids = period_obj.build_ctx_periods(self.cr, self.uid, data['form']['period_from'], data['form']['period_to'])
|
||||
|
||||
content = ''
|
||||
lines = self._get_lines(self._get_basedon(data), company_id=data['form']['company_id'])
|
||||
taxreport_obj.render_html(cr, uid, [], data=data)
|
||||
lines = taxreport_obj._get_lines(taxreport_obj._get_basedon(data), company_id=data['form']['company_id'], cr=cr, uid=uid)
|
||||
|
||||
if lines:
|
||||
xls = StringIO.StringIO()
|
||||
|
|
|
@ -118,6 +118,14 @@ class ReportController(Controller):
|
|||
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
|
||||
response.set_cookie('fileToken', token)
|
||||
return response
|
||||
elif type =='controller':
|
||||
from werkzeug.test import Client
|
||||
from werkzeug.wrappers import BaseResponse
|
||||
from werkzeug.datastructures import Headers
|
||||
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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ openerp.report = function(instance) {
|
|||
|
||||
// QWeb reports
|
||||
if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
|
||||
|
||||
debugger
|
||||
var report_url = '';
|
||||
switch (action.report_type) {
|
||||
case 'qweb-html':
|
||||
|
@ -48,42 +48,51 @@ openerp.report = function(instance) {
|
|||
});
|
||||
report_url += "?" + $.param(action.datas.form);
|
||||
}
|
||||
if (action.report_type == 'qweb-html' || action.report_type == 'controller') {
|
||||
if (action.report_type == 'qweb-html') {
|
||||
// Open the html report in a popup
|
||||
window.open(report_url, '_blank', 'height=900,width=1280');
|
||||
instance.web.unblockUI();
|
||||
return;
|
||||
} else {
|
||||
// Trigger the download of the pdf report
|
||||
// Trigger the download of the pdf/controller report
|
||||
var c = openerp.webclient.crashmanager;
|
||||
var response = new Array();
|
||||
response[0] = report_url;
|
||||
response[1] = action.report_type;
|
||||
|
||||
(wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
|
||||
// Fallback of qweb-pdf if wkhtmltopdf is not installed
|
||||
if (presence == 'install' && action.report_type == 'qweb-pdf') {
|
||||
self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
|
||||
system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
|
||||
wkhtmltopdf.org</a>'), true);
|
||||
window.open(report_url.substring(12), '_blank', 'height=768,width=1024');
|
||||
instance.web.unblockUI();
|
||||
} else {
|
||||
if (presence == 'upgrade') {
|
||||
self.do_notify(_t('Report'), _t('You should upgrade your version of\
|
||||
Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
|
||||
support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
|
||||
target="_blank">wkhtmltopdf.org</a>'), true);
|
||||
if (action.report_type == 'qweb-pdf') {
|
||||
(wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
|
||||
// Fallback of qweb-pdf if wkhtmltopdf is not installed
|
||||
if (presence == 'install' && action.report_type == 'qweb-pdf') {
|
||||
self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
|
||||
system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
|
||||
wkhtmltopdf.org</a>'), true);
|
||||
window.open(report_url.substring(12), '_blank', 'height=768,width=1024');
|
||||
instance.web.unblockUI();
|
||||
} else {
|
||||
if (presence == 'upgrade') {
|
||||
self.do_notify(_t('Report'), _t('You should upgrade your version of\
|
||||
Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
|
||||
support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
|
||||
target="_blank">wkhtmltopdf.org</a>'), true);
|
||||
}
|
||||
self.session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: openerp.web.unblockUI,
|
||||
error: c.rpc_error.bind(c)
|
||||
});
|
||||
}
|
||||
self.session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: openerp.web.unblockUI,
|
||||
error: c.rpc_error.bind(c)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: openerp.web.unblockUI,
|
||||
error: c.rpc_error.bind(c)
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return self._super(action, options);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue