Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
6 Odpowiedzi
22855 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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',
],
...
Awatar
Odrzuć

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

Najlepsza odpowiedź

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?



Awatar
Odrzuć

```

<?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>

```

Powiązane posty Odpowiedzi Widoki Czynność
4
kwi 23
7058
3
sty 19
12365
2
paź 17
11638
1
kwi 15
5610
0
cze 15
4799