[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.
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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', []))
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user