Is there a way to show the ARReport Id in Senaite.Impress Report

Hi Everybody,

Is there a way to show the ARReport Id in Senaite.Impress Report?

the unique Id of ARReport could be define and generate in “SETUP →ID Server”

image

then, how to get it when to customize in ReportView class or PT template.

thanks in advance!

Deng

Hi,

supposedly not possible, because there is no report id, when it is rendered.

It is generated after - just for storing in senaite.

thank you @grulisco. you pointed out the key of problem.

but is there an alternative solution if want to keep the traceability in report-document itself ?

You can have a look our custom add-on bika.coa, we have a function get_coa_number and use it on the template bika.coa/src/bika/coa/reports/Multi.pt at 2.x · bikalims/bika.coa · GitHub

and then it’s also used here

Hi lunga,

thank you for sharing the “best practice”. i tried / migrated “the code” to my case.

it works very well by get “id” (generateUniqueId) through “ID Server” and show “id” in document.

one more question is, if ARReport include 2-or-more analysisrequests, then each analysisrequest save the report individually (i have actived). the “id” of ARReport object stored in system is consumed and increment 2-or-more. but get “id” through “ID Server” only increment 1.

then when publish the next report, i will got the “id” show in document and the “id” of ARReport object stored in system are not the same.

so is there a way to adapt “id” when create ARReport object? (for example, the first analysisrequest using xxxx-01, second xxxx-02)

thx again @lunga

Thanks for spotting this @fengyun.deng. I’ll open an issue in our repo and link back to you for updates.

There's another option: generating a UID for each render. Something like this:

<span tal:content="python: str(view.generateId())[:20]"></span>

def generateId(self):

    import uuid

    return uuid.uuid4()

This would generate a unique ID for each render. Although it wouldn't match the ServerID, it guarantees that the ID is unique in the PDF.

The problem with Bika.coa aproach is that if two renders run simultaneously before saving, they will have the same ID in the PDF.