Ir al contenido
Menú
Se marcó esta pregunta

I needed to write a method that exports some records programmatically, I checked and found the function that do the export is the javascript function : on_click_export_data found in the addons\web\static\src\js\data_export.js file. How to call such function from Odoo?

Avatar
Descartar
Mejor respuesta


Hello,

I hope this will help you. In your js file do like this :

    openerp.module_name = function(instance) {

            var QWeb = openerp.web.qweb;

            _t = instance.web._t;

        instance.web.DataExport.include({

            on_click_export_data: function() {

                var self = this;

                console.log('Put Your Code Here .. .. ');    

                return self._super();

            },

        });

    };

Avatar
Descartar
Mejor respuesta

Hi Tarek

The real export is done in a web controller at the url "/web/export/" followed by the specific export format. The formats available with their urls are:

openerp.addons.web.controllers.main.CSVExport used with the url "/web/export/csv"

openerp.addons.web.controllers.main.ExcelExport used with the url "/web/export/xls"

Depending of the format you need you could call the methods index or base on the corresponding class and passing the necessary arguments or finding and recreating the code for exporting the data to a file by yourself.


Avatar
Descartar
Mejor respuesta

Hi, 

The export is done by odoo, why call a javascript function from odoo, if the javascript function call an odoo method. if you need export your data see the method export_data in openerp.models

    @api.multi

    def export_data(self, fields_to_export, raw_data=False):

        """ Export fields for selected objects


            :param fields_to_export: list of fields

            :param raw_data: True to return value in native Python type

            :rtype: dictionary with a *datas* matrix


            This method is used when exporting data via client menu

        """


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 16
11176
1
dic 24
4414
1
oct 20
4640
2
jun 20
4383
5
dic 17
5725