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

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!!

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.

1 Like

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

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.

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

@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.

There is an example with the InvoiceReport: modules/account_invoice: 7383144676cd invoice.py

1 Like

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.

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.

1 Like

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

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

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

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.

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

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).

Our developers seem to discuss that issue:
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.