beanio customhandler get value from different field - bean-io

I have one beanio xml file, the record example is like this:
<record name="dealsRecord" order="3" class="map">
<field name="RedemptionMode" required="true" maxLength="6"/>
<field name="ConversionRate" required="false" maxLength="10" typeHandler="ynHandler"/>
</record>
in the "ynHandler", I want to use "RedemptionMode" value, then I will do some logic with "RedemptionMode" and "ConversionRate".
Is anyone know how to write the handler to get value from "RedemptionMode"?
Thanks!

What you want is not possible. What you can do though is to write a type handler for the dealsRecord and from there decide how to format the entire string ( both the RedemptionMode and the ConversionRate)

Related

Odoo - Compute field working on local but not online

I have a custom field on the partner model that will get all signatures records (from the Sign app) concerning the current partner, here is my code :
# Signatures
x_signatures_relation = fields.One2many("signature.request.item", "partner_id")
x_signatures = fields.One2many("signature.request", compute="_get_signed_documents")
#api.multi
def _get_signed_documents(self):
for record in self:
record.x_signatures = [(6, 0, record.x_signatures_relation.ids)]
And this in the xml part :
<page string="Signatures" name="signatures">
<tree>
<field name="x_signatures" />
</tree>
</page>
The code works perfectly as expected on my local machine, but once I push It through Github to odoo.sh, I get this error when I visit a partner with one signature at least (doesn't happen with partners with no signatures) :
Error:
TypeError: val is undefined
https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264
Traceback:
_parseServerData/<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264:545
_.forEach#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:12:558
_parseServerData#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264:288
_readMissingFields/</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1275:445
_.forEach#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:12:558
_readMissingFields/<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1275:35
then/</</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:678
fire#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
Deferred/</deferred[tuple[0]]#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:803:56
rpc/</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:3869:346
then/</</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:678
fire#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
Deferred/</deferred[tuple[0]]#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:803:56
fire#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
then/</</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:874
fire#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
then/</</<#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:874
fire#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
done#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:1192:86
callback#https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:1212:15
If I remove the xml part, It displays the partner correctly, otherwise I wouldn't be able to find out where the problem is coming from since the stack trace is not really helping, any ideas ?
I think this is enough
<page string="Signatures" name="signatures">
<field name="x_signatures">
<tree>
<field name='your_filed_name'/>
<field name='your_filed_name_2'/>
</tree>
</field>
</page>
The answer of sfx should be enough, but i want to share more about your mistake.
<page string="Signatures" name="signatures">
<tree>
<field name="x_signatures" />
</tree>
</page>
(I guess) You're trying to tell Odoo to show the signatures as list view. That's not necessary, as the other answer already is telling you. But the real mistake here is using <tree> hierachical above the field, which should be shown as a list subview.
You have to use <tree> (or <kanban>) within a field you want to show as subview. And then it's not enough to just define an empty subview, but a subview with fields, labels, and so on:
<page string="Signatures" name="signatures">
<field name="x_signatures">
<tree>
<field name="field_1" />
<field name="field_2" />
<field name="field_n" />
</tree>
</field>
</page>
I solved It by editing the Python code as follow :
#api.depends('x_signatures_relation')
#api.multi
def _get_signed_documents(self):
for record in self:
ids = []
for signature in record.x_signatures_relation:
ids.append(signature.signature_request_id.id)
record.x_signatures = [(6, 0, ids)]
Still I have no idea why the first piece of code did not work on odoo.sh and worked perfectly on my local machine.

Count characters used in p:inputTextarea instead of characters remaining

I posted a similar question earlier but I'm looking for a different approach. I have a inputTextArea and I need to limit the amount of characters that can be entered in to it as well as display the amount of characters used (ex: "31/50 characters used"). Currently, I am just using attributes for the inputTextArea to do this, however, this way, I can only get a count for the characters remaining. Below is a picture of the inputTextArea as well as the code to do this.
Characters Remaining counter
<p:inputTextarea id="ogdGacOther" rows="1" style="vertical-align: top; width: 98% !important;" styleClass="preformatted" autoResize="false" value="#{rfeBean.rfe.targetOfficerReasonsForReferral.otherOgdGac}" disabled="#{!rfeBean.ogdGacReferralReasonsChecked[ReferralTemplateConstants.OGD_GAC_OTHER] or !raudUserSessionBean.raudUser.referMode or rfeBean.workItemMissing}"
counter="displayGacCharCount" maxlength="50" counterTemplate="{0} #{msg.rfeCharactersRemaining}">
<p:ajax event="change" process="#this" />
</p:inputTextarea>
<br/>
<h:outputText id="displayGacCharCount" />
I am wondering if there is way to modify this so that it displays characters used. The {0} in the counter template, is the number that represents the amount of char remaining. If anyone know a way I could call a java method using that {0}, I would be golden. Either way, let me know what you think the best approach. I am trying to avoid using any javascript of jQuery.
I tried something like this:
<h:outputText id="displayGacCharCount" value="#{rfeBean.methodToChangeCharRemainToCharUsed(valueForCharRemain({0})}" />
When I tried this, I got an error along the lines of "El Expression is unbalanced"
Liam,
It's very simple, forget the counter and get the string length:
<p:inputTextarea id="ogdGacOther" rows="1" maxlength="50"
value="#{rfeBean.rfe.targetOfficerReasonsForReferral.otherOgdGac}">
<p:ajax event="keyup" update="displayGacCharCount" global="false"/>
<p:ajax event="keydown" update="displayGacCharCount" global="false"/>
<p:ajax event="keypress" update="displayGacCharCount" global="false"/>
</p:inputTextarea>
<h:outputText id="displayGacCharCount"
value="#{rfeBean.rfe.targetOfficerReasonsForReferral.otherOgdGac.length()}"/>

make voiceXML to read the result returned by the server

I am new in voiceXML and I am wondering how to read a value return by the server after post. I want voiceXML to read the server's response. According to voiceXML documentation, I understand that the result should be in XML.
Here is my node.js/express.js code that receives the result:
app.post("/getData", function (req, res) {
console.log(JSON.stringify(req.body));
res.header('Content-Type','text/xml').send('<?xml version="1.0" ?> <vxml version="2.0"> <block> <prompt> The time in Milwaukee is 10 </prompt> </block> </vxml>');
});
Here is the screenshot showing that I am successfully receiving the posted content:
Here is the screenshot showing that I am successfully sending the XML result:
Here is my voiceXML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml xmlns="http://www.w3.org/2001/vxml" xmlns:bevocal="http://www.bevocal.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<form scope="dialog">
<field name="name" modal="false">
<grammar src="grammars.grammar#Names"/>
<prompt>Whats your name?</prompt>
<filled>
<prompt>Hello <value expr="name"/>
</prompt>
</filled>
</field>
<field name="city" modal="false">
<grammar src="grammars.grammar#Cities"/>
<prompt>What city are you from?</prompt>
<filled>
<prompt>You are from <value expr="city"/>
</prompt>
</filled>
</field>
<field name="country" modal="false">
<grammar src="grammars.grammar#Countries"/>
<prompt>What country are you from?</prompt>
<filled>
<prompt>You are from <value expr="country"/>
</prompt>
</filled>
</field>
<field name="cityTime">
<prompt>
What city would you like the time for?
</prompt>
<grammar type="application/x-nuance-gsl">
[denver (san francisco) ]
</grammar>
</field>
<field name="formatTime">
<prompt>
Twelve hour or twenty four hour clock?
</prompt>
<grammar type="application/x-nuance-gsl">
[[twelve (twenty four)] ?hour]
</grammar>
</field>
<block>
<submit next="http://65.29.170.122/getData" method="post" namelist="name city country cityTime formatTime" />
</block>
</form>
</vxml>
Two approaches are available:
First, after collecting your input submit the form and the response should be a new VoiceXML document that plays your data.
Second, if your browser supports it (most do), you can use the Data element to make a request from within the VoiceXML form. The response needs to be XML. VoiceXML provides a way to walk the resulting DOM to get your data.
As for speaking the data, most browsers support the say-as element of SSML within a prompt. For most professional applications, the typically approach is to build a javascript library to assemble and play a set of recordings to play the time.
add php code in a file, add xml script and echo the server response wherever you want. This way the final XML that the voice server gets actually has php code also but it does'nt matter as it will ignore the php only take the xml tags in between which you would have echoed the result. For eg:
<?php
$appointmentTime = $_REQUEST['appointment_time'];
?>
<Response>
<Play> <?php echo $appointmentTime ?> </Play>
</Response>

Can I read the maxOccurs property for a segment from the stream being processed?

I am trying to create a mapping file for a fixed length file that contains multiple repeating segments. Problem is, that more than one of these segments are repeated an indefinite number of times, which is not supported by beanio for flat files. I understand, that there is a good reason for this, as beanio can do only so much guesswork about how often a segment repeats.
However the number of repetitions for each segment is present in the file, at a position before the repeating segments occur, so I am trying to figure out whether there is a way to read that number from the stream and then populate the "minOccurs" and "maxOccurs" properties for the following segment with the correct value.
Basically my mapping file looks like:
<beanio>
<stream name="employeeFile" format="fixedlength">
<record name="record1" class="example.Record1">
<field name="field1" length="10"/>
<field name="field2" length="2"/>
<field name="length1" length="2"/>
<segment name="list1" collection="list" minOccurs="1" maxOccurs="unbounded" class="example.List1">
...
</segment>
<field name="length2" length="2"/>
<segment name="list2" collection="list" minOccurs="1" maxOccurs="unbounded" class="example.List2">
...
</segment>
</record>
</stream>
</beanio>
I now need some way to use the value of fields length1 and length2 as "maxOccurs" property in the segments. I am fairly certain that there is no "official" way to get this behavior, but I have so far failed to come up with an even remotely elegant solution for this.
An idea I had was to create a procedure that loads the number of repetitions for each segment from the file and then doing a search-replace on the mapping file, before loading this in beanio, however this seems like a very complicated way of doing things.
Thanks,
Sönke
Found the answer myself. I was reading the beanio reference documentation for version 2.0, not 2.1 which introduced the feature I am looking for.
The reference document states:
If a field repeats a fixed number of times based on a preceding field
in the same record, the occursRef attribute can be used to identify
the name of the controlling field. If the controlling field is not
bound to a separate property of its parent bean object, be sure to
specify ignore="true". The following mapping file shows how to
configure the accounts field occurrences to be dependent on the
numberOfAccounts field. If desired, minOccurs and maxOccurs may still
be specified to validate the referenced field occurrences value.
So one can use:
<field name="accounts" type="int" collection="list" occursRef="numberOfAccounts" />
to get the intended result.
I don't think this property works with xml streams, as it is not really needed here. I accidentally tried to add this in a mapping file and got an exception instead of a proper error message.

Thousands separators in Ext.form.NumberField

I want to override some config options of Ext.form.NumberField, but I don't find something like a "thousands separator". Is there a way to define this for NumberFields in Ext?
Or have I had to write my own function to provide this functionality?
On closer inspection according to the forums/devs, NumberField doesn't support formatting. Numbercolumn on a grid does.
Their suggestion is to use a TextField and either format the value serverside before displaying it, or to apply a function on say, the 'change' event of a text field to apply the formatting you want, e.g.
<ext:TextField
ID="txtField"
runat="server"
FieldLabel="My Label"
AllowBlank="false"
ReadOnly="true">
<Listeners>
<Change Handler="this.setValue(Ext.util.Format.number(newValue.replace(/[\,\.]/g, ''), '0.000/i'));" />
</Listeners>
</ext:TextField>
I would assume you'd need to tweak things a little to ensure your value was displayed as you'd like but there should be something you fit in the Ext.util.Format.number patterns listed here:
http://dev.sencha.com/deploy/ext-3.3.1/docs/output/Ext.util.Format.html#Ext.util.Format-number
you can also use this override
Ext.override.ThousandSeparatorNumberField

Resources