diff --git a/addons/document/document.py b/addons/document/document.py index 3ae783f49e7..27dde3250e2 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -154,6 +154,7 @@ class document_file(osv.osv): parent_id = vals.get('parent_id', False) res_model = vals.get('res_model', False) res_id = vals.get('res_id', 0) + if op == 'write': for file in self.browse(cr, uid, ids): # FIXME fields_only if not name: @@ -164,11 +165,11 @@ class document_file(osv.osv): res_model = file.res_model and file.res_model or False if not res_id: res_id = file.res_id and file.res_id or 0 - res = self.search(cr, uid, [('id', '<>', file.id), ('name', '=', name), ('parent_id', '=', parent_id), ('res_model', '=', res_model), ('res_id', '=', res_id)]) + res = self.search(cr, uid, [('id', '<>', file.id), ('name', '=', name), ('parent_id', '=', parent_id), ('res_model', '=', res_model), ('res_model', '!=', ''), ('res_id', '=', res_id)]) if len(res): return False if op == 'create': - res = self.search(cr, uid, [('name', '=', name), ('parent_id', '=', parent_id), ('res_id', '=', res_id), ('res_model', '=', res_model)]) + res = self.search(cr, uid, [('name', '=', name), ('parent_id', '=', parent_id), ('res_id', '=', res_id), ('res_model', '=', res_model), ('res_model', '!=', '')]) if len(res): return False return True @@ -219,7 +220,11 @@ class document_file(osv.osv): res = self.search(cr, uid, [('id', 'in', ids)]) if not len(res): return False - if not self._check_duplication(cr, uid, vals, ids, 'write'): + + # when a user write a mail, there are no model + # don't check the duplication for the mails + res_mail = self.search(cr, uid, [('id', 'in', ids), ('res_model', '=', '')]) + if res!=res_mail and not self._check_duplication(cr, uid, vals, ids, 'write'): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) # if nodes call this write(), they must skip the code below diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index da4143df909..4e8d036d68a 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -697,7 +697,7 @@ class mail_thread(osv.AbstractModel): def message_post_api(self, cr, uid, thread_id, body='', subject=False, type='notification', subtype=None, parent_id=False, attachments=None, context=None, **kwargs): # if the user write on his wall - if self._name=='res.partner' and (not thread_id or not thread_id[0]): + if self._name=='res.partner' and not thread_id: user = self.pool.get('res.users').browse(cr, uid, uid, context=context) thread_id = user.partner_id.id diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 9133078d433..c2abc6a5882 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -245,6 +245,7 @@ .openerp .oe_mail_msg_email { padding: 8px; background: white; + position: relative; } .openerp .oe_mail_msg_notification:after, diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 599241e598f..8fab771fcc0 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -104,12 +104,13 @@ openerp.mail = function(session) { this.res_id = options.parameters.res_id; this.is_private = options.parameters.is_private; this.partner_ids = options.parameters.partner_ids; - this.show_header_compose = options.parameters.options.thread.show_header_compose; - this.display_on_flat = options.parameters.options.thread.display_on_flat; + this.options={thread:{}}; + this.options.thread.show_header_compose = options.parameters.options.thread.show_header_compose; + this.options.thread.display_on_flat = options.parameters.options.thread.display_on_flat; this.attachment_ids = []; - this.show_attachment_delete = true; - this.show_attachment_link = true; + this.options.thread.show_attachment_delete = true; + this.options.thread.show_attachment_link = true; this.parent_thread= parent.messages!= undefined ? parent : false; @@ -147,12 +148,17 @@ openerp.mail = function(session) { var $target = $(event.target); if ($target.val() !== '') { + // if the files exits for this answer, delete the file before upload + var attachments=[]; for(var i in this.attachment_ids){ if(this.attachment_ids[i].url == $target.val()){ var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); - ds_attachment.unlink(this.attachment_ids.id); + ds_attachment.unlink([this.attachment_ids.id]); + } else { + attachments.push(this.attachment_ids[i]); } } + this.attachment_ids = attachments; // submit file session.web.blockUI(); @@ -186,7 +192,7 @@ openerp.mail = function(session) { this.display_attachments(); var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); - ds_attachment.unlink(attachment_id); + ds_attachment.unlink([attachment_id]); } }, @@ -231,7 +237,7 @@ openerp.mail = function(session) { this.$('input[data-id]').remove(); this.attachment_ids=[]; this.display_attachments(); - if(!this.show_header_compose || !this.display_on_flat){ + if(!this.options.thread.show_header_compose || !this.options.thread.display_on_flat){ this.$el.hide(); } }, @@ -455,10 +461,10 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; + // event: click on 'Attachment(s)' in msg - this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) { - var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments'); - act_dom.toggle(); + this.$('a.oe_mail_msg_view_attachments:first').on('click', function (event) { + self.$('.oe_mail_msg_attachments:first').toggle(); }); // event: click on icone 'Read' in header this.$el.on('click', 'a.oe_read', this.on_message_read_unread); diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index db6935d7af8..cd14632ec6c 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -55,14 +55,14 @@ Template used to display attachments in a mail.message --> -