# Renders Parent Model Field in Report

**URL:** https://discuss.tryton.org/t/renders-parent-model-field-in-report/8524
**Category:** Developer
**Created:** [April 25, 2025, 3:53am UTC](https://discuss.tryton.org/t/renders-parent-model-field-in-report/8524 "2025-04-25T03:53:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bromoapp](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bromoapp](https://discuss.tryton.org/u/bromoapp)
#### Post date: [April 25, 2025, 3:53am UTC](https://discuss.tryton.org/t/renders-parent-model-field-in-report/8524/1 "2025-04-25T03:53:55Z")

</div>

I create a report using 2 parent-child models:

- **UserTimesheet**
- **UserTimesheetRecord**

**UserTimesheetRecord** has a field **Many2One** to a model called **Project**

In database **UserTimesheetRecord** table is like below, in which the column **‘project’** holds the ID of a project record in project table:  
 ![tsheet-record-db](https://discuss-cdn.tryton.org/uploads/default/optimized/2X/c/c307db195c5544dc3d9f011492199711a25f6e8c_2_690x55.jpeg)

And below is Project data in DB:

 ![proj_table](https://discuss-cdn.tryton.org/uploads/default/original/2X/4/4621af4617540b3509e4553683ebfc615be0d3a0.jpeg)

based on opportunity [tutorial](https://docs.tryton.org/latest/server/tutorial/module/report.html), to renders party module field value, all you need to do is calling it from field placeholder at FODT file like this: **opportunity.party.rec\_name**.

So at FODT or FODS template, I try to renders Project’s name (should be derives from Project table, with field placeholder: **record.project.proj\_name** (at FODT) or **relatorio://record.project.proj\_name** (at FODS).

But both throws error says:

```auto
  File "/genshi/template/eval.py", line 397, in undefined
    raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: None has no member named "proj_name"

```

I am not stopping there. So I read in the API Ref Doc that you can load a desired module into the context at Report class, and I tried, but it seems cannot works. My code is below.

```auto
class UserTimesheetReport(Report):
    "User Timesheet Report"
    __name__ = 'user.timesheet.report'
    
    @classmethod
    def get_context(cls, records, header, data):
        logger.warning(">>>>>>>> PROCESSING GET CONTEXT <<<<<<<")
        pool = Pool()
        Project = pool.get('afx.project')

        context = super().get_context(records, header, data)
        project_id = Transaction().context.get('project')
        project = Project(project_id) if project_id else None
        context['project'] = project
        return context

```

I click PRINT button, and I was hoping I can see the LOG Message in the console, but that also not happened (I already have a custom logging config file and executed when I start trytond).

My questions:

1. Is there any link sample to do this that explains the proper way to use get\_context method or any other workable solution that enable me to render the correct project name?
2. Is there anyway I can print my logging message to console from overridden method?

Any advice would be very helpful to me

Regards  
Bromo

---

<div class="post-metadata">

### Author: ![udono](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/udono/32/2114_2.png) [@udono](https://discuss.tryton.org/u/udono)
#### Post date: [May 9, 2025, 10:09pm UTC](https://discuss.tryton.org/t/renders-parent-model-field-in-report/8524/2 "2025-05-09T22:09:08Z")

</div>

> [@bromoapp](#):
>
> But both throws error says:
> 
> ```auto
> File "/genshi/template/eval.py", line 397, in undefined
> raise UndefinedError(key, owner=owner)
> genshi.template.eval.UndefinedError: None has no member named "proj_name"
> 
> ```

You are close to the solution. The error just stats, that you have a `record in records` which has no `project`. No `project` means it is empty which is `None`. So you try to derive `project_name` from ` `None`(like`None.proj\_name`), which is not possible.  
There are two solutions:

1. Make the `project` field required on `UserTimesheetRecord` that it has always a value
2. Catch the None project in the placeholder like this

```auto
<record.project.proj_name if record.project else ''> or

<getattr(record.project, 'proj_name', '')> or

<if test="record.project">
    <record.project.proj_name'>
</if>

```

WDYT?

---

<div class="post-metadata">

### Author: ![bromoapp](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bromoapp](https://discuss.tryton.org/u/bromoapp)
#### Post date: [May 10, 2025, 12:46pm UTC](https://discuss.tryton.org/t/renders-parent-model-field-in-report/8524/3 "2025-05-10T12:46:51Z")

</div>

I fixed this already.. I use cursor IDE and the AI shows me how to utilize **get\_context** combined with **execute** methods.. thanks anyway @udono

regards  
Bromo
