From 0d2fb541e877d093564c3fd0140ce372c50fde88 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Wed, 14 Jun 2017 15:07:46 +0200 Subject: [PATCH] [FIX] *: reports: check required values for 'render_html' Some reports require additional information to render. When accessed in Odoo, the user has to fill a wizard to provide those information. However, when these reports were opened in Studio, it crashed as those information were missing (we don't pass through the configuration wizard in this case). This fix checks if all the required information are given before trying to render those reports, and it displays a warning in the logs in they are missing, which is better than a traceback. --- addons/account/report/account_aged_partner_balance.py | 4 ++++ addons/account/report/account_balance.py | 4 ++++ addons/account/report/account_general_ledger.py | 4 ++++ addons/account/report/account_journal.py | 4 ++++ addons/account/report/account_partner_ledger.py | 4 ++++ addons/account/report/account_report_financial.py | 4 ++++ addons/hr_holidays/report/holidays_summary_report.py | 4 ++++ addons/hr_payroll/report/report_contribution_register.py | 4 ++++ .../report/report_hr_salary_employee_bymonth.py | 4 ++++ .../report/report_hr_yearly_salary_detail.py | 4 ++++ addons/report/models/report.py | 5 ++++- 11 files changed, 44 insertions(+), 1 deletion(-) diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py index 88e4730c59c..0c303514843 100644 --- a/addons/account/report/account_aged_partner_balance.py +++ b/addons/account/report/account_aged_partner_balance.py @@ -2,6 +2,7 @@ import time from odoo import api, models, _ +from odoo.exceptions import UserError from odoo.tools import float_is_zero from datetime import datetime from dateutil.relativedelta import relativedelta @@ -196,6 +197,9 @@ class ReportAgedPartnerBalance(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form') or ('active_model', 'active_id') not in self.env.context.keys(): + raise UserError(_("Some data are 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')) diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 81f5c30dedc..f2c3f896308 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -2,6 +2,7 @@ import time from odoo import api, models +from odoo.exceptions import UserError class ReportTrialBalance(models.AbstractModel): @@ -57,6 +58,9 @@ class ReportTrialBalance(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form') or not self.env.context.get('active_model'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + self.model = self.env.context.get('active_model') docs = self.env[self.model].browse(self.env.context.get('active_ids', [])) display_account = data['form'].get('display_account') diff --git a/addons/account/report/account_general_ledger.py b/addons/account/report/account_general_ledger.py index d3b871f24b8..f7ebf8ad451 100644 --- a/addons/account/report/account_general_ledger.py +++ b/addons/account/report/account_general_ledger.py @@ -2,6 +2,7 @@ import time from odoo import api, models +from odoo.exceptions import UserError class ReportGeneralLedger(models.AbstractModel): @@ -109,6 +110,9 @@ class ReportGeneralLedger(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form') or not self.env.context.get('active_model'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + self.model = self.env.context.get('active_model') docs = self.env[self.model].browse(self.env.context.get('active_ids', [])) diff --git a/addons/account/report/account_journal.py b/addons/account/report/account_journal.py index d134891eb75..9dfa7807f48 100644 --- a/addons/account/report/account_journal.py +++ b/addons/account/report/account_journal.py @@ -2,6 +2,7 @@ import time from odoo import api, models +from odoo.exceptions import UserError class ReportJournal(models.AbstractModel): @@ -95,6 +96,9 @@ class ReportJournal(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + target_move = data['form'].get('target_move', 'all') sort_selection = data['form'].get('sort_selection', 'date') diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index ba2503d41a9..94d12a7bd3a 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -3,6 +3,7 @@ from datetime import datetime import time from odoo import api, models +from odoo.exceptions import UserError from odoo.tools import DEFAULT_SERVER_DATE_FORMAT @@ -69,6 +70,9 @@ class ReportPartnerLedger(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + data['computed'] = {} obj_partner = self.env['res.partner'] diff --git a/addons/account/report/account_report_financial.py b/addons/account/report/account_report_financial.py index abb50715ac5..bd072ed300e 100644 --- a/addons/account/report/account_report_financial.py +++ b/addons/account/report/account_report_financial.py @@ -2,6 +2,7 @@ import time from odoo import api, models +from odoo.exceptions import UserError class ReportFinancial(models.AbstractModel): @@ -144,6 +145,9 @@ class ReportFinancial(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form') or ('active_model', 'active_id') not in self.env.context.keys(): + raise UserError(_("Some data are missing, this report cannot be printed.")) + self.model = self.env.context.get('active_model') docs = self.env[self.model].browse(self.env.context.get('active_id')) report_lines = self.get_account_lines(data.get('form')) diff --git a/addons/hr_holidays/report/holidays_summary_report.py b/addons/hr_holidays/report/holidays_summary_report.py index 7d58e6bfbca..1428562ed62 100644 --- a/addons/hr_holidays/report/holidays_summary_report.py +++ b/addons/hr_holidays/report/holidays_summary_report.py @@ -4,6 +4,7 @@ from datetime import timedelta from dateutil.relativedelta import relativedelta from odoo import api, fields, models +from odoo.exceptions import UserError class HrHolidaySummaryReport(models.AbstractModel): @@ -102,6 +103,9 @@ class HrHolidaySummaryReport(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + Report = self.env['report'] holidays_report = Report._get_report_from_name('hr_holidays.report_holidayssummary') holidays = self.env['hr.holidays'].browse(self.ids) diff --git a/addons/hr_payroll/report/report_contribution_register.py b/addons/hr_payroll/report/report_contribution_register.py index ebfc969c1fd..c56918c88be 100644 --- a/addons/hr_payroll/report/report_contribution_register.py +++ b/addons/hr_payroll/report/report_contribution_register.py @@ -6,6 +6,7 @@ from datetime import datetime from dateutil.relativedelta import relativedelta from odoo import api, fields, models +from odoo.exceptions import UserError class ContributionRegisterReport(models.AbstractModel): @@ -29,6 +30,9 @@ class ContributionRegisterReport(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form'): + raise UserError(_("Some data are missing, this report cannot be printed.")) + register_ids = self.env.context.get('active_ids', []) contrib_registers = self.env['hr.contribution.register'].browse(register_ids) date_from = data['form'].get('date_from', fields.Date.today()) diff --git a/addons/l10n_in_hr_payroll/report/report_hr_salary_employee_bymonth.py b/addons/l10n_in_hr_payroll/report/report_hr_salary_employee_bymonth.py index 3ff69127d5c..a4f649eb53a 100644 --- a/addons/l10n_in_hr_payroll/report/report_hr_salary_employee_bymonth.py +++ b/addons/l10n_in_hr_payroll/report/report_hr_salary_employee_bymonth.py @@ -4,6 +4,7 @@ from datetime import date from odoo import api, models +from odoo.exceptions import UserError class ReportHrSalaryEmployeeBymonth(models.AbstractModel): @@ -93,6 +94,9 @@ class ReportHrSalaryEmployeeBymonth(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if not data.get('form') or ('active_model', 'active_id') not in self.env.context.keys(): + raise UserError(_("Some data are missing, this report cannot be printed.")) + model = self.env.context.get('active_model') docs = self.env[model].browse(self.env.context.get('active_id')) get_periods, months, total_mnths = self.get_periods(data['form']) diff --git a/addons/l10n_in_hr_payroll/report/report_hr_yearly_salary_detail.py b/addons/l10n_in_hr_payroll/report/report_hr_yearly_salary_detail.py index 57a74787f5d..751dbbb54fd 100644 --- a/addons/l10n_in_hr_payroll/report/report_hr_yearly_salary_detail.py +++ b/addons/l10n_in_hr_payroll/report/report_hr_yearly_salary_detail.py @@ -4,6 +4,7 @@ from datetime import date from odoo import api, models +from odoo.exceptions import UserError class EmployeesYearlySalaryReport(models.AbstractModel): @@ -127,6 +128,9 @@ class EmployeesYearlySalaryReport(models.AbstractModel): @api.model def render_html(self, docids, data=None): + if ('active_model', 'active_id') not in self.env.context.keys(): + raise UserError(_("Some data are missing, this report cannot be printed.")) + model = self.env.context.get('active_model') docs = self.env[model].browse(self.env.context.get('active_id')) docargs = { diff --git a/addons/report/models/report.py b/addons/report/models/report.py index c576ced2e5d..0aa50a817df 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -132,7 +132,10 @@ class Report(models.Model): report_model = self.env.get(report_model_name) if report_model is not None: - return report_model.render_html(docids, data=data) + try: + return report_model.render_html(docids, data=data) + except UserError as e: + _logger.warning("%s: %s", report_name, e.name) else: report = self._get_report_from_name(report_name) docs = self.env[report.model].browse(docids)