Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to call JavaScript from python function?

By
ameer ashraf
on 12/18/15, 11:20 PM 682 views

I am trying to call JavaScript from python function.

Python class:

 def print_excel(self, cr, uid, ids, context=None):

return self.print_report(cr, uid, ids, context=context)

def print_report(self, cr, uid, ids, context=None):

if context is None:

context = {}

datas = {'ids': context.get('active_ids', [])}

res = self.read(cr, uid, ids, ['date_start', 'date_end', 'user_ids'], context=None)

res = res and res[0] or {}

datas['form'] = res

if res.get('id',False):

datas['ids']=[res['id']]

if context.get('xls_export'):

return {

'class':'oe_export_excel',

'type': 'text/javascript',

'src':'/export_excel/static/src/js/export_excel_print.js',

}

else:

return self.pool['report'].get_action(cr, uid, [], 'point_of_sale.report_detailsofsales', data=datas, context=None)

JavaScript file:

openerp.export_excel = function(instance, m) {

var _t = instance.web._t;

var QWeb = instance.web.qweb;

instance.web.ListView.include({

load_list: function () {

var self = this;

this._super.apply(this, arguments);

self.$pager.find("oe_export_excel").unbind('click').click(function(event){self.export_to_excel("excel")})

},

export_to_excel: function(export_type) {

var self = this

var export_type = export_type

view = this.getParent()

// 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})

// }

});

});

//Find Data Element

data_eles = self.$el.find('.oe_list_content > tbody > tr')

export_data = []

$.each(data_eles,function(){

data = []

$data_ele = $(this)

is_analysis = false

if ($data_ele.text().trim()){

//Find group name

group_th_eles = $data_ele.find('th')

$.each(group_th_eles,function(){

$group_th_ele = $(this)

text = $group_th_ele.text().trim() || ""

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{

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() || ""

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})

}

});

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

});

}

},

});

};

When I run this module, the page stopped loading.

What am I doing wrong here?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/18/15, 11:20 PM
Seen: 682 times
Last updated: 12/18/15, 11:47 PM