How to use "if condition" in RML-Odoo v8 - odoo-8

I want to use condition to print certain terms and conditions according to value set.
For example, there are 10 "Terms and Conditions" for payment. The default rate is "rate1" but if "rate2" is choosen, conditions no 3 and 4 should be change to something else.
If "rate1" is set then,
1. This is condition for both (1 or 2)
2. This is condition for both (1 or 2)
3. This is condition for rate 1
4. This is condition for rate 1
.
.
.
9. This is condition for both (1 or 2)
10. This is condition for both (1 or 2)
If "rate2" is set then,
1. This is condition for both (1 or 2)
2. This is condition for both (1 or 2)
3. This is condition for rate 2
4. This is condition for rate 2
.
.
.
9. This is condition for both (1 or 2)
10. This is condition for both (1 or 2)
Terms and conditions are "static", not stored in object.
My RML is like this:
<tr>
<td><para>1</para></td>
<td><para>This is condition for both (1 or 2)</para></td>
</tr>
<tr>
<td><para>2</para></td>
<td><para>This is condition for both (1 or 2)</para></td>
</tr>
<tr>
<td><para>3</para></td>
<td><para>This is condition for rate 1</para></td>
</tr>
Is there any way that I can use "condition" in line 3.
Thank you in advance.

I am not sure if it has exactly "if else conditions" in RML.
But in my case, I managed to solve as follows, and may be helpful for somebody like me.
[[ r.rate2 != '']]
[['3. Condition for Rate 2 '']]
[[ r.rate1 != '']]
[['3. Condition for Rate 1 '']]
OR
[[(r.rate1 == 0 and ' ') or '3. Condition for Rate 1']]
[[(r.rate2 == 0 and ' ') or '3. Condition for Rate 2']]
It doesn't seems a good way, but fixed the problem.
If found a better way, will always be appreciated.

Related

How to iterate For loop until certain condition meets?

I need to iterate for loop till certain condition meets in Robot Framework.
${counter}= Set Variable 1
:FOR ${item} IN RANGE ${counter}
\ Check condition
\ ${counter} = ${counter} + 1
Is it possible to increase the ${counter} variable value here?
Yes.
${counter}= Set Variable 1
FOR ${item} IN RANGE 1 20
${counter}= Evaluate ${counter} + 1
Log To Console ${counter}
Exit For Loop If ${counter} == 10
END
And FOR loops can be exited using Exit For Loop or Exit For Loop If keywords. Keywords documentation.
EDIT after comments.
You're asking about a while loop. Robot doesn't have a while loop. There's simply no support for it, and robot probably won't support it until at least 2021. The only looping construct is a for loop.
You seem to have an aversion to setting a limit of 20, but there must be a practical limit to the number of iterations, whether it's 1,000, 10,000, or 1 million or more. Just use a FOR loop that has a huge upper limit, and for all intents and purposes you've created a while loop.
FOR ${item} IN RANGE 1000000
Exit FOR loop if <some condition>
${counter}= evaluate $counter + 1
END
While it doesn't look quite as pretty as While <some condition>, the end result will be the same, assuming your condition becomes true at some point before one million iterations.

In a series of IF - ELSE IF statements, only the first IF works

I am trying to create a New variable "X", from Variables "A" "B" and "C".
This is the code that I am using.
I only get the first option "VAS_USAGE=1", the other options are lost.
What I wanted was for VAS_USAGE to have 1 to 6 values.
What am I doing wrong?
```
compute VAS_USAGE=0.
DO IF ((VAS1=1) AND (VAS2=1) AND (VAS3=1)).
COMPUTE VAS_USAGE=1.
ELSE IF ((VAS1=1) AND (VAS2=1) AND (VAS3=0)).
COMPUTE VAS_USAGE=2.
ELSE IF ((VAS1=1) AND (VAS2=0) AND (VAS3=1)).
COMPUTE VAS_USAGE=3.
ELSE IF ((VAS1=1) AND (VAS2=0) AND (VAS3=0)).
COMPUTE VAS_USAGE=4.
ELSE IF ((VAS1=0) AND (VAS2=0) AND (VAS3=1)).
COMPUTE VAS_USAGE=5.
ELSE IF ((VAS1=0) AND (VAS2=0) AND (VAS3=0)).
COMPUTE VAS_USAGE=6.
END IF.
EXECUTE.```
This is how the nested table looks like. This is what I was expecting to get.
This is what I got.
1.00 = 63
As suggested by #user45392 I would check if the answers 'yes' and 'no' are indeed coded as 1 and 0.
In any case I would suggest avoiding the complex 'do if' scheme which might be prone to errors and harder to debug. For example, you could create VAS_USAGE like this:
compute VAS_USAGE = 100*VAS1 + 10*VAS2 + VAS3.
Or if you want to stick to the specific values you gave in your post, add this:
recode VAS_USAGE (111=1)(110=2)(101=3)(100=4)(1=5)(0=6).
Also if you just want a simple index from 1 to 8 you can do this:
compute VAS_USAGE = 4*VAS1 + 2*VAS2 + VAS3 + 1.

Variable recording event incrementally (no loops)

I have this kind of structure (ID and Event) :
ID Event X
A 0 0
A 0 0
A 1 1
A 0 1
B 0 0
B 1 1
B 0 1
B 1 2
B 0 2
B 0 2
B 1 3
And I would like to create X, but I can't use any loops as the data base is huge. I would appreciate any suggestion.
Edit: I tried some kinds of bysort ID and Event without luck: now I'm working with this approach:
gen Spell=Event
replace Spell=2 if Spell[_n-1]==1 & Spell[_n+1]==0 & ID[_n]==ID[_n-1]
but it's not going to work since I can't discriminate between the second or the third + event showing on the data base.
Solved
gen X=Event[_n]
replace X=X[_n]+X[_n-1] if _n>1 & ID[_n]==ID[_n-1]
Datasets like this need a time or other sequence variable. You should certainly create one if you don't have one:
sort ID, stable
by ID : gen t = _n
What you want is then just
bysort ID (t) : gen wanted = sum(event)
which is cleaner and clearer than what you have. In Stata
help sum()
search by
search spell
to see relevant help files and expository articles.
(You are aware of this approach, but as you don't show precisely what you tried, so we can't comment on what was wrong.)

Drop all obs of group if condition is met

suppose I have the following panel data (didn't include time var for simplicity)
clear
input id var
1 .
1 0
1 0
1 .
2 .
2 .
2 .
2 .
3 1
3 .
3 .
3 0
end
I would like to delete all groups that have all missing data in their group, that is, I want my data to be like:
id var
1 .
1 0
1 0
1 .
3 1
3 .
3 .
3 0
I tried doing a gen todrop = var[_N], but for some reason, for some groups it doesn't work. Any thoughts? I thought about sorting id var, then doing a cascade replace, but I'm sure there is a better way to do this.
In general, you can verify whether all observations hold the same value by checking first and last observations in each panel, after appropriate sorting. The same principle applies here. I'll use the missing() function:
clear
set more off
input id myvar
1 .
1 0
1 0
1 .
2 .
2 .
2 .
2 .
3 1
3 .
3 .
3 0
end
bysort id (myvar) : gen todrop = missing(myvar[1]) & missing(myvar[_N])
list, sepby(id)
In this case, just checking the first one also works. If it's missing, all others are.
See help by.
Roberto has provided a solution which is however case specific and might lead to wrong outcome.
In fact, suppose you have an observation as follows:
id myvar
2 .
2 1
2 .
Using Roberto's code, you would remove this group, while in the question you need to remove only if all observations are missing.
Therefore I suggest you use a different approach, as follows:
levels id, local(groups) // creates unique values for id (no need to egen if you don't really have to)
foreach iter of local groups {
mdesc myvar if id == "`iter'" // use mdesc and put double quotes if id is a string
drop if id == "`iter'" & r(percent) == 100 // r(percent) is stored after mdesc
}
Roberto's code definitely works. Also does below code. The only contribution is that the original order (sort) of observations is kept if you might want it.
egen todrop2 = min(missing(myvar)), by(id)

Case Statement in Simulink

I am just not able to figure out how to proceed:
I am trying to build a model:
It would have 4 Inputs ( Boolean i/p)
It would have 1 output (Signed: 8 bit)
It would perform the following:
Based on which input is 1, it would give a corresponding output reflecting the DataRate.
If I have to write in Matlab, I would write something like this :
if (portA==1)
PSDU_Data_Rate=1;
elseif(portB==1)
PSDU_Data_Rate=2;
elseif (portC==1)
PSDU_Data_Rate=5.5;
elseif(portD==1)
PSDU_Data_Rate=11;
end
I am attaching, the part of the model which I am developing for the same functionality:
Any idea on how to proceed or code correction or suggestion on how it can be improved would be really helpful.
Thanks
Since you have 4 distinct inputs instead of a single input carrying an enumerated value, use If - Else, instead of a Case statement. I'm adding screenshots of how this can be done. Note that the If block also lets you have an Else output if you want to select one of the data rates by default (if none of the inputs are non-zero).
If block settings:
Number of inputs: 4
If expression: u1 ~= 0
Elseif expressions: u2 ~=0, u3 ~= 0, u4 ~= 0
The model consists of an If block connected to a set of If Action Subsystem blocks. The outputs of the latter can be combined into a single signal using a Merge block.

Resources