[IMP] change the way to name the attachement and change when you already have a google document the button will be hide
bzr revid: mva@openerp.com-20120402131817-oxv227m8i11pfsjx
This commit is contained in:
parent
ac63b945f6
commit
fb989dbfb7
|
@ -105,9 +105,11 @@ class google_docs(osv.osv):
|
|||
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
|
||||
print name_gdocs
|
||||
name_gdocs = name_gdocs % model_fields_dic[0]
|
||||
|
||||
# check if a model is configurate with a template
|
||||
if google_docs_config:
|
||||
|
@ -130,22 +132,17 @@ class config(osv.osv):
|
|||
}
|
||||
|
||||
_defaults = {
|
||||
'name_template': 'pr_%(name)',
|
||||
'name_template': 'pr_%(name)s',
|
||||
}
|
||||
def get_config(self, cr, uid, model):
|
||||
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
|
||||
'''
|
||||
domain = [('model_id', '=', model)]
|
||||
if self.search_count(cr, uid, domain) != 0:
|
||||
return False
|
||||
# attached only one document to a model
|
||||
if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%')]) !=0:
|
||||
return 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 self.search(cr, uid, domain)
|
||||
|
||||
return True
|
||||
config()
|
||||
|
||||
|
||||
|
|
|
@ -5,31 +5,35 @@ openerp.google_docs = function(instance, session) {
|
|||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.delegate('.oe_google_docs_text_button', 'click', this.on_add_text_gdoc);
|
||||
var self = this;
|
||||
var config = new instance.web.DataSet(this, 'google.docs.config', this.view.dataset.get_context());
|
||||
config.call('get_config', [this.view.dataset.ids[this.view.dataset.index]], function(r) {
|
||||
// if the configuration isn't set, the buttons should be hidden.
|
||||
if (r==false) {
|
||||
$('.oe_google_docs_text_button',this.$element).hide();
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
var attachment = new instance.web.DataSet(this, 'ir.attachment', self.view.dataset.get_context());
|
||||
attachment.call('copy_gdoc', [self.view.dataset.model, [self.view.datarecord.id]], function(res) {
|
||||
});
|
||||
});
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
console.log($('.oe_google_docs_text_button',this.$element))
|
||||
$('.oe_google_docs_text_button',this.$element)
|
||||
},
|
||||
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();
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue