Skip to content

Commit

Permalink
[UPD] present display_name for sample record, increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsirintanis committed Oct 10, 2022
1 parent 25722ae commit c51fe59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions report_dynamic/models/report_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
(
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions report_dynamic/tests/test_report_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
5 changes: 5 additions & 0 deletions report_dynamic/views/report_dynamic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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')])"
/>
<field
name="preview_res_id_display_name"
attrs="{'invisible': [('is_template', '=', False)]}"
string="Sample record display name"
/>
</group>
</group>
<notebook>
Expand Down

0 comments on commit c51fe59

Please sign in to comment.