跳至内容
菜单
此问题已终结

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?

形象
丢弃
最佳答案


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

            },

        });

    };

形象
丢弃
最佳答案

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.


形象
丢弃
最佳答案

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

        """


形象
丢弃
相关帖文 回复 查看 活动
1
7月 16
11189
1
12月 24
4429
1
10月 20
4674
2
6月 20
4397
5
12月 17
5746