Skip to content

Commit

Permalink
[14.0][FIX] assets_management view html report
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed May 31, 2023
1 parent a067baa commit 4b1f23a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
21 changes: 3 additions & 18 deletions assets_management/report/asset_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.misc import format_amount
from odoo.tools.safe_eval import safe_eval


def format_date(rec, field_name, fmt):
Expand Down Expand Up @@ -95,10 +94,8 @@ def print_report(self, report_type=None):
"""
self.ensure_one()
report_type = report_type or "qweb-pdf"
if report_type in ("qweb-pdf", "xlsx"):
if report_type in ("qweb-pdf", "xlsx", "qweb-html"):
res = self.do_print(report_type)
elif report_type == "qweb-html":
res = self.view_report()
elif report_type:
raise ValidationError(
_("No report has been defined for type `{}`.").format(report_type)
Expand All @@ -113,25 +110,13 @@ def do_print(self, report_type):
self.ensure_one()
if report_type == "qweb-pdf":
xml_id = "assets_management.report_asset_journal_pdf"
elif report_type == "qweb-html":
xml_id = "assets_management.report_asset_journal_html"
else:
xml_id = "assets_management.report_asset_journal_xlsx"
report = self.env.ref(xml_id)
return report.report_action(self)

def view_report(self):
"""Launches view for HTML report"""
self.ensure_one()
xmlid = "assets_management.act_client_asset_journal_report"
[act] = self.env.ref(xmlid).read()
ctx = act.get("context", {})
if isinstance(ctx, str):
ctx = safe_eval(ctx)
# Call update twice to force 'active_id(s)' values to be overridden
ctx.update(dict(self._context))
ctx.update(active_id=self.id, active_ids=self.ids)
act["context"] = ctx
return act

@api.model
def get_html(self, given_context=None):
"""Method needed from JavaScript widget to render HTML view"""
Expand Down
21 changes: 3 additions & 18 deletions assets_management/report/asset_previsional.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_is_zero
from odoo.tools.misc import format_amount
from odoo.tools.safe_eval import safe_eval


def format_date(rec, field_name, fmt):
Expand Down Expand Up @@ -100,10 +99,8 @@ def print_report(self, report_type=None):
"""
self.ensure_one()
report_type = report_type or "qweb-pdf"
if report_type in ("qweb-pdf", "xlsx"):
if report_type in ("qweb-pdf", "xlsx", "qweb-html"):
res = self.do_print(report_type)
elif report_type == "qweb-html":
res = self.view_report()
elif report_type:
raise ValidationError(
_("No report has been defined for type `{}`.").format(report_type)
Expand All @@ -118,25 +115,13 @@ def do_print(self, report_type):
self.ensure_one()
if report_type == "qweb-pdf":
xml_id = "assets_management.report_asset_previsional_pdf"
elif report_type == "qweb-html":
xml_id = "assets_management.report_asset_previsional_html"
else:
xml_id = "assets_management.report_asset_previsional_xlsx"
report = self.env.ref(xml_id)
return report.report_action(self)

def view_report(self):
"""Launches view for HTML report"""
self.ensure_one()
xmlid = "assets_management.act_client_asset_previsional_report"
[act] = self.env.ref(xmlid).read()
ctx = act.get("context", {})
if isinstance(ctx, str):
ctx = safe_eval(ctx)
# Call update twice to force 'active_id(s)' values to be overridden
ctx.update(dict(self._context))
ctx.update(active_id=self.id, active_ids=self.ids)
act["context"] = ctx
return act

@api.model
def get_html(self, given_context=None):
"""Method needed from JavaScript widget to render HTML view"""
Expand Down

0 comments on commit 4b1f23a

Please sign in to comment.