This question has been flagged
9 Replies
10748 Views

While my date format settings for the corresponding (and every) language are "%d/%m/%Y" in PDF export (aka print) it is always "%m/%d/%Y". How can I fix this?

Avatar
Discard
Author

Thank you Yenthe for your answer. I do not want to hardcode it since I have customers in the US so I want the date format to follow the language of the customer. Isn't this supposed to be the default behavior?

I cannot comment your answer due to limited Karma. Please see my comment above.

@Fotis hmm yes I don't like it hardcoded either. The default behaviour *should* be that the report takes the dateformat that you chose as language but this doesn't seem to be the case. You could open a report for this at https://github.com/odoo/odoo/issues/ with some luck they'll fix it..

Author

Yenthe I have tried both your suggestions and none seemed to work for me. I remind that I need the edit in invoice PDFs. i tried changing both sale.report_saleorder_document and account.report_invoice_document qweb templates but it had no effect. I have filed a bug report: https://github.com/odoo/odoo/issues/4618

Have you tried this with an invoice that existed before you modified or after you've modified the QWeb? An invoice lay-out never changes after it has been created.. not even if you changed the QWeb so my guess is you didn't make a new invoice after you changed the dateformat on the QWeb template. And good that you created a report for this!

Best Answer

Hi Fotis

To fix this you have two options.
The first is to go to settings > Reports, find the correct QWeb report and open it. Modify the line <p t-field="o.date_order"/> here to <p t-field="o.date_order" t-field-options="{&quot;format&quot;: &quot;dd/MM/YYYY&quot;}"/>

The second option is to do it permanently (also when you update your module) by modifying the XML file for the report where the dateformat is wrong.
For example on a sale order you will see this in the code: (report_saleorder.xml under /addons/sale/views/)

<p t-field="o.date_order">

If you then modify it like this:

<p t-field="o.date_order" t-field-options="{&quot;format&quot;: &quot;dd/MM/YYYY&quot;}"/>

You will get a dateformat of d/m/Y in place of m/d/Y.

 

Avatar
Discard
Best Answer

The best solution to keep the date localization is to do the following:

<p t-field="o.your_datetime_field" t-field-options='{"widget": "date"}'/>

Avatar
Discard
Author Best Answer

Turns out this issue happens only to existing invoices. New invoice dates seem to be fine after changing date format settings. I have updated my github issue description to include this improvement for existing invoices as well.

Avatar
Discard

This is not a bug or an error. Changing an approved invoice is technically even illegal as it is an official and finale document.