How to add "PDF" link in Purchase Order list? (i.e. direct link to specific Print Format)

Is it possible to do this…

Where “view” link would be a link to a specific “Print Format” with [x] Letterhead enabled?

Reason for this is we have some old school users who will simply want to view in PDF format with least amount of clicks.

1 Like

Not a solution to this question, but I’m sure everyone knows that if you click into the PO, then you have the option to print it using the icon top right of screen…

image

From there, you can print, print preview, export to pdf and view, etc. … lots of clicks.

What I am asking (to have a direct link to a print view/preview) would save a couple of clicks I guess.

Does this help?

Haha nooo :slight_smile:

That’s 3 clicks just to get to print dialogue… and it’s actually 8 clicks total to be looking at a PDF* from there (including selecting letterhead).

What I’m after is 1 click to be looking at PDF with letterhead + your default/preferred Print Format for purchase orders on that screen. 1 click to what you’re after is so much more user-experience friendly than 8. :smiley:

I’m too new to erpnext to figure out how to do it just yet…

but it should be as simple (with custom script?) as linking the same…
letterhead= ‘yes’
print_format= ‘thisformat’
PDF generating link foreach row in the purchase order list?

An option for 1 click Vs. 8?.. that would be a big improvement!

(it’s only 4 clicks if you want to print preview in a non-standard print format by using the printer icon within the purchase order record)

reasonable requirement, I will try…

2 Likes

referred to the standard todo doctype which has a button in the list view.

here how it can be done for purchase order list

  1. add the client script for purchase order list view as below
    frappe.listview_settings['Purchase Order'] = {
        button: {
    		show: function(doc) {
    			return true;
    		},
    		get_label: function() {
    			return __('View');
    		},
    		get_description: function(doc) {
    			return __('Open {0}', [`${doc.name}`])
    		},
    		action: function(doc) {
    			frappe.set_route("/app/print/Purchase Order/"+doc.name);
    		}
    	}
    }
  1. new in purchase order list view

here print view with default language, print format and letter head preset, this way, there is no need to manually handle this default setting in client code, also the context(standard menu) is kept, user can easily switch back as needed. anyway jump to PDF is also possible by different route path and route options with above mentioned default values.

9 Likes

That’s awesome. Thanks!

I wonder if I did something wrong… look at all the warnings and errors:

image

it seems some cut & paste changes single quotes, but even after fixing still has error and not working…

image

nevermind… I missed the tildes ` around [$doc.name}] brackets. Really have to be careful of cut and paste from forum. Can you tell this is my first time cutting & pasting script from Erpnext forum? :slight_smile: Leaving the progression below for other newbies to learn from my mistake…

image

And now…

image

Working!

Very cool :+1:

1 Like

Cool one. I wish someone explain what does these 16 line of beauty does.

1 Like

@TurkerTunali TLDR: 1 click to get to print view from list view.

instead of 4-9+ clicks to go from a list view of a Doctypes (in this case, Purchase Order) to print/pdf view, this code allows for button directly on the list. This gets it down to 1-2 clicks for print/pdf view.

You also want probably want to set the default Print Format and Letterhead for your DocType… this helps you get down to that 1-2 clicks (instead of having to change print format from Standard every time, etc.)

Thank you for your explanation but I already know output of the code.
I just want to know how @szufisher did it.

He borrowed the button code from todo doctype and route button action to /app/print/Purchase Order/ :slight_smile:

2 Likes

good explaination of what I have done.

1 Like

Funny. Really ? I’ve missed that. Thank you :slight_smile:

@szufisher can we set the print format?

We can also trigger full page view in a new tab. Then we can set print format name, language etc.

I’ve used

return __('Open {0}', [doc.name])

at line 11. Because it doesn’t show the doc name on mouse hover.

I’ve created a tutorial about this one. You may watch it here tomorrow. I also modified a bit to set the print format name and to print directly.

Modified version is here .

2 Likes