This question has been flagged
1 Reply
5257 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>
Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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