diff options
| author | Denis Ledoux <dle@openerp.com> | 2013-06-27 19:11:37 +0200 |
|---|---|---|
| committer | Denis Ledoux <dle@openerp.com> | 2013-06-27 19:11:37 +0200 |
| commit | aa28839fb1818db22ce58606cc2a831ee39546ef (patch) | |
| tree | 423ee638e382bdc990e12331cecc0048814e5dc1 /addons/google_spreadsheet | |
| parent | 53358465b32fb99295bf75a2a7ffd3f1d8157af6 (diff) | |
[ADD]google_spreadsheet
bzr revid: dle@openerp.com-20130627171137-5r1gyciz92c8abbr
Diffstat (limited to 'addons/google_spreadsheet')
| -rw-r--r-- | addons/google_spreadsheet/__init__.py | 1 | ||||
| -rw-r--r-- | addons/google_spreadsheet/__openerp__.py | 43 | ||||
| -rw-r--r-- | addons/google_spreadsheet/google_spreadsheet.py | 34 | ||||
| -rw-r--r-- | addons/google_spreadsheet/google_spreadsheet_data.xml | 11 | ||||
| -rw-r--r-- | addons/google_spreadsheet/static/src/js/search.js | 54 | ||||
| -rw-r--r-- | addons/google_spreadsheet/static/src/xml/addtospreadsheet.xml | 5 |
6 files changed, 148 insertions, 0 deletions
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 (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + + +{ + '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 (<http://www.openerp.com>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + +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 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + <record id="google_spreadsheet_template" model="google.drive.config"> + <field name="name">Base Spreadsheet Template</field> + <field name="model_id" ref="base.model_res_partner"/> + <field name="google_drive_template_url">https://docs.google.com/spreadsheet/ccc?key=0ApGVjjwUC-ygdDZ0TG5EQnRlLVFQNlFGdFN5b1ZrY1E</field> + <field name="name_template">Reporting %(name)s</field> + </record> + </data> +</openerp>
\ 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 @@ +<template> +<div t-name="SearchView.addtogooglespreadsheet" class="oe_searchview_dashboard"> + <h4>Add to Google Spreadsheet</h4> +</div> +</template>
\ No newline at end of file |
