From c51fe5962ce0bce86818c8198341a6e409c5c848 Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Mon, 10 Oct 2022 12:20:10 +0200 Subject: [PATCH] [UPD] present display_name for sample record, increase test coverage --- report_dynamic/models/report_dynamic.py | 6 ++++++ report_dynamic/tests/test_report_dynamic.py | 10 ++++++++++ report_dynamic/views/report_dynamic.xml | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/report_dynamic/models/report_dynamic.py b/report_dynamic/models/report_dynamic.py index 256faa0eed..1c9c46a473 100644 --- a/report_dynamic/models/report_dynamic.py +++ b/report_dynamic/models/report_dynamic.py @@ -76,6 +76,7 @@ class ReportDynamic(models.Model): ) section_count = fields.Integer(string="Sections", compute="_compute_section_count") preview_res_id = fields.Integer(compute="_compute_preview_res_id") + preview_res_id_display_name = fields.Char(compute="_compute_preview_res_id") _sql_constraints = [ ( @@ -275,10 +276,15 @@ def action_wizard_lock_report(self): } def _compute_preview_res_id(self): + "" for tpl in self: domain = safe_eval(tpl.condition_domain_global or "[]") record = self.env[self.model_id.model].search(domain)[:1] tpl.preview_res_id = record.id + if "display_name" in record._fields: + tpl.preview_res_id_display_name = record.display_name + continue + tpl.preview_res_id_display_name = _("Not Available.") def action_preview_content(self): self.ensure_one() diff --git a/report_dynamic/tests/test_report_dynamic.py b/report_dynamic/tests/test_report_dynamic.py index 1e769c9954..f71cb715f8 100644 --- a/report_dynamic/tests/test_report_dynamic.py +++ b/report_dynamic/tests/test_report_dynamic.py @@ -142,3 +142,13 @@ def test_wizards(self): def test_default_wrapper(self): self.rd_template.wrapper_report_id = False self.assertEqual(self.rd_template.get_template_xml_id(), "web.external_layout") + + def test_preview_record(self): + self.rd_template.condition_domain_global = [ + ("name", "=", self.partner_wood_corner.name) + ] + self.assertEqual(self.rd_template.preview_res_id, self.partner_wood_corner.id) + self.assertEqual( + self.rd_template.preview_res_id_display_name, + self.partner_wood_corner.display_name, + ) diff --git a/report_dynamic/views/report_dynamic.xml b/report_dynamic/views/report_dynamic.xml index 28a530e2fa..4c7bce1e30 100644 --- a/report_dynamic/views/report_dynamic.xml +++ b/report_dynamic/views/report_dynamic.xml @@ -166,6 +166,11 @@ attrs="{'invisible': [('is_template', '=', False)]}" help="When you have multiple templates for one model (eg. a contract for senior employees and another for juniors), this domain is used to determine the domain condition that decides for which records to choose this template (eg. [('employee_id.skill_level', '=', 'junior')])" /> +