Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Python expression in xml data file

By
saad
on 4/2/13, 10:00 AM 2,428 views

I have created a specific salary rule which the amount computation is based on a complex python expression
My python expression is similar to:

result = (-200 if contract.wage >= 12000 
else -150 if ((contract.wage >= 9000) and (contract.wage <= 11999))
else -80 if ((contract.wage >= 6000) and (contract.wage <= 8999)) 
else -20 if  ((contract.wage >= 3000) and (contract.wage <= 5999))
else -0)

How can I put this salary rule in a xml data file knowing that '&gt;' and '&lt;' didn't work?

0
Turkesh Patel (tpa)
On 4/2/13, 11:30 AM
<record id="hr_rule_xyz" model="hr.salary.rule">
    <field name="name">xyz</field>
    <field name="sequence" eval="1"/>
    <field name="code">xyz</field>
    <field name="category_id" ref="hr_payroll.xyz"/>
    <field name="condition_select">none</field>
    <field name="amount_select">code</field>
    <field name="amount_python_compute">result = (-200 if contract.wage &gt;= 12000 else -150 if ((contract.wage &gt;= 9000) and (contract.wage &lt;= 11999)) else -80 if ((contract.wage &gt;= 6000) and (contract.wage &lt;= 8999)) else -20 if  ((contract.wage &gt;= 3000) and (contract.wage &lt;= 5999)) else -0)</field>
</record>

use >= for >=

Turkesh Patel (tpa)
on 4/2/13, 11:31 AM

Thank you friends. I used the '<' sign and it get a syntax error as it' interpreted as a tag start. I didn't think to reverse conditional expressions to use '>'.

saad
on 4/2/13, 12:55 PM

oh yes lt and gt u can use it works..i have been used lt and gt in my answe but it shows < and >

Turkesh Patel (tpa)
on 4/3/13, 2:42 AM
0
Turkesh Patel (tpa)
On 4/2/13, 11:22 AM
    <record id="hr_rule_xyz" model="hr.salary.rule">
        <field name="name">xyz</field>
        <field name="sequence" eval="1"/>
        <field name="code">xyz</field>
        <field name="category_id" ref="hr_payroll.xyz"/>
        <field name="condition_select">none</field>
        <field name="amount_select">code</field>
        <field name="amount_python_compute">result = (-200 if contract.wage >= 12000 else -150 if ((contract.wage >= 9000) and (contract.wage <= 11999)) else -80 if ((contract.wage >= 6000) and (contract.wage <= 8999)) else -20 if  ((contract.wage >= 3000) and (contract.wage <= 5999)) else -0)</field>
    </record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/2/13, 10:00 AM
Seen: 2428 times
Last updated: 3/16/15, 8:10 AM