Accessing JRMapCollectionDataSource in JasperReports (using iReport) - dictionary

My datasource is like this:
final Collection<Map<String, ?>> summaryList = new ArrayList<Map<String, ?>>();
parameters.put("P_SUBREPORT", new JRMapCollectionDataSource(summaryList));
The collection has only one Map, and this hashmap has all the information I need.
How do I access that information in iReport, knowing that "?" is a regular POJO having for example fields like "name" and "hours"?
I've this in my masterReport:
<subreport>
<reportElement stretchType="RelativeToBandHeight" x="0" y="21" width="802" height="58"/>
<dataSourceExpression><![CDATA[$P{P_SUBREPORT}]]></dataSourceExpression>
<subreportExpression><![CDATA["subReport.jasper"]]></subreportExpression>
</subreport>
What would I have in the subreport? The following?
<field name="hours" class="java.lang.Double"/>
<field name="name" class="java.lang.String"/>

Related

How to call a FORM VIEW via a button? (Odoo 13 Enterprise)

I defined a button via "Server Actions" in this FORM VIEW:
And created another FORM VIEW from the submenu.
Then I'd tried to call this FORM VIEW via the button, but it's not worked.
So how to call this FORM VIEW via the button?
Please help!
Thank you!
Try to give
"view_mode" : "form"
in xml :
<record id="account_common_report_view" model="ir.ui.view">
<field name="name">Common Report</field>
<field name="model">account.common.report</field>
<field name="arch" type="xml">
<form string="Report Options">
<group col="4">
<header>
<button name="check_report" string="Print" type="object"
default_focus="1" class="oe_highlight"/>
<button string="Cancel" class="btn btn-secondary" />
</header>
</form>
</field>
</record>
python :
call every things call
def check_report(self):
self.ensure_one()
data = {}
data['ids'] = self.env.context.get('active_ids', [])
data['model'] = self.env.context.get('active_model', 'ir.ui.menu')
data['form'] = self.read(['date_from', 'date_to', 'journal_ids', 'target_move', 'company_id'])[0]
used_context = self._build_contexts(data)
data['form']['used_context'] = dict(used_context, lang=get_lang(self.env).code)
return self.with_context(discard_logo_check=True)._print_report(data)

Try to override(noupdate=1) email template in Odoo 12

I am trying override base email template(noupdate=1) but, unable to override. Also, search for my issue but didn't get proper solution.
So, anybody can help me for this issue.
my code is like:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<!-- Email template for reset password -->
<delete id="auth_signup.reset_password_email" model="mail.template"/>
<record id="reset_password_email" model="mail.template">
. . .
</record>
<!-- Email template for new users -->
<delete id="auth_signup.set_password_email" model="mail.template"/>
<record id="set_password_email" model="mail.template">
. . .
</record>
</data>
</odoo>
This error comes when create new user:
ValueError: External ID not found in the system: auth_signup.reset_password_email
Thanks in advance
well, you don't need to override the existing email template. you may need a new one. you could also delete the old one
<record id="reset_password_email" model="mail.template">
<field name="name">Auth Signup: Reset Password</field>
<field name="model_id" ref="base.model_res_users"/>
<field name="subject">Password reset</field>
<field name="email_from">"${object.company_id.name | safe}" <${(object.company_id.email or user.email) | safe}></field>
<field name="email_to">${object.email_formatted | safe}</field>
<field name="body_html" type="html">
<p>whatever email template you want & remember you could use OBJECT AS FOLLOWING</p>
<span style="font-size: 20px; font-weight: bold;">
${object.name}
</span>
</field>
<field name="lang">${object.lang}</field>
<field name="auto_delete" eval="True"/>
<field name="user_signature" eval="False"/>
</record>
please note that you custom template id would be names as custom_module.reset_password_email & it will replace auth_signup.reset_password_email.
or you could follow:
Odoo - How to update non updateable records by XML

Castor Hashtable polymorphism

Good Day
I am attempting to use castor to construct a HashTable that has multiple implementations of an abstract class.
here is the parent "config"
<class name="com.Config">
<map-to xml="config" />
<field name="rulesMap" collection="hashtable">
<bind-xml auto-naming="deriveByClass" >
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="java.lang.String">
<bind-xml name="name" node="attribute" />
</field>
<field name="value" type=com.Rule">
</field>
</class>
</bind-xml>
</field>
</class>
'com.Rule' is an Abstract Class and
at the end of the day i would like an xml struct that looks like this
<config>
<rule-impl1 name="ruleType1Instance1" ruleField="field" />
<rule-impl2 name="ruleType2Instance2" ruleField="field" ruleImpl2Field1="..." />
</config>
I'm not sure there is enough detail or a question that is well formed here to give an accurate answer, but I was doing something pretty similar and ran into some roadblocks. Thought I'd provide my 2 cents. I'm not as familiar with Castor as I am some other XML frameworks and in my case Castor is doing it's automatic marshalling/unmarshalling instead of us manually writing the code to decide when we want it to be done. If we were manually doing that piece I thought we would have been able to make decisions to unmarshall to specific classes that extend the abstract class.
With all my disclaimers out of the way, what you could do.
**If you can add a field to the request/response then create something like this:
public class RuleContainer {
private RuleType ruleType; // possibly build enum or other non-java equivalent
private RuleImpl1 ruleImpl1;
private RuleImpl2 ruleImpl2;
private RuleImpl...N ruleImpl...N;
// getters & setters, etc
}
Then the value of your table is changed to
<field name="value" type="com.RuleContainer"></field>
and include your mapping of the RuleContainer
<class name="com.RuleContainer">
<field name="ruleType" type="com.RuleType"
<field name="ruleImpl1" type="com.RuleImpl1">
<field name="ruleImpl2" type="com.RuleImpl2">
<field name="ruleImpl...N" type="com.RuleImpl...N">
</class>
also include mappings of each implementation whatever those may look like. In my case I've broken each implementation mapping out into a separate file and used the
<include href="" />
tag to include those extraneous mappings in the parent file.
All of this sets you up to use that RuleType field to know which rule in the RuleContainer is valid (the rest will be null as the Castor default is required="false"). The logic to work with each implementation of a Rule is simple to write from there.
Hope this helps.

Restrict upload by filetype or mimetype using Dexterity on Plone

I have a custom content type, built with dexterity. In the schema (The schema is listed below), I use 'plone.namedfile.field.NamedFile' for attachements/uploads.
I would like to restrict uploads so that only mp3 files can be attached to my content type. What is the best approach for achieving this?
Here is the full schema/model for my content type:
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="date" type="zope.schema.Date">
<description />
<title>Date</title>
</field>
<field name="speaker" type="zope.schema.TextLine">
<description />
<title>Speaker</title>
</field>
<field name="service" type="zope.schema.Choice">
<description />
<title>Service</title>
<values>
<element>1st Service</element>
<element>2nd Service</element>
</values>
</field>
<field name="audio_file" type="plone.namedfile.field.NamedFile">
<description />
<title>Audio File</title>
</field>
</schema>
</model>
I shall begin my search here: http://plone.org/products/dexterity/documentation/manual/developer-manual/reference/default-value-validator-adaptors
I've decided to use javascript for my first line of validation.
I've based my solution on information found at <input type="file"> limit selectable files by extensions
Based on the advice my script looks something like this:
$(document).ready( function() {
function checkFile(event) {
var fileElement = document.getElementById("form-widgets-audio_file-input");
var fileExtension = "";
if (fileElement.value.lastIndexOf(".") > 0) {
fileExtension = fileElement.value.substring(fileElement.value.lastIndexOf(".") + 1, fileElement.value.length);
}
if (fileExtension == "mp3") {
return true;
}
else {
alert("You must select a mp3 file for upload");
return false;
}
}
$("form#form").bind("submit",checkFile);
});
This is half the solution, next I'll need to add validation on the server side.

NHibernate One-To-Many Delete Not Cascading

I have a 'Photo' class and a 'Comment' class. An Photo can have multiple comments assigned to it.
I have this configured as a one-to-many relationship within my HBM mapping file, and have set cascade="all-delete-orphan" against the 'Comments' bag within the Photo.hbm.xml mapping file.
However, if I try to delete a Photo which has 1 or more Comments associated with it, I am getting 'The DELETE statement conflicted with the REFERENCE constraint "FK_Comments_Photos"'
I tried a couple of other cascade options against the Comments bag in my Photo.hbm.xml but regardless of what I set it to, I'm getting the same outcome each time. I just want to be able to delete a Photo and have any associated comments automatically delete too.
Here is my Photo mapping (edited for brevity):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" .... default-access="property" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Photo" table="Photos">
<id name="PhotoId" unsaved-value="0">
<column name="PhotoId" />
<generator class="native" />
</id>
...
<bag name="Comments" table="Comments" cascade="all-delete-orphan" order-by="DateTimePosted desc" where="Approved=1">
<key column="PhotoId" />
<one-to-many class="Comment" />
</bag>
</class>
Here is my Comment mapping (edited for brevity):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" ... default-access="property" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="Comment" table="Comments">
<id name="CommentId" unsaved-value="0">
<column name="CommentId"></column>
<generator class="native" />
</id>
...
<property name="Author" not-null="true" />
<property name="Body" not-null="true" />
<property name="Approved" not-null="true" />
<many-to-one name="Photo" not-null="true">
<column name="PhotoId" />
</many-to-one>
</class>
Does anyone have any suggestions as to why the cascade is not happening when I try to delete a Photo with comments associated with it?
UPDATE: The only way I can get the cascade to happen is to configure the 'Delete Rule' within SQL Server against this relationship to 'Cascade', and in doing so means that I don't need to specify any cascade action within my NHibernate Mapping. However, this isn't ideal for me - I'd like to be able to configure the cascade behaviour within the NHibernate Mapping ideally, so I'm still confused as to why it doesn't appear to be taking any notice of my NHibernate cascade setting?
My guess would be that the problem comes from the fact that the many-to-one in the Comment mapping is set to not-null="true".
Because of that, NHibernate is not allowed to set this property to null temporarily before it deletes the Photo object and therefore when is goes about deleting the Photo object SQL Server throws an foreign key exception.
If I remember correctly for the order of actions when deleting is:
Set foreign key value to null in all child objects
Delete parent object
Delete all child references
Try to remove the not-null="true" from the many-to-one and see what will happen.
Try with inverse="true" on the bag collection of your mapping.
I had similar problem for 1 day .. and got frustrated over it.
Finally the solution boiled down to the DB.
I had to change the FK key constraints in "INSERT UPDATE SPECIFICATION"
'Delete Rule' : from 'No Action' to 'Cascade'
additionally you can also set
'Update Rule' : from 'No Action' to 'Cascade'
You can specify the delete-cascade option in NH:
<bag name="Comments" cascade="all-delete-orphan" order-by="DateTimePosted desc" where="Approved=1">
<key column="PhotoId" on-delete="cascade"/>
<one-to-many class="Comment" />
</bag>
You probably should make it inverse. Then I wonder where your FK_Comments_Photos column is specified.

Resources