tom10271
tom10271

Reputation: 4657

How Odoo store `res.config.settings`? It looks it saved but not presented in `res.config.settings` and `ir.config_parameter`

https://www.odoo.com/forum/help-1/question/12-0-enable-features-in-the-res-config-settings-149566

I have created my setting data file as the followings mentioned by Alexander inside the page above:

res_config_data.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="my_config_settings" model="res.config.settings">
        <field name="company_id" ref="base.main_company"/>
        <field name="group_multi_currency" eval="True"/>
        <field name="group_product_variant" eval="True"/>
        <field name="group_stock_multi_warehouses" eval="True"/>
        <field name="group_stock_multi_locations" eval="True"/>
        <!-- Delivery Packages -->
        <field name="group_stock_tracking_lot" eval="True" />
        <field name="module_stock_picking_batch" eval="True" />
        <!-- Display Lots & Serial Numbers: Lots & Serial numbers will appear on the delivery slip -->
        <field name="group_lot_on_delivery_slip" eval="True" />
        <!-- Multi-Step Routes: Use your own routes and putaway strategies -->
        <field name="group_stock_adv_location" eval="True" />
        <field name="po_order_approval" eval="True" />
        <!-- Quantities billed by vendors -->
        <field name="default_purchase_method">purchase</field>
        <field name="multi_sales_price" eval="True" />
        <!-- Multiple prices per product -->
        <field name="multi_sales_price_method">percentage</field>
        <field name="group_analytic_tags" eval="True" />
        <field name="group_analytic_accounting" eval="True" />
        <!-- Set specific billing and shipping addresses -->
        <field name="group_sale_delivery_address" eval="True" />
        <!-- Consignment -->
        <field name="group_stock_tracking_owner" eval="True" />
        <!-- Prepayment -->
        <field name="prepayment_account_id" ref="my_chart_of_account.my_account_prepayments" />
        <!-- Multi-company-->
        <field name="group_multi_company" eval="False" />
    </record>
    <function model="res.config.settings" name="execute">
        <value model="res.config.settings"
               search="[('id', '=', ref('my_config_settings'))]"/>
    </function>
</odoo>

__manifest__.py

    'data': [
        'data/res_config_data.xml',
     ],

It works if I apply it once only. But when I try to reinstall this setting module, it will not work.


It somehow fails to recognize what fields are the supported.

2020-06-11 02:26:48,117 52288 WARNING odoo_dev odoo.models: res.config.settings.create() with unknown fields: company_id, default_purchase_method, group_analytic_accounting, group_analytic_tags, group_lot_on_delivery_slip, group_multi_company, group_multi_currency, group_product_variant, group_sale_delivery_address, group_stock_adv_location, group_stock_multi_locations, group_stock_multi_warehouses, group_stock_tracking_lot, group_stock_tracking_owner, module_stock_picking_batch, multi_sales_price, multi_sales_price_method, po_order_approval, prepayment_account_id 

Odoo discarded these unrecognized fields and insert the plain object into DB

2020-06-11 02:26:48,118 52288 ERROR odoo_dev odoo.sql_db: bad query: b'INSERT INTO "res_config_settings" ("id", "create_uid", "create_date", "write_uid", "write_date") VALUES (nextval(\'res_config_settings_id_seq\'), 1, (now() at time zone \'UTC\'), 1, (now() at time zone \'UTC\')) RETURNING id'
ERROR: null value in column "company_id" violates not-null constraint
DETAIL:  Failing row contains (10, 1, 2020-06-11 02:26:47.302998, 1, 2020-06-11 02:26:47.302998, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).
psycopg2.IntegrityError: null value in column "company_id" violates not-null constraint
DETAIL:  Failing row contains (10, 1, 2020-06-11 02:26:47.302998, 1, 2020-06-11 02:26:47.302998, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).

When I installed this setting module with a brand new Odoo database, and I go to general setting page, I can see the settings are installed. But when I check res.config.settings and ir.config_parameter tables, I don't see any settings record stored. I want to understand how this setting data file being proceeded and stored in where.

Upvotes: 1

Views: 4639

Answers (1)

tom10271
tom10271

Reputation: 4657

Ok although I still have no idea how settings being saved by Odoo. I managed to fix the update setting error.

The reason why it states res.config.settings.create() with unknown fields is because I was trying to update setting that are belongs to different module. For example group_multi_company is under base_setup. However in my setting module I have not listed base_setup as the dependencies.

After putting all modules for those settings I was trying to set, I can update settings properly. Yes if you do not add these dependencies it is still installable but for the first time only, yet you won't be able to update data later on. So always list all related dependent modules.

# -*- coding: utf-8 -*-
{
    'name': "My Odoo Settings",
    'description': "My configuration for setup",
    'version': '12.0.2',
    'author': "Wow Ltd.",
    'website': "https://github.com/o.o/odoo-addons",
    'summary': "My configuration for setup",
    # Here, originally I have set with [] only. 
    # With these I can now update settings successfully
    'depends': ['base_setup', 'sale', 'account', 'purchase', 'stock', 'stock_account', 'sale_management'],
    'data': [
        'data/settings.xml',
    ],
    'installable': True,
}

Upvotes: 1

Related Questions