Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
6 Odpovědi
22728 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit

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

Nejlepší odpověď

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
Zrušit

```

<?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 Odpovědi Zobrazení Aktivita
4
dub 23
6978
3
led 19
12365
2
říj 17
11578
1
dub 15
5610
0
čvn 15
4767