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.

0

How to define the parent_id of a new account.account entry if actual accounts don't have external ID?

By
Pascal Tremblay
on 2/1/16, 12:44 PM 633 views

Hello all,

In a custom module, I want to create a new account with this code :

<record id="rounding_account" model="account.account">
            <field name="name">Rounding account</field>
            <field name="code">5300</field>
            <field name="type">regular</field>
            <field name="user_type" ref="account.data_account_type_expense"/>
            <field name="reconcile" eval="False"/>
            <field name="parent_id" ref="????????"/>
 </record>


But none of my actual accounts have an external ID. Even if I define manually an external ID for the parent account that I want, the next to install the module will never have the same external ID...

If I want that this module be easy to install on any Odoo server, how to choose the right parent_id, for example account of code 111 in the accounting chart?


UPDATE #1

For the moment, with the answer of Cyrus Waithaka, I get this error : 

ParseError: "invalid syntax
('<string>', 1, 7, "[(code='111')]")" while parsing /home/odoo-test/addons_pt/canada_rounding/journal_account_lapagept.xml:11, near
<record id="rounding_account" model="account.account">
<field name="name">Rounding account</field>
<field name="code">53300</field>
<field name="type">Regular</field>
<field name="user_type" ref="account.data_account_type_expense"/>
<field name="reconcile" eval="False"/>
<field name="parent_id" search="[(code='111')]"/>
</record>
0
Cyrus Waithaka
On 2/1/16, 3:28 PM

Every record in odoo will have an external id attached to it. You can view this ID by exporting the records. A record that is added by a module using xml will have an external id equivalent to "module_name.value_of_record_tag_id". You will notice that manually created records will also have an external ID.

You can also use 'search' in the event that you want to reference another record by another field name rather than by external id. For example:

<field name="parent_id" search="[(code='111')]"/>

I hope this will help

very interesting trick. Will try it very soon... thanks a lot. I come back

Pascal Tremblay
on 2/1/16, 4:35 PM

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

1 follower(s)

Stats

Asked: 2/1/16, 12:44 PM
Seen: 633 times
Last updated: 2/1/16, 6:30 PM