Improve report name

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.

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.

That’s the current option for now.

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

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

I see no problem with that.

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

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.

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)

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.

As I look into the patch trytond/report/ - Issue 306161002: trytond: Add record name in report filename - Code Review 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]

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

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

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

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.

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

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.

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)

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

This is not an acceptable solution 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.

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 …

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

We should keep using Genshi as in and

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?

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)
        items = []
        if self.full_number:
        if self.reference:
            items.append('[%s]' % self.reference)
        if not items:
            items.append('(%s)' %
        return ' '.join(items)

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

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

Something similar to what we did for subject of notifications but for report filenames.