This question has been flagged
1 Reply
5764 Views

Hello everyone,

I am working with Odoo v12 and having some problems on understanding "external IDs".
As per my understanding, an external ID is created on 2 situations:

1- When we create a record (by installing a module, adding data to tables, etc.), Odoo takes care of it automatically. In this case the external ID name is provided by Odoo itself;
 2- On a custom module by "forcing" the external ID name using the "<record id...>"

So, based on that, I have created the following external id for my account data for a localization module:

      <record id="ao_1161" model="account.account.template">
           <field name="code">11.6.1</field>
           <field name="reconcile" eval="False"/>
           <field name="name">Taras e vasilhame</field>
           <field name="user_type_id" ref="account.data_account_type_current_assets"/>
           <field name="chart_template_id" ref="ao_chart_template"/>
      </record>

So, if I correctly understood the external ID functionality, when my module is installed, this record for this specific account will have the following external ID:

          module_name.ao_1161

The problem is that when I install my module, I can see that the external ID for this record is:

          module_name.1_ao_1161

This is raising a problem because all modules I use that depends on this specific record are failing to install because they refer to "module_name.ao_1161" and it does not exist on the database...

Note: This is only happening with the accounts from my chart of accounts. Other external IDs are kept as defined on xml, for instance:

      <record id="money_sale_journal" model="account.journal">
            <field name="name">Sale Money Sales</field>
            <field name="code">VDC</field>
            <field name="type">sale</field>
            <field name="sequence_number_next">1</field>
            <field name="sequence_id" ref="sequence_customer_moneysale"/>
            <field name="default_debit_account_id" ref="l10n_ao_account.ao_6111"/>
            <field name="default_credit_account_id" ref="l10n_ao_account.ao_6111"/>
      </record>

The external ID for the above record is kept as: module_name.money_sale_journal

Can anyone help me correctly understand how can I keep the original external ID defined on the custom module for the chart of accounts records or other information saved on the "data" folder?

I think is something related with the xml file base location.

The chart of accounts data is on "data" folder under my module structure.
The other xml files (the ones that external ids are preserved) are on "views" folder under my module structure.

So, how can I make the desired records located on "data" to keep the original "external ids"?

Thank you everyone for helping me

Best regards

Paulo

Avatar
Discard
Best Answer

Hi Paulo: 

The external id, if specified, is retained "as is" by Odoo i.e. when you install the module, the id will be set to "<module>.<record id specified by you>". It does not matter where the file is located. The issue you are facing with the chart of accounts theoretically should not happen. You may want to double check to make sure this is not happening because of a typo.

Also, try specifying the complete name (including the module id) in the record id. This is not a best practice but is an alternate way of specifying the id. For example,

      <record id="module_name.ao_1161" model="account.account.template">

<field name="code">11.6.1</field>
<field name="reconcile" eval="False"/>
<field name="name">Taras e vasilhame</field>
<field name="user_type_id" ref="account.data_account_type_current_assets"/>
<field name="chart_template_id" ref="ao_chart_template"/>
    </record>
Avatar
Discard
Author

Hi @Paresh,

Tank you very much.

You're right when you say this is not a normal behaviour.

I have doubble checked and all my account are acting like that.

After making some tests, I have found something which seems to be strange to me.

My chart data definition refers to the "account.account.template"

Here, my account data is set as:

<record id="ao_1111" model="account.account.template">.

Note: Tested with "l10n_ao_account.ao_1111" and see no changes on external IDs.

After installing the module, I look for the external IDs (just for the last part) and I see that the accounts are set on both "account.account.template" and "account.account" modules.

Is this correct?

I think "account.account.template" is just a template to be used for future reference, for instance on multicompany environments where Odoo gets the chart data from this model.

The "account.account" module, contains the chart data actually installed for the actual company...

So, my actual working chart of accounts is on "account.account" and this is where the problem is, because on the "account.account", the external ID is changed to "l10n_ao_account.1_ao_1111" and this is where problem resides.

On the "account.account.template", the external ID is kept as "l10n_ao_account.ao_1111" which is correct.

My problem is I want to set default values for a new journal on the "default_debit_account_id" field which is has a relation with "account.account" model.

Even thinking that I have this problem, when I install my module "exactly" from the "module name" (from my localization module with no modules installed), everything runs fine because Odoo will install all required dependencies.

If I try to instal this module on a database with existing modules, for instance "account" module, it fails to install because the external id... "1_ao_1111" is not found.

Thank you

Paulo

Hi Paulo: There seem to be 3 pieces to the puzzle here. Chart Template (account.chart.template), Account Template (account.account.template) and Chart of Accounts (account.account). The 1st two define the core structure of the localization template. The 3rd seems to be a copy that gets created for each company that uses the template. It seems like the "1" in the id of the account.account records you are seeing is referring to the internal (database) id of the main company (res.company).

You may find it beneficial to study how the generic coa localization has been defined in the system. Here's a link to the l10n_generic_coa module.

https://github.com/odoo/odoo/tree/12.0/addons/l10n_generic_coa

Hope this helps.

This link in the same module may also help since it is an example of creating demo data.

https://github.com/odoo/odoo/blob/12.0/addons/l10n_generic_coa/data/account_invoice_demo.xml

This may provide a clue that answers the question you have about how to set the default_debit_account_id.

https://github.com/odoo/odoo/blob/12.0/addons/account/test/account_minimal_test.xml#L223

Author

@Paresh,

You're great my friend.

I will look at every single peace of code here and will update you about what I am missing here.

Thank you once again

Best regards and have great weekend

Paulo