Odoo Help

0

How to add Salary rule as data in Base salary structure

By
youta
on 4/30/16, 10:54 AM 1,158 views

Hello,

I need to add a new Salary rule in Base AS a data.xml file so it can compute the total allowances and deductions.

Here's my code:

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data noupdate="1">

<record id="ALLOWANCES" model="hr.salary.rule.category">

<field name="name">Allowances</field>

<field name="code">ALLOWANCES</field>

</record>

<record id="DEDUCTIONS" model="hr.salary.rule.category">

<field name="name">Deductions</field>

<field name="code">DEDUCTIONS</field>

</record>

<record id="hr_rule_allowances" model="hr.salary.rule">

<field name="name">Allowances</field>

<field name="sequence" eval="99"/>

<field name="code">ALLOWANCES</field>

<field name="category_id" ref="hr_payroll.ALLOWANCES"/>

<field name="condition_select">none</field>

<field name="amount_select">code</field>

<field name="amount_python_compute">result = categories.ALW</field>

</record>

<record id="hr_rule_deductions" model="hr.salary.rule">

<field name="name">Deductions</field>

<field name="sequence" eval="199"/>

<field name="code">DEDUCTIONS</field>

<field name="category_id" ref="hr_payroll.DEDUCTIONS"/>

<field name="condition_select">none</field>

<field name="amount_select">code</field>

<field name="amount_python_compute">result = categories.DED</field>

</record>

<!-- Salary Structure -->

<record id="structure_base_extend" model="hr.payroll.structure">

<field name="inherit_id" ref="hr_payroll.structure_base"/>

<field eval="[(6, 0, [ref('hr_rule_allowances'), ref('hr_rule_deductions')])]" name="rule_ids"/>

</record>

</data>

</openerp>


but I get this error: 

ParseError: "External ID not found in the system: hr_payroll.ALLOWANCES" while parsing /home/youta/odoo-8/my_addons/hr_wps/wps_data.xml:15, near

<record id="hr_rule_allowances" model="hr.salary.rule">


and when I tried to erase this line 

<field name="category_id" ref="hr_payroll.ALLOWANCES"/>

I got another error that category_id cannot be NULL


Any help will be appreciated

Thanks

1

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
3133
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 5/1/16, 1:51 AM

Hello,

the ref works as :

module_name.record_id

So the ref="hr_payroll.ALLOWANCES" will not works because the hr_payroll module has no id with name ALLOWANCES

So you need to replace hr_payroll to your module name to be as:

<field name="category_id" ref="your_module_name.ALLOWANCES"/>

Update:

to override/modify already existing record you just need to make the record id as same as the targeting record.

E.g


<!-- Salary Structure -->

<record id="hr_payroll.structure_base" model="hr.payroll.structure">

<field name="code">BASE</field>

<field name="name">Base for new structures</field>

<field eval="[(6, 0, [ref('hr_rule_allowances'), ref('hr_rule_deductions')])]" name="rule_ids"/>

</record>

Hope this could helps

Ok it's worked.. thanks for the advice.. But now it created duplicated BASE salary rule with the new two rows instead of being added to the original BASE. how can I edit these line of codes to inherit the BASE structure instead of creating new one ` BASE Base for new structures `

youta
on 5/1/16, 5:49 AM
0
youta
On 5/1/16, 5:51 AM

Ok it worked.. thanks for the advice.. But now it created duplicated BASE salary rule with the new two rows instead of being added to the original BASE. how can I edit these line of codes to inherit the BASE structure instead of creating new one. Here's my code :

<!-- Salary Structure -->

<record id="structure_base_extend" model="hr.payroll.structure">

<field name="code">BASE</field>

<field name="name">Base for new structures</field>

<field name="inherit_id" ref="hr_payroll.structure_base"/>

<field eval="[(6, 0, [ref('hr_rule_allowances'), ref('hr_rule_deductions')])]" name="rule_ids"/>

</record>

I've updated my answer ....

Ahmed M.Elmubarak
on 5/1/16, 8:51 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 4/30/16, 10:54 AM
Seen: 1158 times
Last updated: 5/1/16, 5:51 AM