Search code examples
odooodoo-8odoo-9odoo-10

Is there any way to override standard many2many field pop up after clickin add an item?


When I click add an item on many2many field standard pop up appears with all the filters, group by's and so on. What I want to do is to leave that pop up as it is except change it's style a little bit. I tested it throo inspect element and all I have to do is to remove one class from div. Now I need to find a way to do that at code. Thanks for considering my question!!


Solution

  • here is what i change some style in One2many Pop up

    if you need just change some style, this will help you

    you just need to find classname

    Example classname of 'Create' Button in Many2Many is "oe_selectcreatepopup-search-create"

    create .js file in your module then include it like this

    <?xml version="1.0" encoding="utf-8"?>
    <!-- vim:fdn=3: -->
    <openerp>
        <data>
            <template id="assets_backend" name="nstda_bst assets" inherit_id="web.assets_backend">
                <xpath expr="." position="inside">
                    <link rel="stylesheet" href="/nstda_bst/static/css/nstda_bst.css"/>
                    <script type="text/javascript" src="/nstda_bst/static/js/nstda_bst.js"></script>
                </xpath>
            </template>
        </data>
    </openerp>
    

    Then copy 'oe_selectcreatepopup' js function in core/addons/web/static/scr/js/view_form.js

    to your new js in your module

    then change it.

    openerp.nstda_bst = function(instance) {
    
    var MODELS_TO_HIDE = [ 'nstda.bst', 'nstda.bst.hbill', 'nstda.bst.dbill' ];
    
    var QWeb = instance.web.qweb, _t = instance.web._t, _lt = instance.web._lt;
    var dateBefore = null;
    
    instance.web.form.AbstractFormPopup.include({
        template : "AbstractFormPopup.render",
    
        setup_form_view : function() {
            var self = this;
            var tmp = this._super.apply(this, arguments);
            var res_model = this.dataset.model;
    
            if ($.inArray(res_model, MODELS_TO_HIDE) != -1) {
                var  button_t = setInterval(function(){
    
                    $(".oe_abstractformpopup-form-close").addClass('oe_button oe_form_button_cancel oe_highlight .openerp button.oe_highlight button.oe_highlight:hover');
                    $(".oe_abstractformpopup-form-close").removeClass('oe_bold');
                    $(".oe_abstractformpopup-form-close").css('display', 'inline-block');
                    $(".oe_abstractformpopup-form-close").css('line-height', '1.7em;');
                    $(".oe_abstractformpopup-form-close").css('background-color', 'c02c2c');
                    $(".oe_abstractformpopup-form-close").css('background-image', '-webkit-gradient(linear, left top, left bottom, from(#df3f3f), to(#a21a1a))');
                    $(".oe_abstractformpopup-form-close").css('background-image', '-webkit-linear-gradient(top, #df3f3f, #a21a1a)');
                    $(".oe_abstractformpopup-form-close").css('background-image', '-moz-linear-gradient(top, #df3f3f, #a21a1a)');
                    $(".oe_abstractformpopup-form-close").css('background-image', '-ms-linear-gradient(top, #df3f3f, #a21a1a)');
                    $(".oe_abstractformpopup-form-close").css('background-image', '-o-linear-gradient(top, #df3f3f, #a21a1a)');
                    $(".oe_abstractformpopup-form-close").css('background-image', 'linear-gradient(to bottom, #df3f3f, #a21a1a)');
                    $(".oe_abstractformpopup-form-close").css('-moz-box-shadow', '0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 1px rgba(155, 155, 155, 0.4) inset');
                    $(".oe_abstractformpopup-form-close").css('-webkit-box-shadow', '0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 1px rgba(155, 155, 155, 0.4) inset');
                    $(".oe_abstractformpopup-form-close").css('box-shadow', '0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 1px rgba(155, 155, 155, 0.4) inset');
    
                }, 50);
    
            }
        }       
    });
    

    }