Customized Sales Order format

Hi,

I am new to ERPNext and is having problem with customizing a Sales Order print format.

I would like to print the Sales Order details and I am not sure how to get that.

I have tried
{{ frappe.db.get_value(“Sales Order Item”, doc.name, “item_code”) }}

and it’s showing error.

Can someone hep me with this or point me to some resources that can help ?

Thanks in advance,

Jeff

Hi Jeff,
In general, it would be really helpful if you shared the error it’s showing. Here, the problem is that you’re trying to get the Sales Order Item using the Sales Order’s name.

Hi Peterg,

Thanks for the reply.

For this case, it shows “None” in the report.

However, using the standard report provided, it is showing the Sales Order details that was entered.

What i want to know is what is the correct code or script to get the different information like Sales Order details and the Item details (description, etc.) that I can show in the Sales Order document.

Thanks,

Jeff

The Sales Order doctype lists items in what’s called a “child table”, defined by a “child doctype”. In the database, child doctypes are stored in independent tables. Every Sales Order has its own name field, but every Sales Order Item has its own (different) name field too. That’s why what you’re trying to do doesn’t work.

The reason for this structure is that Sales Orders and Sales Order Items have a one-to-many relationship: every Item belongs to exactly one Sales Order, but each Sales Order can have many Items. Likewise, displaying data from child doctypes is a bit more complicated than just calling a variable.

On the Python side, when Frappe assembles your document object, child tables are assembled as lists. You can use any of the normal Jinja features to iterate through these lists. If you just want to print details from the first Sales Order Item, it’s as simple as: {{ doc.items[0].item_code }}. The property items refers to the child table, and the [0] indicates that you want the first one.

To print details from multiple child documents, you’ll want to look into how Jinja does for loops.

Hi Peterg,

Thanks for the quick reply.

I will take a look at what you suggested.

Regards,

Jeff