Change Date Format in Terms and Conditions

Hello there,

I got an error after trying to use Jinja variable in Terms and Conditions.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 55, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 52, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 907, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py", line 23, in get_terms_and_conditions
    return frappe.render_template(terms_and_conditions.terms, doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/jinja.py", line 50, in render_template
    return get_jenv().from_string(template).render(context)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "

And here below is my code :

<div><b>Terms and Conditions</b></div>
<div>Document No. {{ name }} is valid until {{ frappe.utils.formatdate(doc.get_formatted('quote_valid_until'), "dd-mm-yyyy") }}.</div>

Please help me to fix this, what I am wrong.

Regards,

@cipher I think it should be <div>Document No. {{ name }} is valid until {{ doc.get_formatted("quote_valid_until") }}</div>

Thank you so much for your reply. I’ve tried to change my code into your suggestion, however the error’s still existed. Any ideas?

Regards,

Hi @cipher

Then probably you are using [quote=“cipher, post:1, topic:23572”]
frappe.utils.
[/quote]
somewhere improperly . Try building a new custom script where you use the

to check whether you get the correct date format and proceed building the remaining things.

Thanks so much again for your reply. Could you please show me some example that how to use the custom script with your suggested code? because I’m quite new to ERPNext and trying to find and learn about it from Discuss ERPNext for long time.

Thank you so much in advance.

Regards,

1 Like

@cipher . We both sail in the same boat , even I’m trying to learn erpnext from Discuss ERPNext for a long time . Anyway for my use case I wanted to print a date in dd-mm-yyyy format but could not get that done with ubuntu , so here is what I did .

Referred this link to setup my erp server’s date format How to Customize Time & Date Format in Ubuntu Panel | UbuntuHandbook

and then entered the below code in custom print format server side

{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
    {% if letter_head and not no_letterhead %}
    <div class="letter-head">{{ letter_head }}</div>
    {% endif %}
    
    {% if max_pages > 1 %}
    <p class="text-right">{{ _("Page #{0} of {1}").format(page_num, max_pages) }}</p>
    {% endif %}
{%- endmacro -%}
{{ add_header(0,1,doc,letter_head, no_letterhead) }}




<div class="row" ; style="width: 750px">  



<div class="row">

<div  class="col-xs-1"; style="width: 6%;text-align:left;  padding-left: 0;padding-right: 0; height: 20px; "><big><b></b>Date:</big></div>
<div  class="col-xs-1"; style="width: 10%;text-align:left;padding-left: 0; padding-right: 0;height: 20px"><big><b>{{ doc.get_formatted("date") }}</b></big></div>
</div>  

</div>

Have you tried using “dd-MMMM-yyyy”?

{{ frappe.utils.formatdate(doc.get_formatted('posting_date'), "dd-MMMM-yyyy") }}

1 Like

Thanks for your reply. However, after using your code it’s still the same error. Any ideas?

I use this code exactly as it is, but is inside a HTML custom field or at a custom print format.
{{ frappe.utils.formatdate(doc.get_formatted('posting_date'), "dd-MMMM-yyyy") }}

You’re right, at Terms and Conditions seems that doesn’t work any, can’t be changed, why don’t you try creating a custom print format? Or adding a HTML custom field and calling at the custom print format.

See Jinja in Terms and Conditions · Issue #14701 · frappe/frappe · GitHub

@Francisco_Buendia
Hi,
on setting the date format dd-mmm-yyyy
I got following error message on date picker

Any help would me much appreciated!