OpenERP - web_printscreen_zb - 不要正确导出布尔字段

时间:2015-04-09 11:56:31

标签: python boolean openerp export-to-excel add-on

我有一个树视图,可以使用addon web_printscreen_zb导出到Excel。问题是有两个布尔字段(或复选框),当导出在返回时显示为空(没有任何值),即使它们被选中。

我分析了插件web_printscreen_zb中的代码,看看发生了什么,看来它收到的数据带来了这个问题。

其他人有这个问题吗? OpenERP的代码部分可能是什么问题?

提前谢谢你,

Pablo Carballo。

1 个答案:

答案 0 :(得分:0)

问题解决了!!在web_printscreen_zb插件中,在文件:/web_printscreen_zb/static/src/js/web_printscreen_export.js中," export_to_excel"函数,我添加了一个if,检查输入是否是一个复选框,并且,根据是否检查我命令推送" 0"或者" 1"进入要写入excel的数据。

以下是我的web_printscreen_zb / static / src / js / web_printscreen_export.js更新代码:

openerp.web_printscreen_zb = function(instance, m) {

var _t = instance.web._t,
QWeb = instance.web.qweb;

instance.web.ListView.include({
    load_list: function () {
        var self = this;
        this._super.apply(this, arguments);
        var links = document.getElementsByClassName("oe_list_button_import_excel");
        var links_pdf = document.getElementsByClassName("oe_list_button_import_pdf");
        if (links && links[0]){
            links[0].onclick = function() {
                self.export_to_excel("excel")
            };
        }
        if (links_pdf && links_pdf[0]){
            links_pdf[0].onclick = function() {
                self.export_to_excel("pdf")
            };
        }
    },
    export_to_excel: function(export_type) {
        var self = this
        var export_type = export_type
        view = this.getParent()
        console.info("self");
        console.info(self);
        console.info(self.$el);
        // Find Header Element
        header_eles = self.$el.find('.oe_list_header_columns')
        header_name_list = []
        $.each(header_eles,function(){
            $header_ele = $(this)
            header_td_elements = $header_ele.find('th')
            $.each(header_td_elements,function(){
                $header_td = $(this)
                text = $header_td.text().trim() || ""
                data_id = $header_td.attr('data-id')
                if (text && !data_id){
                    data_id = 'group_name'
                }
                header_name_list.push({'header_name': text.trim(), 'header_data_id': data_id})
               // }
            });
        });
        console.info("HOLAAAA");
        //Find Data Element
        var noneObject = false
        data_eles = self.$el.find('.oe_list_content > tbody > tr')
        export_data = []
        checked = data_eles.find('th input[type=checkbox]').attr("checked");
        if (checked !== "checked"){
            noneObject = true
        }
        $.each(data_eles,function(){
            data = []
            $data_ele = $(this)
            is_analysis = false
            checked2 = $data_ele.find('th input[type=checkbox]').attr("checked");
            class_aux = $data_ele.find('th').attr("class");

            //console.info("DATA ELEMENT: " + $data_ele.text());
            //console.info("DATA ELE TRIM: " + $data_ele.text().trim());
            if ($data_ele.text().trim() && ((checked2 === "checked") || (noneObject == true) || class_aux === "oe_list_group_name")){
            //Find group name
                group_th_eles = $data_ele.find('th')
                $.each(group_th_eles,function(){
                    $group_th_ele = $(this)
                    text = $group_th_ele.text()
                    is_analysis = true
                    data.push({'data': text, 'bold': true})
                });
                data_td_eles = $data_ele.find('td')
                $.each(data_td_eles,function(){
                    $data_td_ele = $(this)
                    text = $data_td_ele.text().trim() || ""
                    if ($data_td_ele && $data_td_ele[0].classList.contains('oe_number') && !$data_td_ele[0].classList.contains('oe_list_field_float_time')){
                        text = text.replace('%', '')
                        text = instance.web.parse_value(text, { type:"float" })
                        data.push({'data': text || "", 'number': true})
                    }
                    else if ($data_td_ele && $data_td_ele[0].classList.contains('oe_list_field_boolean')){
                        if($data_td_ele.find('input[type=checkbox]').attr("checked")){
                            data.push({'data': 1})

                        }
                        else{
                            data.push({'data': 0})
                        }
                    }
                    else{
                        data.push({'data': text})
                    }
                });
                export_data.push(data)
            }
        });


        //Find Footer Element
        footer_eles = self.$el.find('.oe_list_content > tfoot> tr')
        $.each(footer_eles,function(){
            data = []
            $footer_ele = $(this)
            footer_td_eles = $footer_ele.find('td')
            $.each(footer_td_eles,function(){
                $footer_td_ele = $(this)
                text = $footer_td_ele.text().trim() || ""
                /* COMENTADO MVARELA    */
                try {
                    if ($footer_td_ele && $footer_td_ele[0].classList.contains('oe_number')){
                        text = instance.web.parse_value(text, { type:"float" })
                        data.push({'data': text || "", 'bold': true, 'number': true})
                    }
                    else{
                        data.push({'data': text, 'bold': true})
                    }
                }
                catch (err){
                    data.push({'data': text, 'bold': true})
                }
                /* FIN COMENTADO MVARELA */

            });
            export_data.push(data)
        });

        //Export to excel
        $.blockUI();
        if (export_type === 'excel'){
             view.session.get_file({
                 url: '/web/export/zb_excel_export',
                 data: {data: JSON.stringify({
                        model : view.model,
                        headers : header_name_list,
                        rows : export_data,
                 })},
                 complete: $.unblockUI
             });
         }
         else{
            console.log(view)
            new instance.web.Model("res.users").get_func("read")(this.session.uid, ["company_id"]).then(function(res) {
                new instance.web.Model("res.company").get_func("read")(res['company_id'][0], ["name"]).then(function(result) {
                    view.session.get_file({
                         url: '/web/export/zb_pdf_export',
                         data: {data: JSON.stringify({
                                uid: view.session.uid,
                                model : view.model,
                                headers : header_name_list,
                                rows : export_data,
                                company_name: result['name']
                         })},
                         complete: $.unblockUI
                     });
                });
            });
         }
    },
});
};

谢谢,

Pablo Carballo。