diff options
| author | Adrien Dieudonne <adr@odoo.com> | 2017-06-14 15:07:46 +0200 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2017-07-20 14:21:57 +0200 |
| commit | 7a1d2d1c4caebba5bd69d63cff3d7824dfd5a7a6 (patch) | |
| tree | de3c763c30a3908d2510d911259c44cc30ec6712 | |
| parent | 11270336fa7dd225bf03fc664d80b1604d4cbc4b (diff) | |
[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.
backported in v10 for opw-753036
10 files changed, 40 insertions, 0 deletions
diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py index 88e4730c59c..b9bef25dfeb 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 not self.env.context.get('active_model') or not self.env.context.get('active_id'): + 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 5bdf40ae7b1..fccc60e7680 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): @@ -59,6 +60,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..4aacdf68108 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 not self.env.context.get('active_model') or not self.env.context.get('active_id'): + 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..1cc67073146 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 not self.env.context.get('active_model') or not self.env.context.get('active_id'): + 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..bb6e2c75423 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 not self.env.context.get('active_model') or not self.env.context.get('active_id'): + 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 = { |
