Print Preview Error {{body}}

This week, one of my clients and I discovered this problem, where PDF generation creates an empty page with {{ body }}. I want to discuss in detail, including the solution.

As others have mentioned, when you try to print a PDF, ERPNext must write a document to a DocType named Access Log. That DocType has a related MySQL table named “tabAccess Log”

If ERPNext cannot write a record to this table? Then the PDF generation fails. On your web browser, all you see is {{ body }}. That’s not helpful, because it doesn’t describe the root cause to the User. Probably the Frappe code should be improved around this.

However, if you examine the ERPNext logging on the server, the problem is described in more detail:

pymysql.err.IntegrityError: (1062, "Duplicate entry 'AL-00001' for key 'PRIMARY'")

Aha! ERPNext needs to write a record to this table. It’s trying to use a name “AL-00001.” But MySQL is throwing an error, because that number was already been used. How do we resolve?

Well, normally there would exist a Naming Series named “AL”. You could find this on the Naming Series form in ERPNext. Alternately, you could query the MySQL table directly:

SELECT name, current FROM `tabSeries` WHERE name like 'AL%'

Next, you would find the highest number in Access Log. And make sure the current value in tabSeries is greater (or equal) to that number. You can edit that in ERPNext itself on the Naming Series form.

However… that solution won’t work for Access Log. Because there is no row in “tabSeries” named “AL”.

This is because Access Log is kind of special. Its Naming Series is different. Here’s a screenshot of the “DocType” form for Access Log.

image

It uses a Naming Series option called “format”. DocTypes with “format” don’t reference unique rows in tabSeries. Instead, they share a single Naming Series row with all other DocTypes using “format”.

This special Naming Series record has a empty name (no characters) in SQL table “tabSeries.”

image

Why does “format” work this way? I don’t know. Probably some Python developer just wanted it to work that way, so you could share a global numbering.

Now that we know the correct row in tabSeries, we can fix the problem. Increment the “current” value for that row with the empty name. Make sure the value is greater than the highest name value in “Access Log” (and also, every other DocType that uses the “format” option. I had to write some code to identify that)

After I fixed this problem with the Naming Series for Access Log? All PDF documents were generated successfully. :partying_face:

~Brian

11 Likes