# How can i modify the "text file name" coming in print option

**URL:** https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046
**Category:** Developer
**Created:** [July 20, 2020, 12:07pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046 "2020-07-20T12:07:01Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)
#### Post date: [July 20, 2020, 12:07pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/1 "2020-07-20T12:07:01Z")

</div>

How can i modify the text file name coming in print option.  
For example in the format \<text\_file\_name\>., where date needs to come up automatically given in the form view.  
One of the example like Test2020-07-13, where Test is the text file name and date is 2020-07-13.

Any help on the above query will be highly grateful!!

---

<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: [July 20, 2020, 2:05pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/2 "2020-07-20T14:05:18Z")

</div>

You can extend `Report.execute` of your custom report and modify the last element of the result (the report name) which will be used by the client to construct the file name.

---

<div class="post-metadata">

### Author: ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)
#### Post date: [July 20, 2020, 2:20pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/3 "2020-07-20T14:20:32Z")

</div>

Is there any module in tryton where it is used to check for the code reference.

---

<div class="post-metadata">

### Author: ![oscarQ](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/oscarq/32/413_2.png) [@oscarQ](https://discuss.tryton.org/u/oscarQ)
#### Post date: [July 21, 2020, 6:54am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/4 "2020-07-21T06:54:19Z")

</div>

I think that there isn’t any example in the code, but you have to do something like this:

```
@classmethod
def execute(cls, ids, data):
    res = super(Report, cls).execute(ids, data)
    # convert the res to a list because it is a tuple and we need to modify it
    aux = list(res)
    aux[-1] = 'new report name'
    return tuple(aux)

```

Anyway, I think that would be better if the file name could be set through the _data_ argument when calling super.

---

<div class="post-metadata">

### Author: ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)
#### Post date: [July 23, 2020, 7:46am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/5 "2020-07-23T07:46:46Z")

</div>

@ced any recommedations for the same??  
I am not getting any clue for the same.

---

<div class="post-metadata">

### Author: ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)
#### Post date: [July 23, 2020, 7:48am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/6 "2020-07-23T07:48:38Z")

</div>

@oscarQ I tried the code but still unable to understand how will it work, I am still seeing the same name of the text file as given in report\_name in xml file.

---

<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: [July 23, 2020, 8:35am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/7 "2020-07-23T08:35:44Z")

</div>

There is an example with the InvoiceReport: [https://hg.tryton.org/modules/account\_invoice/file/7383144676cd/invoice.py#l2572](https://hg.tryton.org/modules/account_invoice/file/7383144676cd/invoice.py#l2572)

---

<div class="post-metadata">

### Author: ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)
#### Post date: [July 23, 2020, 10:00am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/8 "2020-07-23T10:00:18Z")

</div>

On installing the module account invoice this also contains the simple name of the report which is “invoice” `

```
<record model="ir.action.report" id="report_invoice">
        <field name="name">Invoice</field>
        <field name="model">account.invoice</field>
        <field name="report_name">account.invoice</field>
        <field name="report">account_invoice/invoice.fodt</field>
        <field name="single" eval="True"/>
    </record>
    <record model="ir.action.keyword" id="report_invoice_keyword">
        <field name="keyword">form_print</field>
        <field name="model">account.invoice,-1</field>
        <field name="action" ref="report_invoice"/>
    </record>`

```

But I want to change the name of the report. I donot want the report name to be just a simple text like Invoice rather i want it to be a Invoice and invoice.number.  
Ex:- Invoice12345 here Invoice12345 is the name of the report and 12345 should be the invoice.number it should come as the its value given in the form view by the user.

---

<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: [July 23, 2020, 10:18am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/9 "2020-07-23T10:18:29Z")

</div>

> [@prashasti.sharma](#):
>
> Ex:- Invoice12345 here Invoice12345 is the name of the report and 12345 should be the invoice.number it should come as the its value given in the form view by the user.

This is what is implemented by default on the invoice report.  
The linkt to the source code has been already posted on last topic by Cedric.

---

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [December 8, 2020, 11:42am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/10 "2020-12-08T11:42:14Z")

</div>

Sorry, I hardly can understand anything of the above, I’m not that much an expert.

My work would be a little easier if invoices had the structure `<invoice_number>-<party>.odt`. If somebody occasionally can find the time to explain how I can achieve that, I’ll be grateful - and I guess, some more fellows as well.

Cheers,  
Wolf

---

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [December 10, 2020, 1:38am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/11 "2020-12-10T01:38:35Z")

</div>

If I understood, you need to override the Report of Invoice,  
In your module you can try adding:

```
class InvoiceReport(metaclass=PoolMeta):
    __name__ = 'account.invoice'

    @classmethod
    def execute(cls, ids, data):
        pool = Pool()
        Invoice = pool.get('account.invoice')
        with Transaction().set_context(
                language=False,
                address_with_party=True):
            result = super(InvoiceReport, cls).execute(ids, data)
            if len(ids) == 1:
                invoice, = Invoice.browse(ids)
                if invoice.party.rec_name:
                    result = result[:3] + (result[3] + ' - ' + invoice.party.rec_name,)
            return result

```

And your module now depends of account\_invoice

---

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [December 18, 2020, 4:14pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/12 "2020-12-18T16:14:58Z")

</div>

Sorry for the late reply, and thank you for your answer.  
And another sorry: I could not understand your hint. Where is the file which should contain the code above? - I’m using a PIP installation with various virtual environments.

Thanks a lot in advance,  
Wolf

---

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [December 18, 2020, 5:03pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/13 "2020-12-18T17:03:19Z")

</div>

I’m assuming that you already had a custom module like the library rent tutorial. If not, you can search for invoice.py file on trytond under account\_invoice. This is not recommended as it’s part of the base modules, but you can check the snippet there to understand better from where the report name comes.

---

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [January 5, 2021, 6:55pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/14 "2021-01-05T18:55:59Z")

</div>

Sorry again for the again late reply - these hard things tend to be slow with me.  
Actually, I managed to edit `~/[my-environment]/lib/python3.8/site-packages/trytond/modules/account_invoice/invoice.py` as said in #11. Now the file name is “invoice-[customer-name].pdf”. That’s not bad, but in order not to get lost, the invoice number should be in place as well. And I’d love my invoice directory as standard dir - at the moment it points to “~/Documents” (but I guess that’s LibreO settings).

Cheers,  
Wolf

---

<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:32am UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/15 "2021-01-15T09:32:28Z")

</div>

You really want to do that in your own module. if you change the code in site-packages it will be overwritten on the next update of the tryton modules (using pip or whatever).

---

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [January 15, 2021, 1:03pm UTC](https://discuss.tryton.org/t/how-can-i-modify-the-text-file-name-coming-in-print-option/3046/16 "2021-01-15T13:03:39Z")

</div>

Our developers seem to discuss that issue:  
[https://discuss.tryton.org/t/improve-report-name/2528](https://discuss.tryton.org/t/improve-report-name/2528)

So I’ll keep very quiet and wait… My hope to actually do coding in the rest of my lifetime is very limited. And my ambitions are as well.
