Skip to content
Permalink
Browse files

[IMP] web, account : Remove serialized context from report URL

Previously while printing few reports (mostly the ones that are printed
using wizard), some data required for printig the report was aslo being
passed by serializing context and adding it to report url from action manager,
which should not be the case.

This means that all the reports should utilize only provided key-value
data and should NOT use values from context.

This commit improves the behavior by passing required values into data
only and removing context from the report url.

Note: Context was also used to decide the orientation of a report, so from
this commit, we will pass key-value pair in the data dictionary for doing
the same. If 'orientation' key is not specified in data, by default report
will have portrait orientation. For printing a landscpae report, simply pass
'orientation' key with value as 'landscape'.

Task : 21893
Closes : #24918
  • Loading branch information...
dja-odoo authored and mart-e committed May 21, 2018
1 parent 2a63c2e commit 9d6aabe1ef80a0027c6216e0e5cba7ed07b85b7b
@@ -229,12 +229,12 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l

@api.model
def _get_report_values(self, docids, data=None):
if not data.get('form') or not self.env.context.get('active_model') or not self.env.context.get('active_id'):
if not data.get('form'):
raise UserError(_("Form content is missing, this report cannot be printed."))

total = []
model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id'))
model = data['form'].get('active_model')
docs = self.env[model].browse(data['form'].get('id'))

target_move = data['form'].get('target_move', 'all')
date_from = fields.Date.from_string(data['form'].get('date_from')) or fields.Date.today()
@@ -42,7 +42,7 @@ def check_report(self):
data = {}
data['ids'] = self.env.context.get('active_ids', [])
data['model'] = self.env.context.get('active_model', 'ir.ui.menu')
data['form'] = self.read(['date_from', 'date_to', 'journal_ids', 'target_move', 'company_id'])[0]
data['form'] = {'active_model': self._name, **self.read(['date_from', 'date_to', 'journal_ids', 'target_move', 'company_id'])[0]}
used_context = self._build_contexts(data)
data['form']['used_context'] = dict(used_context, lang=self.env.context.get('lang') or 'en_US')
return self.with_context(discard_logo_check=True)._print_report(data)
@@ -14,4 +14,5 @@ class AccountPrintJournal(models.TransientModel):
def _print_report(self, data):
data = self.pre_print_report(data)
data['form'].update({'sort_selection': self.sort_selection})
return self.env.ref('account.action_report_journal').with_context(landscape=True).report_action(self, data=data)
data['orientation'] = 'landscape'
return self.env.ref('account.action_report_journal').report_action(self, data=data)
@@ -95,11 +95,11 @@ def get_total(self, mnths_total):

@api.model
def _get_report_values(self, docids, data=None):
if not data.get('form') or not self.env.context.get('active_model') or not self.env.context.get('active_id'):
if not data.get('form'):
raise UserError(_("Form content is missing, this report cannot be printed."))

model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id'))
model = data['form'].get('active_model')
docs = self.env[model].browse(data['form'].get('id'))
get_periods, months, total_mnths = self.get_periods(data['form'])
get_employee = self.get_employee(data['form'], months, total_mnths)
get_months_tol = self.get_months_tol()
@@ -128,11 +128,11 @@ def get_total(self):

@api.model
def _get_report_values(self, docids, data=None):
if not self.env.context.get('active_model') or not self.env.context.get('active_id'):
if not data.get('form'):
raise UserError(_("Form content is missing, this report cannot be printed."))

model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id'))
model = data['form'].get('active_model')
docs = self.env[model].browse(data['form'].get('id'))
return {
'doc_ids': docids,
'doc_model': model,
@@ -35,5 +35,6 @@ def print_report(self):
data = {'ids': self.env.context.get('active_ids', [])}
res = self.read()
res = res and res[0] or {}
res.update(active_model=self._name)
data.update({'form': res})
return self.env.ref('l10n_in_hr_payroll.action_report_hrsalarybymonth').report_action(self, data=data)
@@ -30,5 +30,6 @@ def print_report(self):
data = {'ids': self.env.context.get('active_ids', [])}
res = self.read()
res = res and res[0] or {}
res.update(active_model=self._name)
data.update({'form': res})
return self.env.ref('l10n_in_hr_payroll.action_report_hryearlysalary').report_action(self, data=data)
@@ -1565,18 +1565,12 @@ def report_routes(self, reportname, docids=None, converter=None, **data):
docids = [int(i) for i in docids.split(',')]
if data.get('options'):
data.update(json.loads(data.pop('options')))
if data.get('context'):
# Ignore 'lang' here, because the context in data is the one from the webclient *but* if
# the user explicitely wants to change the lang, this mechanism overwrites it.
data['context'] = json.loads(data['context'])
if data['context'].get('lang'):
del data['context']['lang']
context.update(data['context'])
landscape = data.get('orientation') == 'landscape'
if converter == 'html':
html = report.with_context(context).render_qweb_html(docids, data=data)[0]
html = report.with_context(landscape=landscape).render_qweb_html(docids, data=data)[0]
return request.make_response(html)
elif converter == 'pdf':
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
pdf = report.with_context(landscape=landscape).render_qweb_pdf(docids, data=data)[0]
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
elif converter == 'text':
@@ -190,7 +190,6 @@ ActionManager.include({
}
} else {
var serializedOptionsPath = '?options=' + encodeURIComponent(JSON.stringify(action.data));
serializedOptionsPath += '&context=' + encodeURIComponent(JSON.stringify(action.context));
reportUrls = _.mapObject(reportUrls, function (value) {
return value += serializedOptionsPath;
});

0 comments on commit 9d6aabe

Please sign in to comment.
You can’t perform that action at this time.