Jasper Erpnext Integration

For the last question. If you see my last image, i upload /Custom Cherry Local 2/compiled/localizationdemo.properties. My Jasper module does not check if localization.properties is uploaded because you can put that in java environment variable and has one general file. So, if you has localization and don’t provide you will get some errors.

Let me know if this help.

Am able to add .jpg and localizaationdemo.properties to the reports without any problems and it works fine. They dont get attached as a child though. see attachment:

near the upload button only the jrxml gets listed as an attached file.

However in my case, the report I have designed in Jasper studio has a subreport, which is another jrxml. May be because the files that I attach don’t go as a child, am not able to attach 2 .jrxml files.

Also, if I upload the parent report first and save, it throws error that the subreport is missing.

I hope I have made myself clear.

Regards

Hi.

Near the upload button you can click to see the tree structure.

Also to upload childs you have first to click in parent, in this case, click in /Cherry/Cherry.jrxml and then in upload button to upload as a child.

Keep me updated!

Yes, I see the tree in Cherry. But, with my subreport file, am not able to add the child even if I click on parent and then click upload. I get the same error…“Remove first the file (None) associated with this document or (None) is a wrong parent.”…Am i missing anything else?

krithi

Hi.

I fix the code. Now you can add a second report if it is a subreport.

The code will check if the subreport is indeed a subreport of the first one, so you must install first the parent.

Let me know if it is ok now.

Thanks.

Thanks much. I could now attach subreports without any error.

I need more clarification on setting the locale. It is not a parameter in my .jrxml file. It is set only when I create a Jasper Report in Erpnext. Kindly clarify why it wouldn’t accept a value I select in Jasper Report but works fine when I allow it to ‘Ask’ at runtime.

I replied too soon. Though it lets me upload the subreport, at run time, it gives JRException: Resource not found at :compiled/childlabel.jasper(see attached image)

If I run a report with the child alone, there are no issues though.

Hi.

To answer to localization question; you need to have one localization file for every language you want to support in your report. The name of the file need to be like this: anyname_es.properties or anyname_ca_ES.properties - this is for spain.
You can upload to jasper folder or you can put in your java classpath. Of course if you have many translation the preferred way is in classpath.

In the case of subreport error:

I need to know if the file exists childlabel.jasper in the compiled folder.

If exists then update jasper.

I appreciate any feedback.
Thanks.

Hi,
Yes, childlabel.jasper is present. Now, In jasper_reports.py, line 147, in getSubReportsQuery,

report_path = path_name.split("/",1 )[1][:-6] + "jrxml" 

I get “IndexError: list index out of range” error. I fixed it to [0][:-6]. The report gets generated without any issues now. Please test the same.

Thank you. I will let you know about the localization.

Hi.

I Fixed this and another error associated with this. Please update.

If you find more errors please tell me.

Thanks for help me to improve jasper.

Few more questions:

  1. When we set the parameter in jasper report, I chose the ‘Is doctype id’ option. It defaults to ‘Ask’ in parameter action and doesnt allow me to change it to ‘Automatic’.

I don’t want any prompts while generating the report. When am in the page of a particular doctype id, I would click on a button to generate the report and it should directly get displayed. Will it be possible to allow me to select ‘Automatic’ as parameter action?

  1. How do I use “use for custom fields” option? on checking the option, where should I mention which field should be taken for the query?

  2. I just now saw that you have added “Do not use” as an option for locale. This is exactly what I was looking for.

However, it still asks for the locale when I generate the report from the click of my custom button. I don’t see the prompt when the report is generated from the jasper icon on the upper right corner!!!

Could you tell me which function should I invoke to achieve this?

Thanks

Hi.

First. How are you planning to give the value to the param? A param of type is doctype id is for selects of this type: select field1, field2, ... from 'tabSomeDoctype' where fieldx = 'your_param_value'; If you know the value when the report is created as doctype (at compile time) then you can put the value in Parameter Value of the Parameters table.

You can make the param of type ‘Is for server hook’, this way it will not ask for value. If you do, then look at JasperBase.py function get_param_hook line 142 for some examples (remove the self in your implementation). You have to make a hook for on_jasper_params.

Of course i can make possible for you to choose Automatic, but i made this way to force to provide a param or provide it in server side. If you don’t provide a param it will give you an error. Give me an example to see if there is other way!

Use For Custom Fields is for Jasper Custom DataSource. In this case you don’t provide a queryString (select query). Instead you only provide fields like this in your jrxml report file:

<field name="doctype_name:doc_name:doc_field" class="java.lang.String"/>

Example:

<field name="User:Administrator:email" class="java.lang.String"/>

for each field you have you must have a text field expression with the same name:

<textFieldExpression><![CDATA[$F{User:Administrator:email}]]></textFieldExpression>

In this way you can put any field from any doctype/docname and mix doctypes.

The second problem i will check it tomorrow.

I will wait for your feedback.

Thanks.

The examples for hooks on_jasper_params have hardcoded values. How do I set the value to a field in doctype? I want to set it to the record that I am currently in, from which I would click the button to generate the report.

When i get home i will Try to easy things for you. Meanwhile, set the hook and check the values that are sent, there are the doc value.
If for some reason the value is not there you can with the id of the doc to get the value with frappe.get_value(…).

Hi.

I made some changes to easy the process of call reports manually (with the click of a button in your case).

Now you can call:

jasper.get_jasper_report({jr_name: "Cherry Local", jr_format: "pdf", doctype_type:"Form", params: {idade: "12"}, doctype:"User", docids:["luisfmfernandes@gmail.com", "Administrator"]})

or if it is a general report:

jasper.get_jasper_report({jr_name: "Aircraft XML Local", jr_format: "pdf"})

In these functions i will check if it is for doctype. If you provide doctype_type and doctype then the function call first jasper.getListOnly and then jasper.getOrphanReport.

Now you can provide params object with all the params and his values.

To use this function and don’t show the dialog you must check in the doctype of the report, in this case, Cherry local, Don't Ask For Parameters.

I made a quickly check and everything is ok. I will make more tests as soon as possible. If you find errors let me know.

I will, also, make more improvements…

Thanks.

Please correct me if am wrong. The values in the params object are still being hard coded here, isn’t it? or is there a way I can mention the doctype record that I would click on?

When I select ‘Is doctype id’ for parameter type, during runtime, the param value, in the prompt already defaults to the primary key of the record I am in. In that case, I jus want to avoid the prompt. Can that be achieved by setting it to ‘Automatic’?

Did you get a chance to fix the ‘Do not use’ option for locale, in case of button click?

Thanks much for your guidance.

Hi.
You can now set Automatic in parameters of type Is doctype id. You can also put in the field Field Doctype Value or in the box Parameter Value the name of the field that you want to use as the value for this parameter. In this way it is not limit to the id/name of doctype.

As an example, putting the Parameter Value box as System Settings:language you can, inside Administrator of doctype User, call the following function:

jasper.get_jasper_report({jr_name: "Cherry Local", jr_format: "pdf"})

It will generate the report Cherry Local in pdf with parameter that you choose for type Is doctype id with the value of the field that you put in Parameter Value` box, in this case with the value of language of the system.

If you want the parameter of type Is doctype id as the field of the doctype where you generate a report (User in this example) then you just need to set the value Field Doctype Value to the name of the User field that you want. As an example you can set the value Field Doctype Value to first_name, the field of doctype User.

You can also pass parameter of type Is doctype id in params argument of jasper.get_jasper_report function, like this, any where call:

jasper.get_jasper_report({jr_name: "Cherry Local", jr_format: "pdf", doctype_type:"Form", params: {language: "System Settings:language"}, doctype:"User", docids:["luisfmfernandes@gmail.com"]})

OR, if inside form User/Administrator just call:

jasper.get_jasper_report({jr_name: "Cherry Local", jr_format: "pdf", params: {language: "System Settings:language"}})

The format of Parameter Value box can be: doctype:fieldname or doctype:docname:fieldname or fieldname.

NOTE: when you use field Field Doctype Value do not use box Parameter Value and the other way around. But if you do then the values passed in jasper.get_jasper_report take precedence to the others then Parameter Value and then Field Doctype Value.
Also, if you do not pass to jasper.get_jasper_report({jr_name: "Cherry Local"}) jr_format it default to pdf.

Let me know if this work for you or you find any error.

Hi.

I made a mistake in the last explanation.

If the param is for the doctype of the report, then you can put in Field Doctype Value the name of the field and only the name that you want to get the value from. If you do want to get the param value from another doctype then you need to put that information in Parameter Value box and use the role: doctype:docname:filename.

I already made the corrections in my last comments.

Thanks.

There seems to be a problem after git pull, the jasper reports page doesnt load…found these errors in the js console

jasper_erpnext_report.js:143 Uncaught SyntaxError: Unexpected token )
desk:202 Uncaught TypeError: jasper.dialog_upload_tree is not a function

Anything missing from my side?

Hi.
I don’t do anything to change that part of the code.

I try in firefox, safari and chrome and i don’t get that error. On onload event of jasper report doctype it call jasper.dialog_upload_tree with new, so it is an object not a function. I don’t understand why it is complaining with function call.

Tell me what is in jasper_erpnext_report.js:143 line.

Try bench update again!

Then,

If not solve the problem try bench migrate.

Here everything is ok.

Let me know.