تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
2684 أدوات العرض

Hello,

When I customize my module, I need to override "SettingsBlock" properties (props). More details, the original code is:

===

SettingsBlock.props = {

    title: { type: String, optional: 1 },

    tip: { type: String, optional: 1 },

    slots: Object,

    class: { type: String, optional: 1 },

};

===

in (web/static/src/webclient/settings_form_view/settings/settings_block.js).

I just want to modify "slots" value (just it). There 2 potential solutions (I think):


1. Create new js in my module and then override entirely SettingsBlock.props, looks like that:

===

SettingsBlock.props = {
...SettingsBlock.props,
slots: { type: Object, optional: 1 },
}

===


2. Use "patch" to avoid all impacts to code base (recommended). However, I don't know how to use. 


Please help. Many thanks.




الصورة الرمزية
إهمال
أفضل إجابة

The slots like that has it own purpose, i'm guessing you have messed with res.config.setting inheritance and you need to that. Trust me, i have encountered with this when my team somehow mess up with xml of res.config.setting inherit, some of them try to invisible wrong element so it caused error something like "slots bla bla"

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

We can use the patching method to override a function without changing the source code.For example, use the below code as a reference:

/** @odoo-module **/

import { SettingsBlock } from "@web/webclient/settings/settings_block";

import { patch } from "@web/core/utils/patch";


patch(SettingsBlock.prototype, {    async setup() {

        super.setup(); // By using the super function, we can execute all parent functions along with ours.

    },    settings_block(value){        // you can write your logic here    }

});


Hope it helps.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 24
1461
1
مايو 24
1960
1
أغسطس 23
2839
2
نوفمبر 24
2307
2
يوليو 25
447