Skip to Content
Menu
This question has been flagged
6 Replies
20595 Views

Hello!

I want to enable some features ​​in the res.config.settings model through a .xml file, but apparently, something is missing because after upgrading my custom module, the group_multi_company and group_use_lead fields remain unchecked. This is my sample code:

file: res_config_data.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="my_config_settings" model="res.config.settings">
        <field name="paperformat_id" ref="base.paperformat_us"/>
        <field name="snailmail_duplex" eval="True"/>
        <field name="group_multi_company" eval="True"/>
        <field name="group_use_lead" eval="True"/>
    </record>
</odoo>

file: __manifest__.py
...
'data': [ 'data/res_config_data.xml',
],
...

Any suggestion? Thanks in advance.

Avatar
Discard
Best Answer

res.config.setting is actually a TransientModel (wizard) which does not store the data for long time. Normally this object set / get the value to or from Company / ir.config.parameter

If you want to set these values, check where these fields are getting the value (company or ir.config.parameter) and then create your data xml accordingly.

Avatar
Discard
Best Answer

To save the data in res.config.settings you have to use get_values/set_values methods,

field_name = fields.Selection([

        ('field1', 'FIELD1  '),

        ('field2', 'FIELD2')],required=True, default='field1')


@api.multi

def set_values(self):

        super(ResConfigSettings, self).set_values()

        select_type = self.env['ir.config_parameter'].sudo()

        select_type.set_param('module_name.field_name', self.field_name)


    @api.model

    def get_values(self):

        res = super(ResConfigSettings, self).get_values()

        select_type = self.env['ir.config_parameter'].sudo()

        sell = select_type.get_param('module_name.field_name')

        res.update({ 'field_name' : sell})

return res

Avatar
Discard
Author Best Answer

Hello! Just for the record, I solved this as follows:

file: res_config_data.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="my_config_settings" model="res.config.settings">
<field name="group_multi_company" eval="True"/>
<field name="company_share_partner" eval="False"/>
<field name="group_use_lead" eval="True"/>
...
</record>
<function model="res.config.settings" name="execute">
<value model="res.config.settings"
search="[('id', '=', ref('my_config_settings'))]"/>
</function>
</odoo>

file: __manifest__.py
...
'data': [
'data/res_config_data.xml',
],
...
Avatar
Discard

Great!!!

You save the "Christmas" :o)

Great solution Alexander :)

In case you found the solution proposed by Alexander is working fine on the first installable but not when you try to update any settings later on.

You are probably missed to list related dependencies in __manifest__.py

See https://stackoverflow.com/questions/62316562/how-odoo-store-res-config-settings-it-looks-it-saved-but-not-presented-in-re/62317099#62317099

Best Answer

Alexander,

I've tried to do your example to check the "group_uom" but I receive the error: "odoo.tools.convert.ParseError: "null value in column "company_id" violates not-null constraint"

I have 2 companies. Where can I set the company_id?



Avatar
Discard

```

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

<odoo>

<record id="my_config_settings" model="res.config.settings">

<!-- Here -->

<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="hbx_chart_of_account.hbx_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>

```

Related Posts Replies Views Activity
4
Apr 23
5760
3
Jan 19
12365
2
Oct 17
10133
1
Apr 15
5610
0
Jun 15
3956