2016-01-05 7 views
9

मैं odoo के साथ काम करता हूं। प्रणाली में क्षेत्र के प्रत्येक प्रकार के लिए render_value विधि मौजूद है:ओडू 9. फॉर्म विजेट को ओवरराइड कैसे करें?

/odoo/addons/web/static/src/js/views/form_widgets.js 
/odoo/addons/web/static/src/js/views/form_relational_widgets.js 

मैं कैसे सभी रूपों के लिए (FieldChar में उदाहरण के लिए) render_value अपने कस्टम विधि का उपयोग कर सकते हैं? और मैं एक फॉर्म या एक मॉड्यूल के लिए विशिष्ट render_value का उपयोग कैसे कर सकता हूं?

मैंने अपने मॉड्यूल में form_widgets.js बनाया, लेकिन मुझे समझ में नहीं आया कि फ़ील्ड को कितनी अच्छी तरह से ओवरराइड किया गया है।

odoo.define('my_module.form_widgets', function (require) { 
"use strict"; 

// what I should do here??? 

}); 

क्या आप छोटे उदाहरण प्रदान कर सकते हैं? अग्रिम धन्यवाद।

उत्तर

17

मुझे समाधान मिला।

पहली चीज़ जो आपको करने की ज़रूरत है वह स्थिर सामने के लिए बना है। जे एस: qWeb के लिए

// path_to_your_module/static/src/js/form_widgets.js 
odoo.define('your_module.form_widgets', function (require) { 
    "use strict"; 

    var core = require('web.core'); 
    var form_common = require('web.form_common'); 
    var FieldChar = core.form_widget_registry.get('char'); 

    FieldChar.include({ 
     // this is will be work for all FieldChar in the system 
     template: 'MyChar', // my template for char fields 
     // we can create here any logic for render 
     //render_value: function() { 
     //} 
    }); 
    // this is widget for unique CharField 
    var MyModuleFieldChar = FieldChar.extend({ 
     template: 'MyUniqueChar' // my custom template for unique char field 
    }); 
    // register unique widget, because Odoo does not know anything about it 
    core.form_widget_registry.add('my_unique_char', MyModuleFieldChar); 

}); 

टेम्पलेट:

<?xml version="1.0" encoding="UTF-8"?> 
<templates xml:space="preserve"> 
<!-- path_to_your_module/static/src/xml/form_widgets.xml --> 
<t t-name="MyChar"> 
    <!-- for example I just added new <span> to all FieldChar --> 
    <span>my_val</span> 
    <!-- this is original content for CharField from path_to_odoo/addons/web/static/src/xml/base.xml --> 
    <span t-att-class="'oe_form_field '+widget.widget_class" t-att-style="widget.node.attrs.style"> 
     <t t-if="!widget.get('effective_readonly')"> 
      <input t-att-type="widget.password ? 'password' : 'text'" 
       t-att-barcode_events="widget.options.barcode_events" 
       t-att-id="widget.id_for_label" 
       t-att-tabindex="widget.node.attrs.tabindex" 
       t-att-autofocus="widget.node.attrs.autofocus" 
       t-att-placeholder="widget.node.attrs.placeholder" 
       t-att-maxlength="widget.field.size" 
      /><img class="oe_field_translate oe_input_icon" t-if="widget.field.translate" t-att-src='_s + "/web/static/src/img/icons/terp-translate.png"' width="16" height="16" border="0"/> 
     </t> 
     <t t-if="widget.get('effective_readonly')"> 
      <span class="oe_form_char_content"></span> 
     </t> 
    </span> 
</t> 
<!-- This is example template for my unique field --> 
<t t-name="MyUniqueChar"> 
    <span>unique_char</span> 
</t> 

</templates> 

दूसरा चरण - हमारे स्थिर फ़ाइलों में शामिल हैं।

जो संपत्ति जोड़ने हो जाएगा नया दृश्य बनाएं: OpenERP में

<?xml version="1.0" encoding="utf-8"?> 
<!-- path_to_your_module/views/assets.xml --> 
<openerp> 
    <data> 
     <template id="assets_backend" name="mail assets" inherit_id="web.assets_backend"> 
      <xpath expr="." position="inside"> 
       <script type="text/javascript" src="/your_module/static/src/js/form_widgets.js"></script> 
      </xpath> 
     </template> 
    </data> 
</openerp> 

अपने मॉड्यूल के .py अगले वर्गों जोड़ें:

'data': [ 
    'views/assets.xml', 
    # other files 
], 
'qweb': [ 
    'static/src/xml/*.xml', 
], 

के बाद यह काम हो जाएगा हमारे सिस्टम 0 में सभी CHAR फ़ील्ड के लिए फील्डर। हम सिर्फ इस तरह से हमारे के क्षेत्र के लिए विशेषता विजेट जोड़ने की जरूरत है हम my_unique_char उपयोग करने के लिए की जरूरत है:

<field name="name" widget="my_unique_char"/> 

मुझे आशा है कि यह किसी को मदद मिलेगी।

संबंधित मुद्दे