Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to call JavaScript from python function?

Subscribe

Get notified when there's activity on this post

This question has been flagged
javascriptpythonodoo
14428 Views
Avatar
ameer ashraf

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?

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Call wizard view in js function
javascript python odoo
Avatar
Avatar
1
Dec 22
4442
TypeError: Cannot read property 'taxes_by_id' of undefined at DiscountButton.apply_discount
javascript python odoo
Avatar
0
Dec 20
50
Display header only on the first page and footer on the last page Qweb Odoo 14
javascript python xml odoo
Avatar
Avatar
Avatar
2
Aug 24
7908
How to set default values to fields in Odoo 14
javascript python xml odoo
Avatar
Avatar
1
Oct 22
25561
How to create a customized Invoice Report . Odoo 14 Solved
javascript python xml odoo
Avatar
Avatar
Avatar
2
Sep 21
14551
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now