From 97503d09aecc70d8d4517406e8c10918bb7cb916 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 18 Feb 2014 10:17:04 -0500 Subject: [PATCH 01/13] Added document_multiple_records module: It allows to manage a document with a multiple records. --- document_multiple_records/__init__.py | 26 ++++ document_multiple_records/__openerp__.py | 55 +++++++ document_multiple_records/document.py | 66 +++++++++ document_multiple_records/document_view.xml | 30 ++++ .../i18n/document_multiple_records.pot | 140 ++++++++++++++++++ .../static/src/js/document.js | 39 +++++ .../static/src/xml/document.xml | 10 ++ document_multiple_records/wizard/__init__.py | 25 ++++ .../wizard/document_wizard.py | 59 ++++++++ .../wizard/document_wizard_view.xml | 41 +++++ 10 files changed, 491 insertions(+) create mode 100644 document_multiple_records/__init__.py create mode 100644 document_multiple_records/__openerp__.py create mode 100644 document_multiple_records/document.py create mode 100644 document_multiple_records/document_view.xml create mode 100644 document_multiple_records/i18n/document_multiple_records.pot create mode 100644 document_multiple_records/static/src/js/document.js create mode 100644 document_multiple_records/static/src/xml/document.xml create mode 100644 document_multiple_records/wizard/__init__.py create mode 100644 document_multiple_records/wizard/document_wizard.py create mode 100644 document_multiple_records/wizard/document_wizard_view.xml diff --git a/document_multiple_records/__init__.py b/document_multiple_records/__init__.py new file mode 100644 index 00000000..d44daea7 --- /dev/null +++ b/document_multiple_records/__init__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################### + +from . import document +import wizard + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/__openerp__.py b/document_multiple_records/__openerp__.py new file mode 100644 index 00000000..f882fb38 --- /dev/null +++ b/document_multiple_records/__openerp__.py @@ -0,0 +1,55 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +{ + 'name': 'Document Management System for Multiple Records', + 'version': '0.1', + 'category': 'Knowledge Management', + 'summary': 'Document Management System for Multiple Records', + 'description': """ +Document Management System for Multiple Records +============================================== + +Contributors +------------ +* El Hadji Dem (elhadji.dem@savoirfairelinux.com) +""", + 'author': 'Savoir-faire Linux', + 'website': 'www.savoirfairelinux.com', + 'license': 'AGPL-3', + 'depends': [ + 'document', + ], + 'data': [ + 'document_view.xml', + 'wizard/document_wizard_view.xml', + ], + 'js': ['static/src/js/document.js'], + 'qweb': ['static/src/xml/document.xml'], + 'test': [], + 'demo': [ + ], + 'installable': True, + 'auto_install': False, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py new file mode 100644 index 00000000..11e9e022 --- /dev/null +++ b/document_multiple_records/document.py @@ -0,0 +1,66 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from openerp.osv import orm, fields + + +class document_file(orm.Model): + _inherit = 'ir.attachment' + + _columns = { + 'attachmentdocument_ids': fields.one2many('ir.attachment.document', 'attachment_id', 'Records'), + } + + 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 = {} + for line in self.browse(cr, uid, ids, context=context): + if line.attachmentdocument_ids: + first_id = min(line.attachmentdocument_ids) + + result = self.write(cr, uid, ids, {'res_id': first_id.res_id, + 'res_model': first_id.res_model, + 'res_name': first_id.res_name, }, context=context) + ir_attach_doc_obj.unlink(cr, uid, min(line.attachmentdocument_ids).id, context=context) + else: + result = super(document_file, self).unlink(cr, uid, ids, context=context) + return result + + +class ir_attachment_document(orm.Model): + _description = 'Attachment Documents' + _name = 'ir.attachment.document' + + _columns = { + 'res_id': fields.integer('Resource ID', readonly=True, + help="The record id this is attached to."), + 'res_model': fields.char('Resource Model', size=64, + readonly=True, + help="The database object this attachment will be attached to"), + 'res_name': fields.char('Resource Name', type='char', + size=128, + readonly=True), + 'attachment_id': fields.many2one('ir.attachment', 'Attachment'), + } + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/document_view.xml b/document_multiple_records/document_view.xml new file mode 100644 index 00000000..aefa125d --- /dev/null +++ b/document_multiple_records/document_view.xml @@ -0,0 +1,30 @@ + + + + + + ir.attachment.multiple.models + ir.attachment + + + + + + + + + + +
+ + + + + +
+
+
+
+
+
+ diff --git a/document_multiple_records/i18n/document_multiple_records.pot b/document_multiple_records/i18n/document_multiple_records.pot new file mode 100644 index 00000000..29aa02b8 --- /dev/null +++ b/document_multiple_records/i18n/document_multiple_records.pot @@ -0,0 +1,140 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * document_multiple_records +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-06 19:28+0000\n" +"PO-Revision-Date: 2014-02-06 14:29-0500\n" +"Last-Translator: EL Hadji DEM \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.5.4\n" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_id:0 +msgid "Resource ID" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Select document(s)" +msgstr "" + +#. module: document_multiple_records +#. openerp-web +#: code:addons/document_multiple_records/static/src/xml/document.xml:7 +#, python-format +msgid "Add existing Doc..." +msgstr "" + +#. module: document_multiple_records +#: field:ir.attachment.document,attachment_id:0 +msgid "Attachment" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "AttachmentDocumentWizardTree" +msgstr "" + +#. module: document_multiple_records +#. openerp-web +#: code:addons/document_multiple_records/static/src/js/document.js:26 +#: model:ir.actions.act_window,name:document_multiple_records.action_view_document +#: view:ir.attachment.wizard:0 +#, python-format +msgid "Add Document" +msgstr "" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_name:0 +msgid "Resource Name" +msgstr "" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment_document +msgid "Attachment Documents" +msgstr "" + +#. module: document_multiple_records +#: field:ir.attachment,attachmentdocument_ids:0 +msgid "Records" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "AttachmentDocumentTree" +msgstr "" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment +msgid "ir.attachment" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "Indexed Content" +msgstr "" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment_wizard +msgid "Attachment wizard" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "AttachmentDocumentForm" +msgstr "" + +#. module: document_multiple_records +#: code:addons/document_multiple_records/wizard/document_wizard.py:46 +#, python-format +msgid "Error" +msgstr "" + +#. module: document_multiple_records +#: help:ir.attachment.document,res_model:0 +msgid "The database object this attachment will be attached to" +msgstr "" + +#. module: document_multiple_records +#: help:ir.attachment.document,res_id:0 +msgid "The record id this is attached to." +msgstr "" + +#. module: document_multiple_records +#: field:ir.attachment.wizard,attachment_ids:0 +msgid "Attachments" +msgstr "" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_model:0 +msgid "Resource Model" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Cancel" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Apply" +msgstr "" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "or" +msgstr "" + +#. module: document_multiple_records +#: code:addons/document_multiple_records/wizard/document_wizard.py:47 +#, python-format +msgid "You have to select at least 1 Document. And try again" +msgstr "" diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js new file mode 100644 index 00000000..c485da9a --- /dev/null +++ b/document_multiple_records/static/src/js/document.js @@ -0,0 +1,39 @@ +openerp.document_multiple_records = function(instance, m) { +var _t = instance.web._t, + QWeb = instance.web.qweb; + + instance.web.Sidebar.include({ + redraw: function() { + var self = this; + this._super.apply(this, arguments); + self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddDocfromserver', {widget: self})) + self.$el.find('.open').on('click', function (e) { + self.on_call_new_view_function(); + //this.$('.oe_btn_class_name').on('click', this.on_call_new_view_function); + }); + }, + on_call_new_view_function: function(state) { + var self = this; + var view = self.getParent(); + var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; + // you can pass in other data using the context dictionary variable + var context = { + 'model': view.dataset.model, + 'ids': ids, + }; + // the action dictionary variable sends data in the "self.do_action" method + var action = { + name: _t("Add Document"), + type: 'ir.actions.act_window', + res_model: 'ir.attachment.wizard', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: context, + }; + // self.do_action accepts the action parameter and opens the new view + self.do_action(action); + } + }); +}; diff --git a/document_multiple_records/static/src/xml/document.xml b/document_multiple_records/static/src/xml/document.xml new file mode 100644 index 00000000..b556c8ad --- /dev/null +++ b/document_multiple_records/static/src/xml/document.xml @@ -0,0 +1,10 @@ + + + + + +
  • Add existing Doc...
  • +
    + +
    diff --git a/document_multiple_records/wizard/__init__.py b/document_multiple_records/wizard/__init__.py new file mode 100644 index 00000000..108a1a20 --- /dev/null +++ b/document_multiple_records/wizard/__init__.py @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from . import document_wizard + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/wizard/document_wizard.py b/document_multiple_records/wizard/document_wizard.py new file mode 100644 index 00000000..83136c83 --- /dev/null +++ b/document_multiple_records/wizard/document_wizard.py @@ -0,0 +1,59 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +from openerp.osv import fields, orm +from openerp.tools.translate import _ + + +class document_wizard(orm.Model): + _name = "ir.attachment.wizard" + _description = "Attachment wizard" + _columns = { + 'attachment_ids': fields.many2many('ir.attachment', + 'document_attachment_rel', + 'wizard_id', 'attachment_id', 'Attachments'), + } + + def action_apply(self, cr, uid, ids, context=None): + if context is None: + context = {} + ir_attach_obj = self.pool.get('ir.attachment') + ir_attach_doc_obj = self.pool.get('ir.attachment.document') + ir_model_obj = self.pool.get(context['model']) + + name = ir_model_obj.browse(cr, uid, context['ids'], context=context)[0]['name'] + data = self.read(cr, uid, ids, [], context=context)[0] + if not data['attachment_ids']: + raise orm.except_orm(_('Error'), + _('You have to select at least 1 Document. And try again')) + for attach in ir_attach_obj.browse(cr, uid, data['attachment_ids'], context=context): + data_attach = { + 'res_model': context['model'], + 'res_id': context['ids'][0], + 'res_name': name, + 'attachment_id': attach.id, + } + ir_attach_doc_obj.create(cr, uid, data_attach, context=context) + return {'type': 'ir.actions.act_window_close'} + +# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/document_multiple_records/wizard/document_wizard_view.xml b/document_multiple_records/wizard/document_wizard_view.xml new file mode 100644 index 00000000..9af0d333 --- /dev/null +++ b/document_multiple_records/wizard/document_wizard_view.xml @@ -0,0 +1,41 @@ + + + + + + Add Document + ir.attachment.wizard + +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + + Add Document + ir.attachment.wizard + form + tree,form + + new + + +
    +
    + From e1bf00a57587ae15282624fe9924734ec813b055 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Thu, 20 Feb 2014 15:08:37 -0500 Subject: [PATCH 02/13] [IMP]comment from lp, create line for attachement if we don't get a res_model --- document_multiple_records/document.py | 1 + document_multiple_records/static/src/js/document.js | 3 +-- document_multiple_records/wizard/document_wizard.py | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index 11e9e022..2fb2c5df 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -36,6 +36,7 @@ class document_file(orm.Model): context = {} for line in self.browse(cr, uid, ids, context=context): if line.attachmentdocument_ids: + # Get the first document first_id = min(line.attachmentdocument_ids) result = self.write(cr, uid, ids, {'res_id': first_id.res_id, diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js index c485da9a..0f2a7872 100644 --- a/document_multiple_records/static/src/js/document.js +++ b/document_multiple_records/static/src/js/document.js @@ -9,7 +9,6 @@ var _t = instance.web._t, self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddDocfromserver', {widget: self})) self.$el.find('.open').on('click', function (e) { self.on_call_new_view_function(); - //this.$('.oe_btn_class_name').on('click', this.on_call_new_view_function); }); }, on_call_new_view_function: function(state) { @@ -23,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 Document"), + name: _t("Add existing document/attachment"), type: 'ir.actions.act_window', res_model: 'ir.attachment.wizard', view_mode: 'form', diff --git a/document_multiple_records/wizard/document_wizard.py b/document_multiple_records/wizard/document_wizard.py index 83136c83..58d10e83 100644 --- a/document_multiple_records/wizard/document_wizard.py +++ b/document_multiple_records/wizard/document_wizard.py @@ -52,7 +52,12 @@ class document_wizard(orm.Model): 'res_name': name, 'attachment_id': attach.id, } - ir_attach_doc_obj.create(cr, uid, data_attach, context=context) + #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: From b23ac72dafb7f6dc1bd1a9b1b54e07286adf0332 Mon Sep 17 00:00:00 2001 From: Joao Alfredo Gama Batista Date: Wed, 26 Feb 2014 11:25:24 -0500 Subject: [PATCH 03/13] [FIX] Partial refactoring based on MP comments --- document_multiple_records/__init__.py | 2 +- document_multiple_records/document.py | 54 ++++++++++++++----- document_multiple_records/document_view.xml | 2 +- .../static/src/js/document.js | 2 +- .../wizard/document_wizard.py | 17 +++--- .../wizard/document_wizard_view.xml | 10 ++-- 6 files changed, 59 insertions(+), 28 deletions(-) diff --git a/document_multiple_records/__init__.py b/document_multiple_records/__init__.py index d44daea7..579abcbc 100644 --- a/document_multiple_records/__init__.py +++ b/document_multiple_records/__init__.py @@ -21,6 +21,6 @@ ############################################################################### from . import document -import wizard +from . import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index 2fb2c5df..fdbd5f4f 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -27,25 +27,55 @@ class document_file(orm.Model): _inherit = 'ir.attachment' _columns = { - 'attachmentdocument_ids': fields.one2many('ir.attachment.document', 'attachment_id', 'Records'), + 'attachment_document_ids': fields.one2many('ir.attachment.document', + 'attachment_id', + 'Records'), } - def unlink(self, cr, uid, ids, context=None, check=True): + 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') + 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 + } + + ir_attachment_document_obj.create(cr, uid, doc_data, + context=context) + + return res + + def unlink(self, cr, uid, ids, context=None): ir_attach_doc_obj = self.pool.get('ir.attachment.document') if context is None: context = {} - for line in self.browse(cr, uid, ids, context=context): - if line.attachmentdocument_ids: - # Get the first document - first_id = min(line.attachmentdocument_ids) - result = self.write(cr, uid, ids, {'res_id': first_id.res_id, - 'res_model': first_id.res_model, - 'res_name': first_id.res_name, }, context=context) - ir_attach_doc_obj.unlink(cr, uid, min(line.attachmentdocument_ids).id, context=context) + for line in self.browse(cr, uid, ids, context=context): + if line.attachment_document_ids and len(line.attachment_document_ids) > 1: + query = [ + ('attachment_id', '=', line.id), + ('res_model', '=', line.res_model), + ('res_id', '=', line.res_id) + ] + 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) + else: - result = super(document_file, self).unlink(cr, uid, ids, context=context) - return result + super(document_file, self).unlink(cr, uid, line.id, + context=context) + return True class ir_attachment_document(orm.Model): diff --git a/document_multiple_records/document_view.xml b/document_multiple_records/document_view.xml index aefa125d..0b564086 100644 --- a/document_multiple_records/document_view.xml +++ b/document_multiple_records/document_view.xml @@ -9,7 +9,7 @@ - + diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js index 0f2a7872..c12ca5d0 100644 --- a/document_multiple_records/static/src/js/document.js +++ b/document_multiple_records/static/src/js/document.js @@ -24,7 +24,7 @@ var _t = instance.web._t, var action = { name: _t("Add existing document/attachment"), type: 'ir.actions.act_window', - res_model: 'ir.attachment.wizard', + res_model: 'ir.attachment.existing.doc', view_mode: 'form', view_type: 'form', views: [[false, 'form']], diff --git a/document_multiple_records/wizard/document_wizard.py b/document_multiple_records/wizard/document_wizard.py index 58d10e83..ebc5dcda 100644 --- a/document_multiple_records/wizard/document_wizard.py +++ b/document_multiple_records/wizard/document_wizard.py @@ -25,12 +25,14 @@ from openerp.tools.translate import _ class document_wizard(orm.Model): - _name = "ir.attachment.wizard" - _description = "Attachment wizard" + _name = "ir.attachment.existing.doc" + _description = "Add existing document/attachment wizard" _columns = { 'attachment_ids': fields.many2many('ir.attachment', 'document_attachment_rel', - 'wizard_id', 'attachment_id', 'Attachments'), + 'wizard_id', + 'attachment_id', + 'Attachments'), } def action_apply(self, cr, uid, ids, context=None): @@ -38,17 +40,17 @@ class document_wizard(orm.Model): context = {} ir_attach_obj = self.pool.get('ir.attachment') ir_attach_doc_obj = self.pool.get('ir.attachment.document') - ir_model_obj = self.pool.get(context['model']) + ir_model_obj = self.pool.get(context.get('model') or context.get('active_model')) - name = ir_model_obj.browse(cr, uid, context['ids'], context=context)[0]['name'] + name = ir_model_obj.browse(cr, uid, context.get('ids') or context.get('active_ids'), context=context)[0]['name'] data = self.read(cr, uid, ids, [], context=context)[0] if not data['attachment_ids']: raise orm.except_orm(_('Error'), _('You have to select at least 1 Document. And try again')) for attach in ir_attach_obj.browse(cr, uid, data['attachment_ids'], context=context): data_attach = { - 'res_model': context['model'], - 'res_id': context['ids'][0], + 'res_model': context.get('model') or context.get('active_model'), + 'res_id': context.get('ids') and context.get('ids')[0] or context.get('active_id'), 'res_name': name, 'attachment_id': attach.id, } @@ -61,4 +63,3 @@ class document_wizard(orm.Model): return {'type': 'ir.actions.act_window_close'} # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/document_multiple_records/wizard/document_wizard_view.xml b/document_multiple_records/wizard/document_wizard_view.xml index 9af0d333..9e4bb836 100644 --- a/document_multiple_records/wizard/document_wizard_view.xml +++ b/document_multiple_records/wizard/document_wizard_view.xml @@ -3,10 +3,10 @@ - Add Document - ir.attachment.wizard + Add existing document/attachment + ir.attachment.existing.doc -
    + @@ -28,8 +28,8 @@ - Add Document - ir.attachment.wizard + Add existing document/attachment + ir.attachment.existing.doc form tree,form From eff15983362c9a39a459af87a9ea56dfb3c86b9d Mon Sep 17 00:00:00 2001 From: Joao Alfredo Gama Batista Date: Tue, 11 Mar 2014 14:38:31 -0400 Subject: [PATCH 04/13] [FIX] Use attachment_document_ids to get list of attachments --- .../static/src/js/document.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js index c12ca5d0..07c61b66 100644 --- a/document_multiple_records/static/src/js/document.js +++ b/document_multiple_records/static/src/js/document.js @@ -33,6 +33,21 @@ var _t = instance.web._t, }; // self.do_action accepts the action parameter and opens the new view self.do_action(action); - } + }, + do_attachement_update: function(dataset, model_id, args) { + var self = this; + this.dataset = dataset; + this.model_id = model_id; + if (args && args[0].error) { + this.do_warn(_t('Uploading Error'), args[0].error); + } + if (!model_id) { + this.on_attachments_loaded([]); + } 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); + } + } }); }; From b30711948ff3de3f8a49def002b4fda323f2b2ad Mon Sep 17 00:00:00 2001 From: Joao Alfredo Gama Batista Date: Tue, 11 Mar 2014 14:39:30 -0400 Subject: [PATCH 05/13] [IMP] More clear message for the user --- document_multiple_records/static/src/xml/document.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document_multiple_records/static/src/xml/document.xml b/document_multiple_records/static/src/xml/document.xml index b556c8ad..fc36ab7a 100644 --- a/document_multiple_records/static/src/xml/document.xml +++ b/document_multiple_records/static/src/xml/document.xml @@ -4,7 +4,7 @@ -
  • Add existing Doc...
  • +
  • Add existing document/attachment...
  • From 2889c10a505ddfcf7bfa02ec69ca00e44bec7623 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 18 Mar 2014 14:50:56 -0400 Subject: [PATCH 06/13] [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 --- document_multiple_records/__openerp__.py | 9 ++- document_multiple_records/document.py | 62 +++++++++---------- .../security/ir.model.access.csv | 2 + .../static/src/js/document.js | 50 +++++++++++---- .../static/src/xml/document.xml | 2 +- .../wizard/document_wizard.py | 6 +- 6 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 document_multiple_records/security/ir.model.access.csv diff --git a/document_multiple_records/__openerp__.py b/document_multiple_records/__openerp__.py index f882fb38..1118ff48 100644 --- a/document_multiple_records/__openerp__.py +++ b/document_multiple_records/__openerp__.py @@ -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': [ ], diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index fdbd5f4f..48ebb228 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -33,49 +33,47 @@ class document_file(orm.Model): } def create(self, cr, uid, data, context=None): + 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) - if 'res_model' and 'res_id' in data: - ir_attachment_document_obj = self.pool.get('ir.attachment.document') + # 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 = {} - - for line in self.browse(cr, uid, ids, context=context): - if line.attachment_document_ids and len(line.attachment_document_ids) > 1: - query = [ - ('attachment_id', '=', line.id), - ('res_model', '=', line.res_model), - ('res_id', '=', line.res_id) - ] - 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) - - else: - super(document_file, self).unlink(cr, uid, line.id, - context=context) - return True + # 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: + query = [ + ('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) + result = ir_attach_doc_obj.unlink(cr, uid, id_to_unlink, context=context) + else: + # Normal delete + result = super(document_file, self).unlink(cr, uid, ids, context=context) + return result class ir_attachment_document(orm.Model): diff --git a/document_multiple_records/security/ir.model.access.csv b/document_multiple_records/security/ir.model.access.csv new file mode 100644 index 00000000..a6d92b57 --- /dev/null +++ b/document_multiple_records/security/ir.model.access.csv @@ -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 diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js index 07c61b66..7eafe28a 100644 --- a/document_multiple_records/static/src/js/document.js +++ b/document_multiple_records/static/src/js/document.js @@ -17,12 +17,12 @@ var _t = instance.web._t, var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; // you can pass in other data using the context dictionary variable var context = { - 'model': view.dataset.model, - 'ids': ids, + 'model': view.dataset.model, + 'ids': ids, }; // 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,22 +32,48 @@ 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); + } + }); + }, - do_attachement_update: function(dataset, model_id, args) { + 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; this.dataset = dataset; this.model_id = model_id; if (args && args[0].error) { - this.do_warn(_t('Uploading Error'), args[0].error); + this.do_warn(_t('Uploading Error'), args[0].error); } if (!model_id) { - this.on_attachments_loaded([]); - } 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); + this.on_attachments_loaded([]); } - } + 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); + } + } }); }; diff --git a/document_multiple_records/static/src/xml/document.xml b/document_multiple_records/static/src/xml/document.xml index fc36ab7a..da9c6987 100644 --- a/document_multiple_records/static/src/xml/document.xml +++ b/document_multiple_records/static/src/xml/document.xml @@ -4,7 +4,7 @@ -
  • Add existing document/attachment...
  • +
  • Add existing document...
  • diff --git a/document_multiple_records/wizard/document_wizard.py b/document_multiple_records/wizard/document_wizard.py index ebc5dcda..68c4e7bb 100644 --- a/document_multiple_records/wizard/document_wizard.py +++ b/document_multiple_records/wizard/document_wizard.py @@ -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) + ir_attach_doc_obj.create(cr, uid, data_attach, context=context) return {'type': 'ir.actions.act_window_close'} # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: From dbe7aac614a42264f4140a3fc1ec2b6da3b9158a Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 18 Mar 2014 18:04:01 -0400 Subject: [PATCH 07/13] [IMP]Fix bug to pass tests --- document_multiple_records/document.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index 48ebb228..3c8af5cc 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -36,9 +36,9 @@ class document_file(orm.Model): 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'] = '' + data['res_model'] = '' if data['res_model'] else False + data['res_id'] = '' if data['res_id'] else False + data['res_name'] = '' if data['res_name'] else False 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: From a9a91394ef84d71086dc8da05c3da661ff940572 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 18 Mar 2014 18:23:28 -0400 Subject: [PATCH 08/13] [IMP]Change condition to pass test --- document_multiple_records/document.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index 3c8af5cc..5d72efe4 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -36,9 +36,12 @@ class document_file(orm.Model): 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'] = '' if data['res_model'] else False - data['res_id'] = '' if data['res_id'] else False - data['res_name'] = '' if data['res_name'] else False + if data['res_model']: + data['res_model'] = '' + if data['res_id']: + data['res_id'] = '' + if data['res_name']: + 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: From 6e5f52a548a5d95b7625e9ba02bb99c358fbe6d8 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Wed, 19 Mar 2014 11:30:13 -0400 Subject: [PATCH 09/13] [IMP]Change condition to pass test --- document_multiple_records/document.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index 5d72efe4..e9dbc0af 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -36,12 +36,10 @@ class document_file(orm.Model): 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 - if data['res_model']: - data['res_model'] = '' - if data['res_id']: - data['res_id'] = '' - if data['res_name']: - data['res_name'] = '' + if ('res_name', 'res_id', 'res_name') in data.keys(): + data['res_model'] = False + data['res_id'] = False + data['res_name'] = False 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: From 4069f2bedb3300746c993054ece27ba32d648cfd Mon Sep 17 00:00:00 2001 From: Marc Cassuto Date: Tue, 25 Mar 2014 11:12:24 -0400 Subject: [PATCH 10/13] [i18n] Added french translations --- document_multiple_records/i18n/fr.po | 141 +++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 document_multiple_records/i18n/fr.po diff --git a/document_multiple_records/i18n/fr.po b/document_multiple_records/i18n/fr.po new file mode 100644 index 00000000..7213da8a --- /dev/null +++ b/document_multiple_records/i18n/fr.po @@ -0,0 +1,141 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * document_multiple_records +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-06 19:28+0000\n" +"PO-Revision-Date: 2014-03-25 02:56-0500\n" +"Last-Translator: Marc Cassuto \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.5.4\n" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_id:0 +msgid "Resource ID" +msgstr "Identifiant de la ressource" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Select document(s)" +msgstr "Choisir un(des) document(s)" + +#. module: document_multiple_records +#. openerp-web +#: code:addons/document_multiple_records/static/src/xml/document.xml:7 +#, python-format +msgid "Add existing Doc..." +msgstr "Ajouter un document existant..." + +#. module: document_multiple_records +#: field:ir.attachment.document,attachment_id:0 +msgid "Attachment" +msgstr "Document joint" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "AttachmentDocumentWizardTree" +msgstr "AttachmentDocumentWizardTree" + +#. module: document_multiple_records +#. openerp-web +#: code:addons/document_multiple_records/static/src/js/document.js:26 +#: model:ir.actions.act_window,name:document_multiple_records.action_view_document +#: view:ir.attachment.wizard:0 +#, python-format +msgid "Add Document" +msgstr "Ajouter un document" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_name:0 +msgid "Resource Name" +msgstr "Nom de la ressource" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment_document +msgid "Attachment Documents" +msgstr "Documents joints" + +#. module: document_multiple_records +#: field:ir.attachment,attachmentdocument_ids:0 +msgid "Records" +msgstr "Enregistrements" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "AttachmentDocumentTree" +msgstr "AttachmentDocumentTree" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment +msgid "ir.attachment" +msgstr "ir.attachment" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "Indexed Content" +msgstr "Contenu indexé" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment_wizard +msgid "Attachment wizard" +msgstr "Assistant" + +#. module: document_multiple_records +#: view:ir.attachment:0 +msgid "AttachmentDocumentForm" +msgstr "AttachmentDocumentForm" + +#. module: document_multiple_records +#: code:addons/document_multiple_records/wizard/document_wizard.py:46 +#, python-format +msgid "Error" +msgstr "Erreur" + +#. module: document_multiple_records +#: help:ir.attachment.document,res_model:0 +msgid "The database object this attachment will be attached to" +msgstr "L'objet de la base de données auquel ce document sera attaché" + +#. module: document_multiple_records +#: help:ir.attachment.document,res_id:0 +msgid "The record id this is attached to." +msgstr "L'identifiant de l'enregistrement auquel est ce document est joint." + +#. module: document_multiple_records +#: field:ir.attachment.wizard,attachment_ids:0 +msgid "Attachments" +msgstr "Documents joints" + +#. module: document_multiple_records +#: field:ir.attachment.document,res_model:0 +msgid "Resource Model" +msgstr "Modèle" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Cancel" +msgstr "Annuler" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "Apply" +msgstr "Appliquer" + +#. module: document_multiple_records +#: view:ir.attachment.wizard:0 +msgid "or" +msgstr "ou" + +#. module: document_multiple_records +#: code:addons/document_multiple_records/wizard/document_wizard.py:47 +#, python-format +msgid "You have to select at least 1 Document. And try again" +msgstr "Vous devez sélectionner au moins un document et essayer de nouveau." + From f6e2f1eab18dfeb030717c1766f0a290de3c07ac Mon Sep 17 00:00:00 2001 From: Marc Cassuto Date: Tue, 25 Mar 2014 14:34:43 -0400 Subject: [PATCH 11/13] [i18n] Updated french translations --- document_multiple_records/i18n/fr.po | 66 ++++++++++++++++------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/document_multiple_records/i18n/fr.po b/document_multiple_records/i18n/fr.po index 7213da8a..707eb07c 100644 --- a/document_multiple_records/i18n/fr.po +++ b/document_multiple_records/i18n/fr.po @@ -6,10 +6,11 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-02-06 19:28+0000\n" -"PO-Revision-Date: 2014-03-25 02:56-0500\n" +"POT-Creation-Date: 2014-03-25 18:24+0000\n" +"PO-Revision-Date: 2014-03-25 14:27-0500\n" "Last-Translator: Marc Cassuto \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -22,35 +23,26 @@ msgid "Resource ID" msgstr "Identifiant de la ressource" #. module: document_multiple_records -#: view:ir.attachment.wizard:0 +#: view:ir.attachment.existing.doc:0 msgid "Select document(s)" msgstr "Choisir un(des) document(s)" -#. module: document_multiple_records -#. openerp-web -#: code:addons/document_multiple_records/static/src/xml/document.xml:7 -#, python-format -msgid "Add existing Doc..." -msgstr "Ajouter un document existant..." - #. module: document_multiple_records #: field:ir.attachment.document,attachment_id:0 msgid "Attachment" msgstr "Document joint" #. module: document_multiple_records -#: view:ir.attachment.wizard:0 +#: view:ir.attachment.existing.doc:0 msgid "AttachmentDocumentWizardTree" msgstr "AttachmentDocumentWizardTree" #. module: document_multiple_records #. openerp-web -#: code:addons/document_multiple_records/static/src/js/document.js:26 -#: model:ir.actions.act_window,name:document_multiple_records.action_view_document -#: view:ir.attachment.wizard:0 +#: code:addons/document_multiple_records/static/src/js/document.js:42 #, python-format -msgid "Add Document" -msgstr "Ajouter un document" +msgid "Uploading Error" +msgstr "Erreur lors du transfert" #. module: document_multiple_records #: field:ir.attachment.document,res_name:0 @@ -63,7 +55,7 @@ msgid "Attachment Documents" msgstr "Documents joints" #. module: document_multiple_records -#: field:ir.attachment,attachmentdocument_ids:0 +#: field:ir.attachment,attachment_document_ids:0 msgid "Records" msgstr "Enregistrements" @@ -82,18 +74,13 @@ msgstr "ir.attachment" msgid "Indexed Content" msgstr "Contenu indexé" -#. module: document_multiple_records -#: model:ir.model,name:document_multiple_records.model_ir_attachment_wizard -msgid "Attachment wizard" -msgstr "Assistant" - #. module: document_multiple_records #: view:ir.attachment:0 msgid "AttachmentDocumentForm" msgstr "AttachmentDocumentForm" #. module: document_multiple_records -#: code:addons/document_multiple_records/wizard/document_wizard.py:46 +#: code:addons/document_multiple_records/wizard/document_wizard.py:48 #, python-format msgid "Error" msgstr "Erreur" @@ -109,33 +96,56 @@ msgid "The record id this is attached to." msgstr "L'identifiant de l'enregistrement auquel est ce document est joint." #. module: document_multiple_records -#: field:ir.attachment.wizard,attachment_ids:0 +#. openerp-web +#: code:addons/document_multiple_records/static/src/js/document.js:25 +#: model:ir.actions.act_window,name:document_multiple_records.action_view_document +#: view:ir.attachment.existing.doc:0 +#, python-format +msgid "Add existing document/attachment" +msgstr "Ajouter un document déjà joint dans le système" + +#. module: document_multiple_records +#: model:ir.model,name:document_multiple_records.model_ir_attachment_existing_doc +msgid "Add existing document/attachment wizard" +msgstr "Assistant pour ajouter un document déjà joint dans le système" + +#. module: document_multiple_records +#: field:ir.attachment.existing.doc,attachment_ids:0 msgid "Attachments" msgstr "Documents joints" +#. module: document_multiple_records +#. openerp-web +#: code:addons/document_multiple_records/static/src/xml/document.xml:7 +#, python-format +msgid "Add existing document/attachment..." +msgstr "Ajouter un document déjà joint dans le système..." + #. module: document_multiple_records #: field:ir.attachment.document,res_model:0 msgid "Resource Model" msgstr "Modèle" #. module: document_multiple_records -#: view:ir.attachment.wizard:0 +#: view:ir.attachment.existing.doc:0 msgid "Cancel" msgstr "Annuler" #. module: document_multiple_records -#: view:ir.attachment.wizard:0 +#: view:ir.attachment.existing.doc:0 msgid "Apply" msgstr "Appliquer" #. module: document_multiple_records -#: view:ir.attachment.wizard:0 +#: view:ir.attachment.existing.doc:0 msgid "or" msgstr "ou" #. module: document_multiple_records -#: code:addons/document_multiple_records/wizard/document_wizard.py:47 +#: code:addons/document_multiple_records/wizard/document_wizard.py:49 #, python-format msgid "You have to select at least 1 Document. And try again" msgstr "Vous devez sélectionner au moins un document et essayer de nouveau." +#~ msgid "Add Document" +#~ msgstr "Ajouter un document" From 94f14442131bfba274b68feaedc8edd4c8c02d91 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Wed, 16 Apr 2014 19:17:38 -0400 Subject: [PATCH 12/13] Add missing access rights --- document_multiple_records/security/ir.model.access.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/document_multiple_records/security/ir.model.access.csv b/document_multiple_records/security/ir.model.access.csv index a6d92b57..6920471b 100644 --- a/document_multiple_records/security/ir.model.access.csv +++ b/document_multiple_records/security/ir.model.access.csv @@ -1,2 +1,3 @@ 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 +access_ir_attachment_existing_doc,access_ir_attachment_existing_doc,model_ir_attachment_existing_doc,base.group_document_user,1,1,1,1 From 3f9ea85e4549f56a3f5e696ba2e157c5fdca36dd Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Wed, 16 Apr 2014 20:24:17 -0400 Subject: [PATCH 13/13] Cleanup code and fix possible bugs create(): Avoid duplicating data locally Fix boolean comparison problem Use name_get rather than name field unlink(): Use more specific context identifiers Remove redundant loop and if statement model: Add ondelete='cascade' --- document_multiple_records/document.py | 53 ++++++++----------- .../static/src/js/document.js | 4 +- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/document_multiple_records/document.py b/document_multiple_records/document.py index e9dbc0af..f576819b 100644 --- a/document_multiple_records/document.py +++ b/document_multiple_records/document.py @@ -34,26 +34,18 @@ class document_file(orm.Model): def create(self, cr, uid, data, context=None): 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 - if ('res_name', 'res_id', 'res_name') in data.keys(): - data['res_model'] = False - data['res_id'] = False - data['res_name'] = False 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 = { + if 'res_model' in data and 'res_id' in data: + ir_attachment_document_obj.create(cr, uid, { 'attachment_id': res, - '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) + 'res_model': data['res_model'], + 'res_id': data['res_id'], + 'res_name': data.get( + 'res_name', self.pool.get(data['res_model']).browse( + cr, uid, data['res_id'], + context=context).name_get()[0][1]), + }, context=context) return res def unlink(self, cr, uid, ids, context=None, check=True): @@ -61,16 +53,18 @@ class document_file(orm.Model): 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: - query = [ - ('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) - result = ir_attach_doc_obj.unlink(cr, uid, id_to_unlink, context=context) + res_model = context.get('multiple_records_res_model') + res_id = context.get('multiple_records_res_id') + if res_model and res_id: + query = [ + ('res_model', '=', res_model), + ('res_id', '=', res_id), + ('attachment_id', 'in', ids), + ] + ids_to_unlink = ir_attach_doc_obj.search( + cr, uid, query, context=context) + result = ir_attach_doc_obj.unlink( + cr, uid, ids_to_unlink, context=context) else: # Normal delete result = super(document_file, self).unlink(cr, uid, ids, context=context) @@ -90,7 +84,6 @@ class ir_attachment_document(orm.Model): 'res_name': fields.char('Resource Name', type='char', size=128, readonly=True), - 'attachment_id': fields.many2one('ir.attachment', 'Attachment'), + 'attachment_id': fields.many2one( + 'ir.attachment', 'Attachment', ondelete='cascade'), } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_multiple_records/static/src/js/document.js b/document_multiple_records/static/src/js/document.js index 7eafe28a..e8808e81 100644 --- a/document_multiple_records/static/src/js/document.js +++ b/document_multiple_records/static/src/js/document.js @@ -49,8 +49,8 @@ var _t = instance.web._t, 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], + 'multiple_records_res_model': self.model_view, + 'multiple_records_res_id': ids[0], }; var $e = $(e.currentTarget); if (confirm(_t("Do you really want to delete this attachment ?"))) {