Custom script not working in print

I have changed calculations of item amount and total in sales invoice , it works good but when trying to print it shows default total value not value calculated in my custom script
here it works

but to print preview or PDF:

How to solve that?
Thanks in advance

I think you should make custom print format and make all your calculations in it by using Jinja

facing the same issue, am using custom print format though,

used a script inside print format to convert some numbers to arabic, conversion works fine in print preview , but when a pdf is generated or doc is actually printed, it goes back to what it was before conversion

1 Like

I have same issue too and ERPNext Support is no help. I wonder if this is a bug versus an issue with our custom calculations?

it will be same issue i think because we will render the same fields value

so what do you think to solve that?or what’s going wrong?

may be ,we need support team help

no i do not think so
because you will replace your custom script with calculations in print format and it will work
i tried it before in salary register to make totals and show totals of specific columns
try it :slight_smile:

for example always return default number in any print format

would you share some calculations of what you want to do to help you in doing it ?

1 Like

print preview is generated in client side, and actual pdf is rendered on server,
wkhtmltopdf renders with data available on the server, client scripts in print formats are not run

1 Like
frappe.ui.form.on('Sales Invoice',{onload:function(frm){

var custom_total=0; 
$.each(frm.doc.items || [], function(i, d) {
    d.amount= d.rate * d.qty * ((d.نسبة_انجاز_الأعمال)/100)

frm.set_value('total', custom_total)






Thanks in Advance

Thanks for clearance I was think there is an error with my code

that is for things in tag in actual print format,

your issue, is mostly you are not saving the data to doc but rather just assigning it to be visible on client side, if you save it to a field and call it in print format, it will be resolved (i think)

my issue is this

this is in print preview inside erpnext

this is when pdf/full page/ or when the actual “Print” button in preview is clicked

1 Like

so,How to that,how to save it? I need to save it to total field i.e with new calculation results

may be you need to add arabic language to your system

you can do you for loop with jinja like this

				{%- for row in doc.earnings-%}
				{%- if row.add_to_print == 0 -%}

							<tr style="border-bottom: 1px solid #d1d8dd">
								<td style="direction: rtl; width: 75%; text-align: right;text-align: Right; font-size: 8.0pt; font-family: Cairo; color: #404040;">
									{{ row.salary_component }}				
								<td style="direction: rtl; width: 25%; text-align: right;text-align: Right; font-size: 8.0pt; font-family: Cairo; color: #404040;">
									{{row.get_formatted("amount", doc) }}			


				{%- endif -%}
				{%- endfor -%}

and you can do what ever you want in your loop

Solved this issue by moving the conversion from js script in print format to a server side python function and calling it in print format. Works fine now.

1 Like

How do you think this can be done on ERPNext Cloud? I am having an issue just like this.