Try ERPNext Buy Support Partners Foundation

Need to get sales order number and sales person on print sales invoice

I customize sales invoice print using html code.
I need show sales order number and sales person that in charge from sales invoice.

I don’t know how to get that value. Please help me

Sales Order No : {{ doc.name }}

Creator : {{ doc. owner }}

and so on

any other filed next to doc. and you can get fields name from customize any doc

Hi @Ronny_Harianto,

is your problem because you are in the Sales Invoice and need information from the preceeding Sales Order?

One way to achieve this (there are several I am sure) is to add a custom field on the Sales Order, e.g. “Sales Order Reference”. Add the same custom field to your Sales Invoice. Mark them hidden. Then, add a custom script on the Sales Invoice that stores its name in this field on validation, something like

frappe.ui.form.on("Sales Order", {
    validate: function(frm) {
        frm.set_value('sales_order_reference', frm.doc.name);
    }
});

The framework will copy the field with the same name to the subsequent document, therefore, when you create your Sales Invoice from the Sales Order (“Make”), it will be there. Now, you can use it in Jinja with

{{ doc.sales_order_reference }}

The same can be applied for any other fields… Or, you can run a lookup on the other fields from Jinja based on the sales order reference:

{% set sales_order = frappe.get_doc("Sales Order", doc.sales_order_reference ) %}
{{ sales_order.owner }}

Hope this helps.

2 Likes

@lasalesi thanks for this!!

You’re welcome :wink: