Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
23134 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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',
],
...
Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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?



Ảnh đại diện
Huỷ bỏ

```

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

```

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 4 23
7109
3
thg 1 19
12365
2
thg 10 17
11713
1
thg 4 15
5610
0
thg 6 15
4854