mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-23 04:22:04 -06:00
[IMP] Refresh automatically list of documents in the form view;from knownlege, delete the documents and references; when delete document from form view, juste delete the reference; informations about the model are saved in the attachment_document_ids
This commit is contained in:
parent
b30711948f
commit
2889c10a50
@ -41,10 +41,15 @@ Contributors
|
||||
],
|
||||
'data': [
|
||||
'document_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/document_wizard_view.xml',
|
||||
],
|
||||
'js': ['static/src/js/document.js'],
|
||||
'qweb': ['static/src/xml/document.xml'],
|
||||
'js': [
|
||||
'static/src/js/document.js'
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/document.xml'
|
||||
],
|
||||
'test': [],
|
||||
'demo': [
|
||||
],
|
||||
|
@ -33,49 +33,47 @@ class document_file(orm.Model):
|
||||
}
|
||||
|
||||
def create(self, cr, uid, data, context=None):
|
||||
res = super(document_file, self).create(cr, uid, data, context=context)
|
||||
if 'res_model' and 'res_id' in data:
|
||||
ir_attachment_document_obj = self.pool.get('ir.attachment.document')
|
||||
original_data = {key: data[key] for key in data.keys()}
|
||||
# Don't save this information below
|
||||
data['res_model'] = ''
|
||||
data['res_id'] = ''
|
||||
data['res_name'] = ''
|
||||
res = super(document_file, self).create(cr, uid, data, context=context)
|
||||
# Create attachment_document_ids with res_model, res_id and res_name
|
||||
if 'res_model' and 'res_id' in original_data:
|
||||
doc_data = {
|
||||
'attachment_id': res,
|
||||
'res_model': data['res_model'],
|
||||
'res_id': data['res_id'],
|
||||
'res_name': data.get('res_name') or self.pool.get(data['res_model']).browse(cr, uid, data['res_id'], context=context).name
|
||||
'res_model': original_data['res_model'],
|
||||
'res_id': original_data['res_id'],
|
||||
'res_name': original_data.get('res_name')
|
||||
or self.pool.get(original_data['res_model']).browse(cr, uid,
|
||||
original_data['res_id'],
|
||||
context=context).name
|
||||
}
|
||||
|
||||
ir_attachment_document_obj.create(cr, uid, doc_data,
|
||||
context=context)
|
||||
|
||||
return res
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
def unlink(self, cr, uid, ids, context=None, check=True):
|
||||
ir_attach_doc_obj = self.pool.get('ir.attachment.document')
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
# Deleting from dropdown list in the form view
|
||||
if context.get('res_model') and context.get('res_id'):
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.attachment_document_ids and len(line.attachment_document_ids) > 1:
|
||||
if line.attachment_document_ids:
|
||||
query = [
|
||||
('attachment_id', '=', line.id),
|
||||
('res_model', '=', line.res_model),
|
||||
('res_id', '=', line.res_id)
|
||||
('res_model', '=', context.get('res_model')),
|
||||
('res_id', '=', context.get('res_id')),
|
||||
('attachment_id', '=', ids),
|
||||
]
|
||||
id_to_unlink = ir_attach_doc_obj.search(
|
||||
cr, uid, query, context=context)
|
||||
|
||||
data = {
|
||||
'res_id': False,
|
||||
'res_model': False,
|
||||
'res_name': False
|
||||
}
|
||||
self.write(cr, uid, ids, data, context=context)
|
||||
ir_attach_doc_obj.unlink(cr, uid, id_to_unlink,
|
||||
context=context)
|
||||
|
||||
id_to_unlink = ir_attach_doc_obj.search(cr, uid, query, context=context)
|
||||
result = ir_attach_doc_obj.unlink(cr, uid, id_to_unlink, context=context)
|
||||
else:
|
||||
super(document_file, self).unlink(cr, uid, line.id,
|
||||
context=context)
|
||||
return True
|
||||
# Normal delete
|
||||
result = super(document_file, self).unlink(cr, uid, ids, context=context)
|
||||
return result
|
||||
|
||||
|
||||
class ir_attachment_document(orm.Model):
|
||||
|
2
document_multiple_records/security/ir.model.access.csv
Normal file
2
document_multiple_records/security/ir.model.access.csv
Normal file
@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_ir_attachment_document_group_user,ir.attachment.document user,model_ir_attachment_document,base.group_document_user,1,1,1,1
|
|
@ -22,7 +22,7 @@ var _t = instance.web._t,
|
||||
};
|
||||
// the action dictionary variable sends data in the "self.do_action" method
|
||||
var action = {
|
||||
name: _t("Add existing document/attachment"),
|
||||
name: _t("Add existing document"),
|
||||
type: 'ir.actions.act_window',
|
||||
res_model: 'ir.attachment.existing.doc',
|
||||
view_mode: 'form',
|
||||
@ -32,7 +32,32 @@ var _t = instance.web._t,
|
||||
context: context,
|
||||
};
|
||||
// self.do_action accepts the action parameter and opens the new view
|
||||
self.do_action(action);
|
||||
self.do_action(action, {
|
||||
// refresh list of documents
|
||||
on_close: function () {
|
||||
self.do_attachement_update(self.dataset, self.model_id);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
on_attachment_delete: function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
var self = this;
|
||||
var view = self.getParent();
|
||||
self.model_view = view.dataset.model
|
||||
var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
|
||||
// Context dictionary variable
|
||||
var context = {
|
||||
'res_model': self.model_view,
|
||||
'res_id': ids[0],
|
||||
};
|
||||
var $e = $(e.currentTarget);
|
||||
if (confirm(_t("Do you really want to delete this attachment ?"))) {
|
||||
(new instance.web.DataSet(this, 'ir.attachment', context)).unlink([parseInt($e.attr('data-id'), 10)]).done(function() {
|
||||
self.do_attachement_update(self.dataset, self.model_id);
|
||||
});
|
||||
}
|
||||
},
|
||||
do_attachement_update: function(dataset, model_id, args) {
|
||||
var self = this;
|
||||
@ -43,7 +68,8 @@ var _t = instance.web._t,
|
||||
}
|
||||
if (!model_id) {
|
||||
this.on_attachments_loaded([]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
var dom = [ ['attachment_document_ids.res_model', '=', dataset.model], ['attachment_document_ids.res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
|
||||
var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
|
||||
ds.read_slice(['name', 'url', 'type', 'create_uid', 'create_date', 'write_uid', 'write_date'], {}).done(this.on_attachments_loaded);
|
||||
|
@ -4,7 +4,7 @@
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="AddDocfromserver">
|
||||
<li class="open"><span><b>Add existing document/attachment...</b></span></li>
|
||||
<li class="open"><span><b>Add existing document...</b></span></li>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
@ -55,11 +55,7 @@ class document_wizard(orm.Model):
|
||||
'attachment_id': attach.id,
|
||||
}
|
||||
#Created attachment_document_ids
|
||||
if attach.res_model:
|
||||
ir_attach_doc_obj.create(cr, uid, data_attach, context=context)
|
||||
# Updated attachment line
|
||||
else:
|
||||
ir_attach_obj.write(cr, uid, [attach.id], data_attach, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue
Block a user