Cannot print Client's contacts and addresses

Hello everyone,

Why is it not printing address_html and contact_html at Client or Supplier forms?

If I would use a custom print format, how can be called address_html and contact_html if are not tables?

Regards.

Unfortunately that is generated from a query. You will have to make a custom print report with Jinja template for this.

Thanks @rmehta,

Could you please share any guide to reference? I have used jinja before, but I’m not an expert and can’t figure how.

Regards.

Hi @kolate_sambhaji,

I followed some of your posts and now I can print a table with addresses related to a Supplier, using this script:

<table border="1" cellpadding="0" cellspacing="0" style="width:100%;" width="100%">
	<thead>
		<tr>
			<th scope="col" style="white-space: nowrap;">DIRECCIONES</th>
		</tr>
	</thead>
	<tbody>
		{%- for row in frappe.get_list(doctype="Address", 
			fields=["address_type", "address_line1", "address_line2", "city", "state", "country", "pincode", "phone"],
			filters={ "address_title":doc.supplier_name}) -%}
		<tr>
			<td>
			<p align="left">{{ _(row.address_type) }}<br>
			{{ row.address_line1 }}, {% if row.address_line2 %} {{ row.address_line2 }} {% endif -%}, {{ row.city }}
			{{ row.state }}, {{ row.pincode }}, {{ row.country}}.
			{% if row.phone %} Teléfono Principal: {{ row.phone }}. {% endif -%}
			</p>
			</td>
		</tr>
		{% endfor %}
	</tbody>
</table> 

But I can’t do the same with contacts. I’m trying to filter contacts based on child table Dynamic Link: filters={ “Dynamic Link”, “link_name":doc.supplier_name}) -%}. It results on Server error.

<table border="1" cellpadding="0" cellspacing="0" style="width:100%;" width="100%">
	<thead>
		<tr>
			<th scope="col" style="white-space: nowrap;">CONTACTOS</th>
		</tr>
	</thead>
	<tbody>
		{%- for row in frappe.get_list(doctype="Contact", 
			fields=[“salutation”, ”first_name", "last_name", “designation”, “department”, “email_id”, “phone”, “mobile_no”],
			filters={ “Dynamic Link”, “link_name":doc.supplier_name}) -%}
		<tr>
			<td>
			<p align="left">
			{{ row.salutation }} {{ row.first_name }} {{ row.last_name }}. {{ row.designation }} {{ row. department }}<br>
			{% if row.email_id %} {{ row.email_id }} {% endif -%}. {% if row.phone %} Teléfono: {{ row.phone }}. {% endif -%} {% if row.mobile_no %} Teléfono: {{ row.mobile_no }}. {% endif -%}
			</p>
			</td>
		</tr>
		{% endfor %}
	</tbody>
</table>

How could be filtered basing on a child table in Contact doctype? Or is there a simpler way?

Regards.

@rmehta @kolate_sambhaji anyone…

Could anybody please help me on this? Any idea?

How can possible that in Supplier or in Customer, can be seen addresses and contacts, but cannot print them as a default function? Not even in standard print formats.

Thanks for effort and time.

What about this error - why not check your logs for ideas

@clarkej, hi

Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)

desk.min.js?ver=1508207731.0:1565 Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 57, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 923, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/www/printview.py", line 187, in get_html_and_style
    no_letterhead=no_letterhead, trigger_print=trigger_print),
  File "/home/frappe/frappe-bench/apps/frappe/frappe/www/printview.py", line 158, in get_html
    html = template.render(args, filters={"len": len})
  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 "<unknown>", line 9, in template
TemplateSyntaxError: unexpected char u'\u201c' at 254

Any idea?
Thanks.

yes that could explain your error - it would be an idea to search your template code for a syntax error!

After many days and many tries, I found the error: it was in quotation marks. Thanks @clarkej.

SOLVED. This code works to print Contacts at Supplier.

<table border="1" cellpadding="0" cellspacing="0" style="width:100%;" width="100%">
	<thead>
		<tr>
			<th scope="col" style="white-space: nowrap;">CONTACTOS</th>
		</tr>
	</thead>
	<tbody>
		{%- for row in frappe.get_list(doctype="Contact", 
			fields=["salutation", "first_name", "last_name", "designation", "department", "email_id", "phone", "mobile_no"],
			filters={ "link_name":doc.supplier_name}) -%}
		<tr>
			<td>
			<p align="left">
			{{ row.salutation }} {{ row.first_name }} {{ row.last_name }}. {{ row.designation }} {{ row. department }}<br>
			{% if row.email_id %} {{ row.email_id }} {% endif -%}. {% if row.phone %} Teléfono: {{ row.phone }}. {% endif -%} {% if row.mobile_no %} Teléfono: {{ row.mobile_no }}. {% endif -%}
			</p>
			</td>
		</tr>
		{% endfor %}
	</tbody>
</table>
3 Likes