ODT Invoice template through API: Solution found

Hello,

Solution to create personalized invoice with Dolibarr.
As it is not easy, I just share the info:

Please note it is necessary to install unoconv on your server and you absolutely need to create your ODT file with openoffice. Do not use Word !

Config Dolibarr > Divers
MAIN_ODT_AS_PDF_DEL_SOURCE set to 1
MAIN_ODT_AS_PDF set to sudo -u xxx /usr/bin/unoconv

Replace the xxx by a user who has the necessary rights on your server because if it is not set correctly you will have some errors (essentially 1 when you have a problem of rights)

                $jsonParams = json_encode([
                "module_part" => $module,
                "original_file" => explode('.',$filename)[0]."/".$filename,
                "doctemplate" => $doctemplate,
                "langcode" => $langcode
        ]);

Be careful with the $doctemplate var as you need to set it to “generic_invoice_odt”

You will have this error in the log file if it is not correctly set

2020-01-28 14:21:14 ERR 178.33.235.194 Error url=/api/index.php/documents/builddoc, query_string=, msg=Error File /var/www/crm.xxxxxxxxxx/htdocs/ticketsup/core/modules/facture/doc/pdf_template_fr_BE.$
2020-01-28 14:21:14 ERR 178.33.235.194 Error url=/api/index.php/documents/builddoc, query_string=, msg=Error File /var/www/crm.xxxxxxxxxx/htdocs/ticketsup/core/modules/facture/doc/pdf_template_fr_BE.$

I encountered some problems with row.lines tag in the ODT file so I used

[!-- BEGIN lines --]

Michael

1 Like

Hi,

Thanks for sharing.

It is not 100% clear where we have to use the $jsonParams ?

This is the call to the API

$url = $this->baseUrl.‘documents/builddoc’;
$header = ['DOLAPIKEY: '.$this->key, ‘Content-Type: application/json’];

    $jsonParams = json_encode([
            "module_part" => $module,
            "original_file" => explode('.',$filename)[0]."/".$filename,
            "doctemplate" => $doctemplate,
            "langcode" => $langcode
    ]);

    $answer = json_decode($this->curlPut($url, $header, $jsonParams));
1 Like