[IMP] mail, document: don't check duplication of file for attachment mail

bzr revid: chm@openerp.com-20121009080858-gnpf1893m12jd3mp
This commit is contained in:
Christophe Matthieu 2012-10-09 10:08:58 +02:00
parent aff7e6d161
commit 7a41798d70
5 changed files with 30 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -245,6 +245,7 @@
.openerp .oe_mail_msg_email {
padding: 8px;
background: white;
position: relative;
}
.openerp .oe_mail_msg_notification:after,

View File

@ -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);

View File

@ -55,14 +55,14 @@
Template used to display attachments in a mail.message
-->
<t t-name="mail.thread.message.attachments">
<ul t-attf-class="oe_mail_msg_attachments #{widget.attachment_ids[0]?'':'oe_hidden'}">
<ul t-attf-class="oe_mail_msg_attachments #{widget.attachment_ids[0] and widget.options.thread.show_attachment_link?'':'oe_hidden'}">
<t t-foreach="widget.attachment_ids" t-as="attachment">
<li>
<a t-if="widget.show_attachment_link" t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
<span t-if="!widget.show_attachment_link"><t t-raw="attachment.name || attachment.filename"/></span>
<t t-if="widget.show_attachment_delete">
<a t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
<t t-if="widget.options.thread.show_attachment_delete">
<a class="oe_right oe_mail_attachment_delete" title="Delete this attachmentt" t-attf-data-id="{attachment.id}">x</a>
</t>
</li>
</t>
</ul>
@ -214,7 +214,6 @@
<ul class="oe_mail_msg_footer">
<li t-if="widget.author_id"><a t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a></li>
<li><span t-att-title="widget.date"><t t-raw="widget.timerelative"/></span></li>
<li t-if="widget.attachment_ids.length > 0">
<a class="oe_mail_msg_view_attachments">
<t t-if="widget.attachment_ids.length == 1">1 Attachment</t>