Custom printing form

Well the thing is that I asked how to print a ticket with the address on but not the hole address. Then I got an email telling me this code: ------------------------- You might have to split the address_display like {{ doc.address_display.split("\n")[0] }} Posted by rmehta on 08/06/2015 ----------------------------- So lets say you pick a customer that didn’t have the complete address and then we tried to print and the printing form Accounts->Sales Invoice-> customer “JOE SMITH” then select last one, and then print form “Pos Ticket INNYEC” did not print because of this error on a blank pop up window:

Message
Close
Server Error: Please check your server logs or contact tech support.
Traceback (innermost last):
File “/home/frappe/v5press/benches/1512081119/apps/frappe/frappe/app.py”, line 67, in application
response = frappe.handler.handle()
File “/home/frappe/v5press/benches/1512081119/apps/frappe/frappe/handler.py”, line 77, in handle
execute_cmd(cmd)
File “/home/frappe/v5press/benches/1512081119/apps/frappe/frappe/handler.py”, line 94, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/v5press/benches/1512081119/apps/frappe/frappe/init.py”, line 788, in call
return fn(*args, **newargs)
File “/home/frappe/v5press/benches/1512081119/apps/frappe/frappe/templates/pages/print.py”, line 139, in get_html_and_style
no_letterhead=no_letterhead, trigger_print=trigger_print),

I compared the ones that document didn’t show the error and was because the ones with error didn’t have the complete address. Then I check all addresses and completed information that was missing hoping the error would`t show again. But then I have a sell to the same customer and the error appears again.

Any ideas? thanks for your help.

Regards,

Gilberto

Hi @gilbester

The error message tells that you do not have a letter head defined.
Please check the letter head first if there is no letter head defined then remove the tick from letter head while having print preview.

Please share the code you are using to print the customer address.

Hi, Thanks here is the code.

.print-format table, .print-format tr, .print-format td, .print-format div, .print-format p { font-family: Monospace; line-height: 110%; vertical-align: middle; font-size: 11px; } @media screen { .print-format { width: 2.8in; padding: 0.10in; min-height: 7in; } }

{{ doc.company }}
{{ doc.select_print_heading or _("Invoice") }}


www.innyec.mx
Miriam Hannali López Villaseñor
Av. Javier Mina 2787
Rinc. de San Andrés
3665-3911 / 3665-4011
{{ _("Receipt No") }}: {{ doc.name }}
{{ _("Date") }}: {{ doc.get_formatted("posting_date") }}
{{ _("Customer") }}: {{ doc.customer_name }}
{{ _("Domicilio")}}: {{ doc.shipping_address.split("\n")[0]}}


{%- for item in doc.items -%} {%- endfor -%}
{{ _("Item") }} {{ _("Qty") }} {{ _("Amount") }}
{{ item.item_code }} {%- if item.item_name != item.item_code -%}
{{ item.item_name }}{%- endif -%}
{{ item.qty }}
@ {{ item.get_formatted("rate") }}
{{ item.get_formatted("amount") }}
{%- for row in doc.taxes -%} {%- if not row.included_in_print_rate -%} {%- endif -%} {%- endfor -%} {%- if doc.discount_amount -%} {%- endif -%}
{{ _("Net Total") }} {{ doc.get_formatted("net_total") }}
{{ row.description }} {{ row.get_formatted("tax_amount", doc) }}
{{ _("Discount") }} {{ doc.get_formatted("discount_amount") }}
{{ _("Grand Total") }} {{ doc.get_formatted("grand_total") }}
{% if doc.get("taxes", filters={"included_in_print_rate": 1}) %}

Taxes Included:

{%- for row in doc.taxes -%} {%- if row.included_in_print_rate -%} {%- endif -%} {%- endfor -%}
{{ row.description }} {{ row.get_formatted("tax_amount_after_discount_amount", doc) }}
{%- endif -%}

{{ doc.terms or "" }}

{{ _("Conserve su ticket")}}
{{ _("---------------------------------")}}
{{ _("GRACIAS POR SU PREFERENCIA")}}
{{ _("---------------------------------")}}
{{ _("Descuento llenando encuesta de calidad en el servicio")}}
{{ _("www.innyec.mx/index.php/contacto/calidad") }}

First of all, try after removing the line {{ _("Domicilio")}}: {{ doc.shipping_address.split("\n")[0]}} . It will ensure that this line is giving the error.

After confirming, you can try this:
{{ _("Domicilio")}}: {{ doc.shipping_address and doc.shipping_address.split("\n")[0] or ""}}

Ok. Thanks. Now the problem is that the customer it does have an address. And why it is not showing the address?

Don’t understand what is the problem now?

Hello,

The line causing the problem is correct, I use the new code, now the error is gone but still need the address.

Thanks,

Gilberto

As Sales Invoice does not have the address, it does not show in print. That is the expected behaviour. Are you trying to fetch the customer address from somewhere else and print in the invoice?

This is the issue,

Let me try to explain.

The customer did not have an address so therefore mark the error, then we added the address and we tough it was going to be updated in the future events.

But then the customer buys again and we got the error as if no address was for the customer so make an error on the printed form. Now the error is passed because the addresses ignore. But in the operation the address is fundamental to continue due someone is going to make the delivery based on the printing, and we have ignore the address.

So the main problem is that even when we add an address is not being pulled out to the form.

Thanks to your cooperation we can print the form but the address should be there.

Thanks,

Gilberto