İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
10594 Görünümler

 I'm trying to add custom widget in odoo 10. The new widget is a custom <table> html tag. The color of each <td> depends on a field in my model.

I followed many examples in the internet but I can't get it work.

Please, anyone could help me by giving a basic example in odoo 10.

Avatar
Vazgeç
En İyi Yanıt

Hello,

  1. Create a javascript module like below for your custom field

  2. Create a qweb template for the custom field

  3. You can access all fields on the form like shown below.

  4. Then you can pass the value to the template
    Finally add the field to the form like <widget type="customwidget"/>




The Script


odoo.define('module.module_title', function (require) {

"use strict";


var core = require('web.core');

var common = require('web.form_common');

var CustomWidget = common.FormWidget.extend({

    template: 'CustomWidget',

     events: {

     

   

    },

   

    start: function() {

      var self=this;

// You can get the values of all fields on the form like this

      var field_value=self.field_manager.get_field_value('field_name');

self.color_class=field_value;

        this._super();

     

    },

  



    })

core.form_custom_registry.add('customwidget', CustomWidget);

return {

  CustomWidget:CustomWidget,




 

};

});


The Template


  <t t-name="CustomWidget">

       

            

<td t-att-style=""  t-att-class="widget.color_class">Some Thig</td>    

       

     

         

      

    </t>


To display the widget on the form view


<widget type="customwidget"/>



Thank You

Avatar
Vazgeç
En İyi Yanıt

Hello,

This module creates a new widget for adding map.You can refer it

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Haz 23
2938
0
Ara 17
5968
0
May 17
8580
0
Tem 24
1330
1
Tem 24
2076