Michael (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-google_docs-rlo into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-google_docs-rlo/+merge/100449
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-google_docs-rlo/+merge/100449
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-google_docs-rlo.
=== modified file 'google_base_account/google_base_account_view.xml'
--- google_base_account/google_base_account_view.xml	2011-03-03 12:23:47 +0000
+++ google_base_account/google_base_account_view.xml	2012-04-02 15:14:42 +0000
@@ -1,20 +1,20 @@
 <?xml version="1.0"?>
 <openerp>
     <data>
-		<record id="view_users_gogole_form" model="ir.ui.view">
-        <field name="name">res.users.google.form1</field>
-          <field name="model">res.users</field>
-          <field name="type">form</field>
-          <field name="inherit_id" ref="base.view_users_form"/>
-          <field name="arch" type="xml">
-              <xpath expr="//notebook[last()]" position="inside">
-                     <page string=" Synchronization ">
-                     	<separator string="Google Account" colspan="4" />
-						<field name="gmail_user"/>
-                      <field name="gmail_password" password="True"/>
-					</page>
-              </xpath>
-          </field>
-     </record>
+        <record id="view_users_gogole_form" model="ir.ui.view">
+            <field name="name">res.users.google.form1</field>
+            <field name="model">res.users</field>
+            <field name="type">form</field>
+            <field name="inherit_id" ref="base.view_users_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//notebook[last()]" position="inside">
+                    <page string=" Synchronization ">
+                        <separator string="Google Account" colspan="4" />
+                        <field name="gmail_user"/>
+                        <field name="gmail_password" password="True"/>
+                    </page>
+                </xpath>
+            </field>
+        </record>
     </data>
 </openerp>

=== modified file 'google_base_account/wizard/google_login.py'
--- google_base_account/wizard/google_login.py	2011-06-07 07:23:20 +0000
+++ google_base_account/wizard/google_login.py	2012-04-02 15:14:42 +0000
@@ -43,6 +43,8 @@
             gd_client = gdata.contacts.service.ContactsService()
         if type == 'calendar':
             gd_client = gdata.calendar.service.CalendarService()
+        if type =='docs_client':
+            gd_client = gdata.docs.client.DocsClient()
         else:
             gd_client = gdata.contacts.service.ContactsService()     
         try:    

=== added directory 'google_docs'
=== added file 'google_docs/__init__.py'
--- google_docs/__init__.py	1970-01-01 00:00:00 +0000
+++ google_docs/__init__.py	2012-04-02 15:14:42 +0000
@@ -0,0 +1,1 @@
+import google_docs

=== added file 'google_docs/__openerp__.py'
--- google_docs/__openerp__.py	1970-01-01 00:00:00 +0000
+++ google_docs/__openerp__.py	2012-04-02 15:14:42 +0000
@@ -0,0 +1,40 @@
+# -*- 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 Docs integration',
+    'version': '0.2',
+    'author': 'OpenERP SA',
+    'website': 'http://openerp.com',
+    'category': 'Tools',
+    'installable': True,
+    'auto_install': False,
+    'web': True,
+    'js': ['static/src/js/gdocs.js'],
+    'qweb' : [
+        "static/src/xml/gdocs.xml",
+    ],
+    'update_xml': [
+        'res_config_user_view.xml'
+    ],
+    'depends': ['google_base_account'],
+    'description': 'Module to attach a google document to any model.'
+}

=== added file 'google_docs/google_docs.py'
--- google_docs/google_docs.py	1970-01-01 00:00:00 +0000
+++ google_docs/google_docs.py	2012-04-02 15:14:42 +0000
@@ -0,0 +1,148 @@
+##############################################################################
+#
+#    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 osv import osv, fields
+try:
+    import gdata.docs.data
+    import gdata.docs.client
+    from gdata.client import RequestError
+    from gdata.docs.service import DOCUMENT_LABEL
+    import gdata.auth
+except ImportError:
+    raise osv.except_osv(_('Google Docs Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
+
+class google_docs_ir_attachment(osv.osv):
+    _inherit = 'ir.attachment'
+
+    def _auth(self, cr, uid,context=None):
+        '''
+        Connexion with google base account
+        @return client object for connexion
+        '''
+        #pool the google.login in google_base_account
+        google_pool = self.pool.get('google.login')
+        
+        #get gmail password and login
+        user_config = google_pool.default_get( cr, uid, {'user' : '' , 'password' : ''},context=context)
+        #login gmail account
+        client = google_pool.google_login( user_config['user'], user_config['password'], type='docs_client', context=context)
+        if not client:
+            raise osv.except_osv(('Google Docs Error!'),("Check your google configuration in users/synchronization") )
+        return client
+
+    def create_empty_google_doc(self, cr, uid, name_gdocs, model, ids, type_doc,context=None):
+        '''Associate a copy of the gdoc identified by 'gdocs_res_id' to the current entity.
+           @param cr: the current row from the database cursor.
+           @param uid: the current user ID, for security checks.
+           @param model: the current model name.
+           @param type_doc: text, spreadsheet or slide.
+           @return the document object.
+           @return False if the google_base_account hasn't been configured yet.
+        '''
+        #login with the base account google module
+        client = self._auth(cr, uid,context=context)
+        # create the document in google docs
+        local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL)
+        #create a new doc in Google Docs 
+        gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/')
+        # register into the db
+        self.create(cr, uid, {
+            'res_model': model,
+            'res_id': ids[0],
+            'type': 'url',
+            'name': 'Google Doc',
+            'url': gdocs_resource.get_alternate_link().href,
+        },context=context)
+        
+        
+        return 1
+
+    def copy_gdoc(self, cr, uid, name_gdocs, model, google_res_id, ids,context=None):
+        '''
+        copy an existing document in google docs
+        '''
+        client = self._auth(cr, uid)
+        # fetch and copy the original document
+        try:
+            original_resource = client.get_resource_by_id(google_res_id)
+            #copy the document you choose in the configuration
+            copy_resource = client.copy_resource(original_resource,'copy_%s' % original_resource.title.text)
+        except:
+            raise osv.except_osv(('Google Docs Error!'),("Your ressource id is not correct. You can find the id in the google docs URL") )
+        # register into the db
+        self.create(cr, uid, {
+            'res_model': model,
+            'res_id': ids[0],
+            'type': 'url',
+            'name': name_gdocs,
+            'url': copy_resource.get_alternate_link().href
+        },context=context)
+
+        return copy_resource
+
+class google_docs(osv.osv):
+    _name = 'google.docs'
+
+    def doc_get(self, cr, uid, model, id, type_doc,context=None):
+        ir_attachment_ref = self.pool.get('ir.attachment')
+        pool_gdoc_config = self.pool.get('google.docs.config')
+        google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', model)])
+        name_gdocs=''
+        model_fields_dic = self.pool.get(model).read(cr,uid,id,[])
+        
+        if google_docs_config:
+            name_gdocs = pool_gdoc_config.browse(cr,uid,google_docs_config,context=context)[0].name_template
+            name_gdocs = name_gdocs % model_fields_dic[0]
+        
+        # check if a model is configurate with a template
+        if google_docs_config:
+            for google_config in self.pool.get('google.docs.config').browse(cr,uid,google_docs_config,context=context):
+                google_res_id = google_config.gdocs_resource_id
+            google_document = ir_attachment_ref.copy_gdoc(cr, uid,name_gdocs ,model,google_res_id, id)
+        else:
+            google_document = ir_attachment_ref.create_empty_google_doc(cr, uid,name_gdocs, model, id, type_doc)
+            return -1
+
+
+class config(osv.osv):
+    _name = 'google.docs.config'
+    _description = "Google Docs templates config"
+
+    _columns = {
+        'model_id': fields.many2one('ir.model', 'Model'),
+        'gdocs_resource_id': fields.char('Google resource ID', size=64,help='This is the id of the template document you kind find it in the URL'),
+        'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'),
+    }
+
+    _defaults = {
+        'name_template': 'pr_%(name)s',
+    }
+    def get_config(self, cr, uid, ids, model,context=None):
+        '''
+        Method use with the js to hidde or show the add google doc button 
+        @return : list of configuration ids or false
+        '''
+        if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%'),('res_model','=',model),('res_id','=',ids[0])]) !=0:
+            return  False
+        else:
+            return True
+config()
+
+

=== added file 'google_docs/res_config_user_view.xml'
--- google_docs/res_config_user_view.xml	1970-01-01 00:00:00 +0000
+++ google_docs/res_config_user_view.xml	2012-04-02 15:14:42 +0000
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <!-- add google docs config field in user form -->
+
+        <record model="ir.ui.view" id="view_google_docs_config_tree">
+            <field name="name">google_docs.config.tree</field>
+            <field name="model">google.docs.config</field>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <group name="default_filters" position="inside">
+                    <field name="model_id"/>
+                </group>
+            </field>
+        </record>
+
+        <record model="ir.ui.view" id="view_google_docs_config_form">
+            <field name="name">google_docs.config.form</field>
+            <field name="model">google.docs.config</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+            <group colspan='4'>
+                <field name="model_id"/>
+                <field name='gdocs_resource_id'/>
+                <field name='name_template'/>
+            </group>
+            </field>
+        </record>
+
+        <record model='ir.actions.act_window' id='action_google_docs_users_config'>
+            <field name='name'>Models configuration</field>
+            <field name='res_model'>google.docs.config</field>
+            <field name='type'>ir.actions.act_window</field>
+            <field name='view_type'>form</field>
+            <field name='view_id' ref='view_google_docs_config_tree'/>
+        </record>
+        <menuitem name='Google Docs configuration' id='menu_gdocs_config' parent='base.menu_administration'/>
+        <menuitem name='Models configuration' id='menu_gdocs_model_config' parent='menu_gdocs_config' action='action_google_docs_users_config'/>
+    </data>
+</openerp>

=== added directory 'google_docs/static'
=== added directory 'google_docs/static/src'
=== added directory 'google_docs/static/src/js'
=== added file 'google_docs/static/src/js/gdocs.js'
--- google_docs/static/src/js/gdocs.js	1970-01-01 00:00:00 +0000
+++ google_docs/static/src/js/gdocs.js	2012-04-02 15:14:42 +0000
@@ -0,0 +1,42 @@
+openerp.google_docs = function(instance, session) {
+
+
+        instance.web.form.SidebarAttachments = instance.web.form.SidebarAttachments.extend({
+            init: function() {
+                this._super.apply(this, arguments);
+                this.$element.delegate('.oe_google_docs_text_button', 'click', this.on_add_text_gdoc);
+            },
+
+
+           on_attachments_loaded: function(attachments) {
+               this._super(attachments);
+               var config = new instance.web.DataSet(this, 'google.docs.config', this.view.dataset.get_context());
+               config.call('get_config', [[this.view.datarecord.id],this.view.dataset.model,this.view.dataset.get_context()], function(r) {
+               if (r == false){
+               $('.oe_google_docs_text_button',this.$element).hide();
+               }
+               });
+           },
+
+            on_add_text_gdoc: function() {
+                var self = this;
+                var $gdocbtn = this.$element.find('.oe_google_docs_text_button');
+                $gdocbtn.attr('disabled', 'true').find('img, span').toggle();
+                var ds = new instance.web.DataSet(this, 'google.docs', this.view.dataset.get_context());
+                ds.call('doc_get', [this.view.dataset.model, [this.view.datarecord.id], 'text'], function(r) {
+                    if (r == 'False') {
+                        var params = {
+                            error: response,
+                            message: "The user google credentials are not set yet. Contact your administrator for help."
+                        }
+                        $(openerp.web.qweb.render("DialogWarning", params)).dialog({
+                            title: "User Google credentials are not yet set.",
+                            modal: true,
+                        });
+                    }
+                    self.do_update();
+                });
+            },
+        });
+};
+

=== added directory 'google_docs/static/src/xml'
=== added file 'google_docs/static/src/xml/gdocs.xml'
--- google_docs/static/src/xml/gdocs.xml	1970-01-01 00:00:00 +0000
+++ google_docs/static/src/xml/gdocs.xml	2012-04-02 15:14:42 +0000
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vim:fdl=1:
+-->
+<templates id="template" xml:space="preserve">
+    <t t-extend="FormView.sidebar.attachments">
+        <t t-jquery="div.oe-binary-file-set" t-operation="append">
+                <button class="oe_google_docs_text_button" type="button">
+                    <img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
+                    <span>Goole Docs</span>
+                </button>
+        </t>
+    </t>
+</templates>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to