# Improve report name

**URL:** https://discuss.tryton.org/t/improve-report-name/2528
**Category:** Ideas
**Created:** [April 2, 2020, 2:36pm UTC](https://discuss.tryton.org/t/improve-report-name/2528 "2020-04-02T14:36:24Z")
**Posts on this page:** 18
**Page:** 2

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 14, 2021, 10:29am UTC](https://discuss.tryton.org/t/improve-report-name/2528/21 "2021-01-14T10:29:23Z")

</div>

> [@ced](#):
>
> For me we can not manage to template the report name because reports are based on list of records so there is no direct variable that can be used.

Maybe we can use the record variable to template and call it for each record on the list.  
If not template is set we may keep the current behaviour (using the rec\_name) of the record.

> [@ced](#):
>
> For the zip name, it is even worst because it must be unique for any record and this can not be checked with a template.

In this case I think we can follow the same patter but add the id at the end. To make it unique.  
Currently the id is added at the start and we get some complaints becausae the order of the filenames is lost when using the zip folder.

Another problem with zip files is that the name can not be customized without altering the rec\_name.

That’s some feedback we received recently from a customer that wanted to get the PDF of multiple invoices in a zip file.

> [@LordVan](#):
>
> I will use something like the execute() code that pokoli posted in April last year – since I need to create my own report class now anyway for other reasons

That’s the current option for now.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 14, 2021, 10:47am UTC](https://discuss.tryton.org/t/improve-report-name/2528/22 "2021-01-14T10:47:13Z")

</div>

> [@pokoli](#):
>
> Maybe we can use the record variable to template and call it for each record on the list.  
> If not template is set we may keep the current behaviour (using the rec\_name) of the record.

Why is record name not good enough? There should be a very strong and large need to introduce a new configuration variable.

> [@pokoli](#):
>
> Currently the id is added at the start and we get some complaints becausae the order of the filenames is lost when using the zip folder.

Maybe. It should be tested with long similar names they do not conflict.

> [@pokoli](#):
>
> Another problem with zip files is that the name can not be customized without altering the rec\_name.

I see no problem with that.

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 14, 2021, 10:50am UTC](https://discuss.tryton.org/t/improve-report-name/2528/23 "2021-01-14T10:50:33Z")

</div>

To be honest .. I am currently contemplating if I can/should just customize rec\_name in our case.. it might be a feasible option for this report at least .. but I am unsure where rec\_name shows up / is used otherwise so I need to check

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [January 14, 2021, 11:26am UTC](https://discuss.tryton.org/t/improve-report-name/2528/24 "2021-01-14T11:26:03Z")

</div>

For me I care the most about the name of the invoices and sale orders, because I’m sending them via email and have now change the name manually. The `rec_name` is already a very good improvement so keep that.  
As an extra I can imagine an extra field (‘customize report name’) on the report record. This field is only active when ‘Single’ is checked, so there is just one record on the report. The field behaves exactly the same as the ‘subject’ field of the (new) email template (I love it!), so you can add for example `Invoice ${record.number}`. The name of the report becomes then ‘Invoice 202134929’ or whatever number the invoice has.  
Together with the new email templates and sending email from Tryton that will be a nice addition.

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 14, 2021, 12:17pm UTC](https://discuss.tryton.org/t/improve-report-name/2528/25 "2021-01-14T12:17:00Z")

</div>

I agree that rec\_name is a quite good default, but .. here is my biggest issue with that:  
I have more than one report from the sale module .. one for pre-production (internal) documentation and then I will also have another one for the actual sale later (unless I use invoice directly there ..)  
so being able to configure that on the Report record would be definitely a great option as I might not want every report for each type to have the same name.  
Though I have no idea how common it is across the user base, that there are different reports available, that should ideally have different names.  
like I want my project documentation to have the name different from the actual Sale docs / invoice (i know invoice is account.invoice of course so that is seperate)

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [January 14, 2021, 12:51pm UTC](https://discuss.tryton.org/t/improve-report-name/2528/26 "2021-01-14T12:51:21Z")

</div>

To stay with the invoice example, you can even add the state of the invoice to the report name. So you have a clear distinction.

I have also multiple reports for invoice or sale. Because when I’m sending the report by email I want to have it as PDF and with my company letterhead as background. For printing I don’t want to have a letterhead.

> [@LordVan](#):
>
> I have more than one report from the sale module … one for pre-production (internal) documentation and then I will also have another one for the actual sale later (unless I use invoice directly there …)  
> so being able to configure that on the Report record would be definitely a great option as I might not want every report for each type to have the same name.

As I look into the patch [https://codereview.tryton.org/306161002/patch/300481002/306461003](https://codereview.tryton.org/306161002/patch/300481002/306461003) It seems to me that the report name will be still the field `name` from the report template but also including the `rec_name` from the first 5 records.  
So to sum it with an example:

`name` field on the report template is ‘Default Invoice’  
`rec_name` of the record is ‘INV392890 [OR342432]’  
You report name will be `Default Invoice-INV392890 [OR342432]`

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 15, 2021, 6:18am UTC](https://discuss.tryton.org/t/improve-report-name/2528/27 "2021-01-15T06:18:31Z")

</div>

I think what I will do is, is implement this on my custom class and see if it works or crashes 😉 – If it works I’ll post a link to it here for either further discussion or future reference for people with similar requirements 😉

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 15, 2021, 7:28am UTC](https://discuss.tryton.org/t/improve-report-name/2528/28 "2021-01-15T07:28:49Z")

</div>

> [@ced](#):
>
> Why is record name not good enough? There should be a very strong and large need to introduce a new configuration variable

Our requirement was that the customer wants to include the customer name in the exported filename but did not want to customize the record\_name (because he does not know how to code). Exactly the same as it was [asked here](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/10)

As we allow to create reports without coding, it makes sense to also set the filename without coding.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 15, 2021, 8:56am UTC](https://discuss.tryton.org/t/improve-report-name/2528/29 "2021-01-15T08:56:41Z")

</div>

> [@pokoli](#):
>
> the customer wants to include the customer name in the exported filename

It is not because someone wants something that it is a good idea (even if multiple wants).

Here I suspect that it is because they want to use a filestorage as a database which is pointless because they must search inside Tryton.

> [@pokoli](#):
>
> As we allow to create reports without coding, it makes sense to also set the filename without coding.

Why not, then it is only the `record.rec_name` that may be replaced by a template string but not other parts of the logic.

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 15, 2021, 9:02am UTC](https://discuss.tryton.org/t/improve-report-name/2528/30 "2021-01-15T09:02:55Z")

</div>

> [@ced](#):
>
> > [@pokoli](#):
> >
> > As we allow to create reports without coding, it makes sense to also set the filename without coding.
> 
> Why not, then it is only the `record.rec_name` that may be replaced by a template string but not other parts of the logic.

Actually I like the idea of being able to somehow (in the UI) be able to customize rec\_name without additional coding. - I did not check the code now if that is already possible somewhere (in other modules) .. though it would not solve my “issue” that I want different filenames for different reports on the same module / record

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 15, 2021, 9:20am UTC](https://discuss.tryton.org/t/improve-report-name/2528/31 "2021-01-15T09:20:18Z")

</div>

> [@ced](#):
>
> Here I suspect that it is because they want to use a filestorage as a database which is pointless because they must search inside Tryton.

They want to include the customer name because they export the invoices for the accountant but they do not want the accountant to access Tryton.

> [@ced](#):
>
> Why not, then it is only the `record.rec_name` that may be replaced by a template string but not other parts of the logic.

No, the idea is to allow to define a template by using the following variables:

- {report\_name}
- {record} (to access any attribute of the record)

> [@LordVan](#):
>
> though it would not solve my “issue” that I want different filenames for different reports on the same module / record

Indeed my idea is to already solve your issue by allowing to customize directly the report filename without modifying the rec\_name

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 15, 2021, 9:23am UTC](https://discuss.tryton.org/t/improve-report-name/2528/32 "2021-01-15T09:23:40Z")

</div>

> [@pokoli](#):
>
> No, the idea is to allow to define a template by using the following variables

This is not an acceptable solution because of my previous objections.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 15, 2021, 9:28am UTC](https://discuss.tryton.org/t/improve-report-name/2528/33 "2021-01-15T09:28:14Z")

</div>

> [@ced](#):
>
> because of my previous objections.

So you mean we should not allow to replace the {report\_name} but allot to configure the other part of the name (currently the rec\_name) with any attribute of the record?

If yes, that sounds like a good improvement for me.

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 15, 2021, 9:34am UTC](https://discuss.tryton.org/t/improve-report-name/2528/34 "2021-01-15T09:34:21Z")

</div>

Yeah could put an option to configure it in the sale settings to be able to add your own template to use in get\_rec\_name ..

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 15, 2021, 10:24am UTC](https://discuss.tryton.org/t/improve-report-name/2528/35 "2021-01-15T10:24:12Z")

</div>

> [@ced](#):
>
> Why not, then it is only the `record.rec_name` that may be replaced by a template string but not other parts of the logic.

What template format do you think would be most suitable here?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 15, 2021, 10:28am UTC](https://discuss.tryton.org/t/improve-report-name/2528/36 "2021-01-15T10:28:24Z")

</div>

> [@LordVan](#):
>
> What template format do you think would be most suitable here?

We should keep using Genshi as in `ir.email` and `notification.email`.

---

<div class="post-metadata">

### Author: ![LordVan](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/lordvan/32/1269_2.png) [@LordVan](https://discuss.tryton.org/u/LordVan)
#### Post date: [January 15, 2021, 10:44am UTC](https://discuss.tryton.org/t/improve-report-name/2528/37 "2021-01-15T10:44:13Z")

</div>

Ah yes .. I see how it is done there. I agree this is definitely a good way to do it.

so it’d be something like this in the end maybe?

```
@staticmethod
def default_rec_name():
    Config = Pool().get('sale.configuration')
    config = Config(1)
    return config.rec_name_template # or whatever it would be called

def get_rec_name(self, name):
    rec_name_template = default_rec_name()
    if rec_name_template:
        return TextTemplate(rec_name_template)
                           .generate(record=self)
                           .render()
    else:
        items = []
        if self.full_number:
            items.append(self.full_number)
        if self.reference:
            items.append('[%s]' % self.reference)
        if not items:
            items.append('(%s)' % self.id)
        return ' '.join(items)

```

I just kept the current implementation if no name is set as a fallback

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 15, 2021, 1:24pm UTC](https://discuss.tryton.org/t/improve-report-name/2528/38 "2021-01-15T13:24:45Z")

</div>

I think it’s easier to add a new attribute on `ir.action.report` to be rendered as the filename.

Something similar to what [we did for subject of notifications](https://hg.tryton.org/modules/notification_email/rev/4786abb9094b) but for report filenames.

[Previous page](https://discuss.tryton.org/t/improve-report-name/2528.md?page=1)
