diff --git a/addons/google_spreadsheet/__init__.py b/addons/google_spreadsheet/__init__.py new file mode 100644 index 00000000000..f57aaed7749 --- /dev/null +++ b/addons/google_spreadsheet/__init__.py @@ -0,0 +1 @@ +import google_spreadsheet \ No newline at end of file diff --git a/addons/google_spreadsheet/__openerp__.py b/addons/google_spreadsheet/__openerp__.py new file mode 100644 index 00000000000..10a9a28de76 --- /dev/null +++ b/addons/google_spreadsheet/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Google Spreadsheet', + 'version': '1.0', + 'category': 'Tools', + 'description': """ +The module adds the possibility to display data from OpenERP in Google Spreadsheets in real time. +======================================== +""", + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': ['board', 'google_drive'], + 'js': [ + 'static/src/js/search.js', + ], + 'qweb': ['static/src/xml/*.xml'], + 'data': ['google_spreadsheet_data.xml'], + 'demo': [], + 'installable': True, + 'auto_install': False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_spreadsheet/google_spreadsheet.py b/addons/google_spreadsheet/google_spreadsheet.py new file mode 100644 index 00000000000..08a8fa8d2cd --- /dev/null +++ b/addons/google_spreadsheet/google_spreadsheet.py @@ -0,0 +1,34 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2012 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import osv + + +class config(osv.osv): + _inherit = 'google.drive.config' + + def set_spreadsheet(self, cr, uid, model, domain, groupbys, view_id, context=None): + try: + config_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'google_spreadsheet', 'google_spreadsheet_template')[1] + except ValueError: + raise + config = self.browse(cr, uid, config_id, context=context) + res = self.copy_doc(cr, uid, 1, config.google_drive_resource_id, 'Spreadsheet %s' % model, model, context=context) + return res diff --git a/addons/google_spreadsheet/google_spreadsheet_data.xml b/addons/google_spreadsheet/google_spreadsheet_data.xml new file mode 100644 index 00000000000..04c2122fabb --- /dev/null +++ b/addons/google_spreadsheet/google_spreadsheet_data.xml @@ -0,0 +1,11 @@ + + + + + Base Spreadsheet Template + + https://docs.google.com/spreadsheet/ccc?key=0ApGVjjwUC-ygdDZ0TG5EQnRlLVFQNlFGdFN5b1ZrY1E + Reporting %(name)s + + + \ No newline at end of file diff --git a/addons/google_spreadsheet/static/src/js/search.js b/addons/google_spreadsheet/static/src/js/search.js new file mode 100644 index 00000000000..beac52c4d6f --- /dev/null +++ b/addons/google_spreadsheet/static/src/js/search.js @@ -0,0 +1,54 @@ +openerp.google_spreadsheet = function(instance) { + var _t = instance.web._t; + instance.web.FormView.include({ + on_processed_onchange: function(result, processed) { + var self = this; + + var fields = self.fields; + _(result.selection).each(function (selection, fieldname) { + var field = fields[fieldname]; + if (!field) { return; } + field.field.selection = selection; + field.values = selection; + field.renderElement(); + }); + return this._super(result, processed); + }, + }); + instance.board.AddToGoogleSpreadsheet = instance.web.search.Input.extend({ + template: 'SearchView.addtogooglespreadsheet', + _in_drawer: true, + start: function () { + var self = this; + this.$el.on('click', 'h4', function(){ + var view = self.view; + var data = view.build_search_data(); + var model = view.model; + var list_view = self.view.getParent().views['list']; + var view_id = list_view ? list_view.view_id : false; + var context = new instance.web.CompoundContext(view.dataset.get_context() || []); + var domain = new instance.web.CompoundDomain(view.dataset.get_domain() || []); + _.each(data.contexts, context.add, context); + _.each(data.domains, domain.add, domain); + domain = JSON.stringify(domain.eval()); + var groupbys = instance.web.pyeval.eval('groupbys', data.groupbys).join(" "); + var view_id = view_id; + var ds = new instance.web.DataSet(self, 'google.drive.config'); + ds.call('set_spreadsheet', [model, domain, groupbys, view_id]).done(function (url) { + if (url){ + window.open(url, '_blank'); + } + }); + }); + }, + }); + instance.web.SearchView.include({ + add_common_inputs: function() { + this._super(); + var vm = this.getParent().getParent(); + if (vm.inner_action && vm.inner_action.views) { + (new instance.board.AddToGoogleSpreadsheet(this)); + } + } + }); +}; \ No newline at end of file diff --git a/addons/google_spreadsheet/static/src/xml/addtospreadsheet.xml b/addons/google_spreadsheet/static/src/xml/addtospreadsheet.xml new file mode 100644 index 00000000000..faf984141a6 --- /dev/null +++ b/addons/google_spreadsheet/static/src/xml/addtospreadsheet.xml @@ -0,0 +1,5 @@ + \ No newline at end of file