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