Merge lp:~savoirfairelinux-openerp/knowledge-addons/document_multiple_records into lp:knowledge-addons/7.0

Status: Rejected
Rejected by: Sandy Carter (http://www.savoirfairelinux.com)
Proposed branch: lp:~savoirfairelinux-openerp/knowledge-addons/document_multiple_records
Merge into: lp:knowledge-addons/7.0
Diff against target: 782 lines (+715/-0)
12 files modified
document_multiple_records/__init__.py (+26/-0)
document_multiple_records/__openerp__.py (+60/-0)
document_multiple_records/document.py (+89/-0)
document_multiple_records/document_view.xml (+30/-0)
document_multiple_records/i18n/document_multiple_records.pot (+140/-0)
document_multiple_records/i18n/fr.po (+151/-0)
document_multiple_records/security/ir.model.access.csv (+3/-0)
document_multiple_records/static/src/js/document.js (+79/-0)
document_multiple_records/static/src/xml/document.xml (+10/-0)
document_multiple_records/wizard/__init__.py (+25/-0)
document_multiple_records/wizard/document_wizard.py (+61/-0)
document_multiple_records/wizard/document_wizard_view.xml (+41/-0)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/knowledge-addons/document_multiple_records
Reviewer Review Type Date Requested Status
Sandy Carter (http://www.savoirfairelinux.com) Needs Resubmitting
Holger Brunn (Therp) code review Approve
OpenERP Community Reviewer/Maintainer Pending
Review via email: mp+206960@code.launchpad.net

Description of the change

Added document_multiple_records module: It allows to manage a document with a multiple records.

To post a comment you must log in.
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Please fix according to https://code.launchpad.net/~savoirfairelinux-openerp/knowledge-addons/add_document_multiple_records/+merge/205249/comments/481345

Holger Brunn (Therp) (hbrunn) wrote on 2014-02-10:

I think you should follow the rule to put models into the subdir model, with one file per model.

#29 why no local import here?
#135ff could you explain those lines? To me it seems we leave stuff in the database there that we don't want
#363 comment
#377 this text seems quite misleading. How about 'Add existing document/attachment'?
$470 ir.attachment.wizard seems a very generic name, I think you should use something more specific to what you do.

Further I don't see where you do any refcount. How do you take care that if attachment A is linked to records R1, R2 and R3, A stays if I delete R1 and R2, but will be deleted when I delete R3?

And how do you deal with attachments being only visible to people who have read permissions on the document given in res_model/res_id? I think you'll have to override that to also take the other linked records into account.

For usability, I'd also add a function field that combines res_model and res_id to a reference field.

review: Needs Fixing (code review, no test)
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) :
review: Approve (code review, test)
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks for taking some of my points into account. A new iteration:

#138 use .copy() for a shallow copy of a dict
#138, #140 'in' applied to dicts checks for keys, no need to create a new keys() list
#154 not all models declare a name property, consider using name_get()
#165 this context keys are very general. Better use some prefix to avoid unintentional clashes
#166ff why the loop?
#171 this yields a warning, better use 'in'
#194 add ondelete='cascade'

And please push your changes over the current branch, otherwise you'll lose all comments as last time

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

...that should be 'needs fixing'

review: Needs Fixing (code review)
25. By Marc Cassuto (SFL)

[i18n] Added french translations

26. By Marc Cassuto (SFL)

[i18n] Updated french translations

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

@Holger, took your comments into consideration

Taking myself out of the Reviewer list since I have contributed.

review: Abstain
27. By Sandy Carter (http://www.savoirfairelinux.com)

Add missing access rights

28. By Sandy Carter (http://www.savoirfairelinux.com)

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'

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks! I think to make this module great, we still need to delete otherwise orphaned attachments when deleting the last referring record. But that's perfectly fine to do in version 0.2

review: Approve (code review)
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) :
review: Approve
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

This MP have been moved to MP to https://github.com/OCA/knowledge/pull/5

review: Needs Resubmitting

Unmerged revisions

28. By Sandy Carter (http://www.savoirfairelinux.com)

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'

27. By Sandy Carter (http://www.savoirfairelinux.com)

Add missing access rights

26. By Marc Cassuto (SFL)

[i18n] Updated french translations

25. By Marc Cassuto (SFL)

[i18n] Added french translations

24. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP]Change condition to pass test

23. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP]Change condition to pass test

22. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP]Fix bug to pass tests

21. By El Hadji Dem (http://www.savoirfairelinux.com)

[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

20. By Joao Alfredo Gama Batista

[IMP] More clear message for the user

19. By Joao Alfredo Gama Batista

[FIX] Use attachment_document_ids to get list of attachments

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'document_multiple_records'
=== added file 'document_multiple_records/__init__.py'
--- document_multiple_records/__init__.py 1970-01-01 00:00:00 +0000
+++ document_multiple_records/__init__.py 2014-04-17 00:23:10 +0000
@@ -0,0 +1,26 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23from . import document
24from . import wizard
25
26# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
027
=== added file 'document_multiple_records/__openerp__.py'
--- document_multiple_records/__openerp__.py 1970-01-01 00:00:00 +0000
+++ document_multiple_records/__openerp__.py 2014-04-17 00:23:10 +0000
@@ -0,0 +1,60 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': 'Document Management System for Multiple Records',
25 'version': '0.1',
26 'category': 'Knowledge Management',
27 'summary': 'Document Management System for Multiple Records',
28 'description': """
29Document Management System for Multiple Records
30==============================================
31
32Contributors
33------------
34* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
35""",
36 'author': 'Savoir-faire Linux',
37 'website': 'www.savoirfairelinux.com',
38 'license': 'AGPL-3',
39 'depends': [
40 'document',
41 ],
42 'data': [
43 'document_view.xml',
44 'security/ir.model.access.csv',
45 'wizard/document_wizard_view.xml',
46 ],
47 'js': [
48 'static/src/js/document.js'
49 ],
50 'qweb': [
51 'static/src/xml/document.xml'
52 ],
53 'test': [],
54 'demo': [
55 ],
56 'installable': True,
57 'auto_install': False,
58}
59
60# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
061
=== added file 'document_multiple_records/document.py'
--- document_multiple_records/document.py 1970-01-01 00:00:00 +0000
+++ document_multiple_records/document.py 2014-04-17 00:23:10 +0000
@@ -0,0 +1,89 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import orm, fields
24
25
26class document_file(orm.Model):
27 _inherit = 'ir.attachment'
28
29 _columns = {
30 'attachment_document_ids': fields.one2many('ir.attachment.document',
31 'attachment_id',
32 'Records'),
33 }
34
35 def create(self, cr, uid, data, context=None):
36 ir_attachment_document_obj = self.pool.get('ir.attachment.document')
37 res = super(document_file, self).create(cr, uid, data, context=context)
38 # Create attachment_document_ids with res_model, res_id and res_name
39 if 'res_model' in data and 'res_id' in data:
40 ir_attachment_document_obj.create(cr, uid, {
41 'attachment_id': res,
42 'res_model': data['res_model'],
43 'res_id': data['res_id'],
44 'res_name': data.get(
45 'res_name', self.pool.get(data['res_model']).browse(
46 cr, uid, data['res_id'],
47 context=context).name_get()[0][1]),
48 }, context=context)
49 return res
50
51 def unlink(self, cr, uid, ids, context=None, check=True):
52 ir_attach_doc_obj = self.pool.get('ir.attachment.document')
53 if context is None:
54 context = {}
55 # Deleting from dropdown list in the form view
56 res_model = context.get('multiple_records_res_model')
57 res_id = context.get('multiple_records_res_id')
58 if res_model and res_id:
59 query = [
60 ('res_model', '=', res_model),
61 ('res_id', '=', res_id),
62 ('attachment_id', 'in', ids),
63 ]
64 ids_to_unlink = ir_attach_doc_obj.search(
65 cr, uid, query, context=context)
66 result = ir_attach_doc_obj.unlink(
67 cr, uid, ids_to_unlink, context=context)
68 else:
69 # Normal delete
70 result = super(document_file, self).unlink(cr, uid, ids, context=context)
71 return result
72
73
74class ir_attachment_document(orm.Model):
75 _description = 'Attachment Documents'
76 _name = 'ir.attachment.document'
77
78 _columns = {
79 'res_id': fields.integer('Resource ID', readonly=True,
80 help="The record id this is attached to."),
81 'res_model': fields.char('Resource Model', size=64,
82 readonly=True,
83 help="The database object this attachment will be attached to"),
84 'res_name': fields.char('Resource Name', type='char',
85 size=128,
86 readonly=True),
87 'attachment_id': fields.many2one(
88 'ir.attachment', 'Attachment', ondelete='cascade'),
89 }
090
=== added file 'document_multiple_records/document_view.xml'
--- document_multiple_records/document_view.xml 1970-01-01 00:00:00 +0000
+++ document_multiple_records/document_view.xml 2014-04-17 00:23:10 +0000
@@ -0,0 +1,30 @@
1<?xml version="1.0"?>
2<openerp>
3<data>
4 <!--Add model list field-->
5 <record model="ir.ui.view" id="view_document_file_multiple_models_form">
6 <field name="name">ir.attachment.multiple.models</field>
7 <field name="model">ir.attachment</field>
8 <field name="inherit_id" ref="document.view_document_file_form"/>
9 <field name="arch" type="xml">
10 <group string="Indexed Content" position="after">
11 <group col="2" colspan="4">
12 <field name="attachment_document_ids" nolabel="1">
13 <tree string="AttachmentDocumentTree" create="false" version="7.0">
14 <field name="res_model"/>
15 <field name="res_id"/>
16 <field name="res_name"/>
17 </tree>
18 <form string="AttachmentDocumentForm">
19 <field name="res_model"/>
20 <field name="res_id"/>
21 <field name="res_name"/>
22 </form>
23 </field>
24 </group>
25 </group>
26 </field>
27 </record>
28</data>
29</openerp>
30
031
=== added directory 'document_multiple_records/i18n'
=== added file 'document_multiple_records/i18n/document_multiple_records.pot'
--- document_multiple_records/i18n/document_multiple_records.pot 1970-01-01 00:00:00 +0000
+++ document_multiple_records/i18n/document_multiple_records.pot 2014-04-17 00:23:10 +0000
@@ -0,0 +1,140 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * document_multiple_records
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-02-06 19:28+0000\n"
10"PO-Revision-Date: 2014-02-06 14:29-0500\n"
11"Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: 8bit\n"
16"Plural-Forms: \n"
17"X-Generator: Poedit 1.5.4\n"
18
19#. module: document_multiple_records
20#: field:ir.attachment.document,res_id:0
21msgid "Resource ID"
22msgstr ""
23
24#. module: document_multiple_records
25#: view:ir.attachment.wizard:0
26msgid "Select document(s)"
27msgstr ""
28
29#. module: document_multiple_records
30#. openerp-web
31#: code:addons/document_multiple_records/static/src/xml/document.xml:7
32#, python-format
33msgid "Add existing Doc..."
34msgstr ""
35
36#. module: document_multiple_records
37#: field:ir.attachment.document,attachment_id:0
38msgid "Attachment"
39msgstr ""
40
41#. module: document_multiple_records
42#: view:ir.attachment.wizard:0
43msgid "AttachmentDocumentWizardTree"
44msgstr ""
45
46#. module: document_multiple_records
47#. openerp-web
48#: code:addons/document_multiple_records/static/src/js/document.js:26
49#: model:ir.actions.act_window,name:document_multiple_records.action_view_document
50#: view:ir.attachment.wizard:0
51#, python-format
52msgid "Add Document"
53msgstr ""
54
55#. module: document_multiple_records
56#: field:ir.attachment.document,res_name:0
57msgid "Resource Name"
58msgstr ""
59
60#. module: document_multiple_records
61#: model:ir.model,name:document_multiple_records.model_ir_attachment_document
62msgid "Attachment Documents"
63msgstr ""
64
65#. module: document_multiple_records
66#: field:ir.attachment,attachmentdocument_ids:0
67msgid "Records"
68msgstr ""
69
70#. module: document_multiple_records
71#: view:ir.attachment:0
72msgid "AttachmentDocumentTree"
73msgstr ""
74
75#. module: document_multiple_records
76#: model:ir.model,name:document_multiple_records.model_ir_attachment
77msgid "ir.attachment"
78msgstr ""
79
80#. module: document_multiple_records
81#: view:ir.attachment:0
82msgid "Indexed Content"
83msgstr ""
84
85#. module: document_multiple_records
86#: model:ir.model,name:document_multiple_records.model_ir_attachment_wizard
87msgid "Attachment wizard"
88msgstr ""
89
90#. module: document_multiple_records
91#: view:ir.attachment:0
92msgid "AttachmentDocumentForm"
93msgstr ""
94
95#. module: document_multiple_records
96#: code:addons/document_multiple_records/wizard/document_wizard.py:46
97#, python-format
98msgid "Error"
99msgstr ""
100
101#. module: document_multiple_records
102#: help:ir.attachment.document,res_model:0
103msgid "The database object this attachment will be attached to"
104msgstr ""
105
106#. module: document_multiple_records
107#: help:ir.attachment.document,res_id:0
108msgid "The record id this is attached to."
109msgstr ""
110
111#. module: document_multiple_records
112#: field:ir.attachment.wizard,attachment_ids:0
113msgid "Attachments"
114msgstr ""
115
116#. module: document_multiple_records
117#: field:ir.attachment.document,res_model:0
118msgid "Resource Model"
119msgstr ""
120
121#. module: document_multiple_records
122#: view:ir.attachment.wizard:0
123msgid "Cancel"
124msgstr ""
125
126#. module: document_multiple_records
127#: view:ir.attachment.wizard:0
128msgid "Apply"
129msgstr ""
130
131#. module: document_multiple_records
132#: view:ir.attachment.wizard:0
133msgid "or"
134msgstr ""
135
136#. module: document_multiple_records
137#: code:addons/document_multiple_records/wizard/document_wizard.py:47
138#, python-format
139msgid "You have to select at least 1 Document. And try again"
140msgstr ""
0141
=== added file 'document_multiple_records/i18n/fr.po'
--- document_multiple_records/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ document_multiple_records/i18n/fr.po 2014-04-17 00:23:10 +0000
@@ -0,0 +1,151 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * document_multiple_records
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-03-25 18:24+0000\n"
10"PO-Revision-Date: 2014-03-25 14:27-0500\n"
11"Last-Translator: Marc Cassuto <marc.cassuto@savoirfairelinux.com>\n"
12"Language-Team: \n"
13"Language: \n"
14"MIME-Version: 1.0\n"
15"Content-Type: text/plain; charset=UTF-8\n"
16"Content-Transfer-Encoding: 8bit\n"
17"Plural-Forms: \n"
18"X-Generator: Poedit 1.5.4\n"
19
20#. module: document_multiple_records
21#: field:ir.attachment.document,res_id:0
22msgid "Resource ID"
23msgstr "Identifiant de la ressource"
24
25#. module: document_multiple_records
26#: view:ir.attachment.existing.doc:0
27msgid "Select document(s)"
28msgstr "Choisir un(des) document(s)"
29
30#. module: document_multiple_records
31#: field:ir.attachment.document,attachment_id:0
32msgid "Attachment"
33msgstr "Document joint"
34
35#. module: document_multiple_records
36#: view:ir.attachment.existing.doc:0
37msgid "AttachmentDocumentWizardTree"
38msgstr "AttachmentDocumentWizardTree"
39
40#. module: document_multiple_records
41#. openerp-web
42#: code:addons/document_multiple_records/static/src/js/document.js:42
43#, python-format
44msgid "Uploading Error"
45msgstr "Erreur lors du transfert"
46
47#. module: document_multiple_records
48#: field:ir.attachment.document,res_name:0
49msgid "Resource Name"
50msgstr "Nom de la ressource"
51
52#. module: document_multiple_records
53#: model:ir.model,name:document_multiple_records.model_ir_attachment_document
54msgid "Attachment Documents"
55msgstr "Documents joints"
56
57#. module: document_multiple_records
58#: field:ir.attachment,attachment_document_ids:0
59msgid "Records"
60msgstr "Enregistrements"
61
62#. module: document_multiple_records
63#: view:ir.attachment:0
64msgid "AttachmentDocumentTree"
65msgstr "AttachmentDocumentTree"
66
67#. module: document_multiple_records
68#: model:ir.model,name:document_multiple_records.model_ir_attachment
69msgid "ir.attachment"
70msgstr "ir.attachment"
71
72#. module: document_multiple_records
73#: view:ir.attachment:0
74msgid "Indexed Content"
75msgstr "Contenu indexé"
76
77#. module: document_multiple_records
78#: view:ir.attachment:0
79msgid "AttachmentDocumentForm"
80msgstr "AttachmentDocumentForm"
81
82#. module: document_multiple_records
83#: code:addons/document_multiple_records/wizard/document_wizard.py:48
84#, python-format
85msgid "Error"
86msgstr "Erreur"
87
88#. module: document_multiple_records
89#: help:ir.attachment.document,res_model:0
90msgid "The database object this attachment will be attached to"
91msgstr "L'objet de la base de données auquel ce document sera attaché"
92
93#. module: document_multiple_records
94#: help:ir.attachment.document,res_id:0
95msgid "The record id this is attached to."
96msgstr "L'identifiant de l'enregistrement auquel est ce document est joint."
97
98#. module: document_multiple_records
99#. openerp-web
100#: code:addons/document_multiple_records/static/src/js/document.js:25
101#: model:ir.actions.act_window,name:document_multiple_records.action_view_document
102#: view:ir.attachment.existing.doc:0
103#, python-format
104msgid "Add existing document/attachment"
105msgstr "Ajouter un document déjà joint dans le système"
106
107#. module: document_multiple_records
108#: model:ir.model,name:document_multiple_records.model_ir_attachment_existing_doc
109msgid "Add existing document/attachment wizard"
110msgstr "Assistant pour ajouter un document déjà joint dans le système"
111
112#. module: document_multiple_records
113#: field:ir.attachment.existing.doc,attachment_ids:0
114msgid "Attachments"
115msgstr "Documents joints"
116
117#. module: document_multiple_records
118#. openerp-web
119#: code:addons/document_multiple_records/static/src/xml/document.xml:7
120#, python-format
121msgid "Add existing document/attachment..."
122msgstr "Ajouter un document déjà joint dans le système..."
123
124#. module: document_multiple_records
125#: field:ir.attachment.document,res_model:0
126msgid "Resource Model"
127msgstr "Modèle"
128
129#. module: document_multiple_records
130#: view:ir.attachment.existing.doc:0
131msgid "Cancel"
132msgstr "Annuler"
133
134#. module: document_multiple_records
135#: view:ir.attachment.existing.doc:0
136msgid "Apply"
137msgstr "Appliquer"
138
139#. module: document_multiple_records
140#: view:ir.attachment.existing.doc:0
141msgid "or"
142msgstr "ou"
143
144#. module: document_multiple_records
145#: code:addons/document_multiple_records/wizard/document_wizard.py:49
146#, python-format
147msgid "You have to select at least 1 Document. And try again"
148msgstr "Vous devez sélectionner au moins un document et essayer de nouveau."
149
150#~ msgid "Add Document"
151#~ msgstr "Ajouter un document"
0152
=== added directory 'document_multiple_records/security'
=== added file 'document_multiple_records/security/ir.model.access.csv'
--- document_multiple_records/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ document_multiple_records/security/ir.model.access.csv 2014-04-17 00:23:10 +0000
@@ -0,0 +1,3 @@
1id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2access_ir_attachment_document_group_user,ir.attachment.document user,model_ir_attachment_document,base.group_document_user,1,1,1,1
3access_ir_attachment_existing_doc,access_ir_attachment_existing_doc,model_ir_attachment_existing_doc,base.group_document_user,1,1,1,1
04
=== added directory 'document_multiple_records/static'
=== added directory 'document_multiple_records/static/src'
=== added directory 'document_multiple_records/static/src/js'
=== added file 'document_multiple_records/static/src/js/document.js'
--- document_multiple_records/static/src/js/document.js 1970-01-01 00:00:00 +0000
+++ document_multiple_records/static/src/js/document.js 2014-04-17 00:23:10 +0000
@@ -0,0 +1,79 @@
1openerp.document_multiple_records = function(instance, m) {
2var _t = instance.web._t,
3 QWeb = instance.web.qweb;
4
5 instance.web.Sidebar.include({
6 redraw: function() {
7 var self = this;
8 this._super.apply(this, arguments);
9 self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddDocfromserver', {widget: self}))
10 self.$el.find('.open').on('click', function (e) {
11 self.on_call_new_view_function();
12 });
13 },
14 on_call_new_view_function: function(state) {
15 var self = this;
16 var view = self.getParent();
17 var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
18 // you can pass in other data using the context dictionary variable
19 var context = {
20 'model': view.dataset.model,
21 'ids': ids,
22 };
23 // the action dictionary variable sends data in the "self.do_action" method
24 var action = {
25 name: _t("Add existing document"),
26 type: 'ir.actions.act_window',
27 res_model: 'ir.attachment.existing.doc',
28 view_mode: 'form',
29 view_type: 'form',
30 views: [[false, 'form']],
31 target: 'new',
32 context: context,
33 };
34 // self.do_action accepts the action parameter and opens the new view
35 self.do_action(action, {
36 // refresh list of documents
37 on_close: function () {
38 self.do_attachement_update(self.dataset, self.model_id);
39 }
40 });
41
42 },
43 on_attachment_delete: function(e) {
44 e.preventDefault();
45 e.stopPropagation();
46 var self = this;
47 var view = self.getParent();
48 self.model_view = view.dataset.model
49 var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
50 // Context dictionary variable
51 var context = {
52 'multiple_records_res_model': self.model_view,
53 'multiple_records_res_id': ids[0],
54 };
55 var $e = $(e.currentTarget);
56 if (confirm(_t("Do you really want to delete this attachment ?"))) {
57 (new instance.web.DataSet(this, 'ir.attachment', context)).unlink([parseInt($e.attr('data-id'), 10)]).done(function() {
58 self.do_attachement_update(self.dataset, self.model_id);
59 });
60 }
61 },
62 do_attachement_update: function(dataset, model_id, args) {
63 var self = this;
64 this.dataset = dataset;
65 this.model_id = model_id;
66 if (args && args[0].error) {
67 this.do_warn(_t('Uploading Error'), args[0].error);
68 }
69 if (!model_id) {
70 this.on_attachments_loaded([]);
71 }
72 else {
73 var dom = [ ['attachment_document_ids.res_model', '=', dataset.model], ['attachment_document_ids.res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
74 var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
75 ds.read_slice(['name', 'url', 'type', 'create_uid', 'create_date', 'write_uid', 'write_date'], {}).done(this.on_attachments_loaded);
76 }
77 }
78 });
79};
080
=== added directory 'document_multiple_records/static/src/xml'
=== added file 'document_multiple_records/static/src/xml/document.xml'
--- document_multiple_records/static/src/xml/document.xml 1970-01-01 00:00:00 +0000
+++ document_multiple_records/static/src/xml/document.xml 2014-04-17 00:23:10 +0000
@@ -0,0 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- vim:fdl=1:
3-->
4<templates id="template" xml:space="preserve">
5
6<t t-name="AddDocfromserver">
7 <li class="open"><span><b>Add existing document...</b></span></li>
8</t>
9
10</templates>
011
=== added directory 'document_multiple_records/wizard'
=== added file 'document_multiple_records/wizard/__init__.py'
--- document_multiple_records/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ document_multiple_records/wizard/__init__.py 2014-04-17 00:23:10 +0000
@@ -0,0 +1,25 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import document_wizard
24
25# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
026
=== added file 'document_multiple_records/wizard/document_wizard.py'
--- document_multiple_records/wizard/document_wizard.py 1970-01-01 00:00:00 +0000
+++ document_multiple_records/wizard/document_wizard.py 2014-04-17 00:23:10 +0000
@@ -0,0 +1,61 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import fields, orm
24from openerp.tools.translate import _
25
26
27class document_wizard(orm.Model):
28 _name = "ir.attachment.existing.doc"
29 _description = "Add existing document/attachment wizard"
30 _columns = {
31 'attachment_ids': fields.many2many('ir.attachment',
32 'document_attachment_rel',
33 'wizard_id',
34 'attachment_id',
35 'Attachments'),
36 }
37
38 def action_apply(self, cr, uid, ids, context=None):
39 if context is None:
40 context = {}
41 ir_attach_obj = self.pool.get('ir.attachment')
42 ir_attach_doc_obj = self.pool.get('ir.attachment.document')
43 ir_model_obj = self.pool.get(context.get('model') or context.get('active_model'))
44
45 name = ir_model_obj.browse(cr, uid, context.get('ids') or context.get('active_ids'), context=context)[0]['name']
46 data = self.read(cr, uid, ids, [], context=context)[0]
47 if not data['attachment_ids']:
48 raise orm.except_orm(_('Error'),
49 _('You have to select at least 1 Document. And try again'))
50 for attach in ir_attach_obj.browse(cr, uid, data['attachment_ids'], context=context):
51 data_attach = {
52 'res_model': context.get('model') or context.get('active_model'),
53 'res_id': context.get('ids') and context.get('ids')[0] or context.get('active_id'),
54 'res_name': name,
55 'attachment_id': attach.id,
56 }
57 #Created attachment_document_ids
58 ir_attach_doc_obj.create(cr, uid, data_attach, context=context)
59 return {'type': 'ir.actions.act_window_close'}
60
61# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
062
=== added file 'document_multiple_records/wizard/document_wizard_view.xml'
--- document_multiple_records/wizard/document_wizard_view.xml 1970-01-01 00:00:00 +0000
+++ document_multiple_records/wizard/document_wizard_view.xml 2014-04-17 00:23:10 +0000
@@ -0,0 +1,41 @@
1<?xml version="1.0"?>
2<openerp>
3<data>
4
5 <record id="document_form_view" model="ir.ui.view">
6 <field name="name">Add existing document/attachment</field>
7 <field name="model">ir.attachment.existing.doc</field>
8 <field name="arch" type="xml">
9 <form string="Add existing document/attachment" version="7.0">
10 <group string="Select document(s)" colspan="4">
11 <field name="attachment_ids" nolabel="1">
12 <tree string="AttachmentDocumentWizardTree">
13 <field name="name"/>
14 <field name="create_uid"/>
15 <field name="create_date"/>
16 <field name="type"/>
17 </tree>
18 </field>
19 </group>
20 <footer>
21 <button string="Apply" name="action_apply" type="object" class="oe_highlight"/>
22 or
23 <button string="Cancel" class="oe_link" special="cancel" />
24 </footer>
25 </form>
26 </field>
27 </record>
28
29 <!-- Actions -->
30 <record model="ir.actions.act_window" id="action_view_document">
31 <field name="name">Add existing document/attachment</field>
32 <field name="res_model">ir.attachment.existing.doc</field>
33 <field name="view_type">form</field>
34 <field name="view_mode">tree,form</field>
35 <field name="view_id" ref="document_form_view"/>
36 <field name="target">new</field>
37 </record>
38
39</data>
40</openerp>
41

Subscribers

People subscribed via source and target branches

to status/vote changes: