Merge pull request #44 from savoirfairelinux/7.0_document_multiple_record_add_field

Add a new field and change the domain filter
This commit is contained in:
Maxime Chambreuil - http://www.savoirfairelinux.com 2015-11-14 12:59:34 -05:00
commit 6a4752be92
9 changed files with 208 additions and 36 deletions

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@ -22,5 +22,3 @@
from . import document
from . import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@ -21,40 +21,40 @@
##############################################################################
{
'name': 'Document Management System for Multiple Records',
'version': '0.1',
'category': 'Knowledge Management',
'summary': 'Document Management System for Multiple Records',
'description': """
"name": "Document Management System for Multiple Records",
"version": "7.0.1.0.0",
"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)
* Maxime Chambreuil (maxime.chambreuil@savoirfairelinux.com)
""",
'author': "Savoir-faire Linux,Odoo Community Association (OCA)",
'website': 'www.savoirfairelinux.com',
'license': 'AGPL-3',
'depends': [
'document',
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
"website": "www.savoirfairelinux.com",
"license": "AGPL-3",
"depends": [
"document",
],
'data': [
'document_view.xml',
'security/ir.model.access.csv',
'wizard/document_wizard_view.xml',
"data": [
"views/document_view.xml",
"security/ir.model.access.csv",
"wizard/document_wizard_view.xml",
],
'js': [
'static/src/js/document.js'
"js": [
"static/src/js/document.js"
],
'qweb': [
'static/src/xml/document.xml'
"qweb": [
"static/src/xml/document.xml"
],
'test': [],
'demo': [
"test": [],
"demo": [
],
'installable': True,
'auto_install': False,
"installable": True,
"auto_install": False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@ -51,6 +51,29 @@ class document_file(orm.Model):
data[attachment.id] = False
return data
def _get_related_model_documents(
self, cr, uid, ids, field_name, args, context=None):
""" This function allows to get only related documents with a specific
model and model_id.
"""
context = context or {}
ir_attachment_doc_obj = self.pool.get('ir.attachment.document')
res = [('id', 'in', [])]
# Format query with the res_model and res_id to search
# in ir.attachment.document model.
query = [
('res_model', '=', context.get('model')),
('res_id', '=', context.get('model_id'))]
ir_attachment_doc_ids = ir_attachment_doc_obj.search(
cr, uid, query, context=context)
ir_attachment_ids = self.search(
cr, uid, [
('attachment_document_ids.id', 'in', ir_attachment_doc_ids)],
context=context)
res = [('id', 'in', ir_attachment_ids)]
return res
_columns = {
'attachment_document_ids': fields.one2many('ir.attachment.document',
'attachment_id',
@ -58,6 +81,9 @@ class document_file(orm.Model):
'res_name': fields.function(_name_get_resname, type='char',
size=128, string='Resource Name',
store=True),
'related_document': fields.function(
lambda self, *a, **kw: True, type='boolean',
fnct_search=_get_related_model_documents),
}
def create(self, cr, uid, data, context=None):

View File

@ -63,6 +63,11 @@ var _t = instance.web._t,
var self = this;
this.dataset = dataset;
this.model_id = model_id;
// Add the model and the model_id in the context
var context = {
'model': dataset.model,
'model_id': model_id
};
if (args && args[0].error) {
this.do_warn(_t('Uploading Error'), args[0].error);
}
@ -70,8 +75,8 @@ var _t = instance.web._t,
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);
var dom = [ ['related_document', '=', true] ];
var ds = new instance.web.DataSetSearch(this, 'ir.attachment', context, dom);
ds.read_slice(['name', 'url', 'type', 'create_uid', 'create_date', 'write_uid', 'write_date'], {}).done(this.on_attachments_loaded);
}
}

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import (
test_ir_attachment,
)
checks = [
test_ir_attachment,
]

View File

@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 Savoir-faire Linux (<http://www.savoirfairelinux.com>)
#
# 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 <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp.tests.common import TransactionCase
class test_ir_attachment(TransactionCase):
def setUp(self):
super(test_ir_attachment, self).setUp()
# Get registries
self.ira_model = self.registry('ir.attachment')
self.user_model = self.registry("res.users")
self.partner_model = self.registry("res.partner")
self.context = self.user_model.context_get(self.cr, self.uid)
# Create first partner
self.partner_id_1 = self.partner_model.create(self.cr, self.uid, {
'name': 'Test first partner'
}, context=self.context)
# Create second partner
self.partner_id_2 = self.partner_model.create(self.cr, self.uid, {
'name': 'Test second partner'
}, context=self.context)
blob1 = 'blob1'
blob1_b64 = blob1.encode('base64')
self.vals = {
'name': 'Test documemt',
'datas': blob1_b64,
'res_model': 'res.partner',
'res_id': self.partner_id_1,
'res_name': 'Test first partner',
'attachment_document_ids': [(0, 0, {
'res_model': 'res.partner',
'res_id': self.partner_id_1,
'res_name': 'Test first partner',
}),
(0, 0, {
'res_model': 'res.partner',
'res_id': self.partner_id_2,
'res_name': 'Test second partner',
})
]
}
def test_create_document(self):
"""Test create document and check each value in vals variable """
cr, uid, vals, context = self.cr, self.uid, self.vals, self.context
ira_id = self.ira_model.create(cr, uid, vals, context=context)
ira_obj = self.ira_model.browse(cr, uid, ira_id, context=context)
self.assertEqual(ira_obj.name, vals['name'])
self.assertEqual(ira_obj.res_id, vals['res_id'])
self.assertEqual(ira_obj.res_name, vals['res_name'])
self.assertEqual(ira_obj.res_model, vals['res_model'])
self.assertEqual(
ira_obj.attachment_document_ids[0].res_id, self.partner_id_1)
self.assertEqual(
ira_obj.attachment_document_ids[0].res_name, 'Test first partner')
self.assertEqual(
ira_obj.attachment_document_ids[0].res_model, 'res.partner')
def test_unlink_document(self):
"""Test normal unlink document """
cr, uid, vals = self.cr, self.uid, self.vals.copy()
context = self.context
ira_id = self.ira_model.create(cr, uid, vals, context=context)
self.ira_model.unlink(cr, uid, ira_id, context=context)
def test_unlink_document_drop_down(self):
"""Test unlink from drop-down list in the form view """
cr, uid, vals = self.cr, self.uid, self.vals.copy()
context = self.context
context['multiple_records_res_model'] = 'res.partner'
context['multiple_records_res_id'] = self.partner_id_1
ira_id = self.ira_model.create(cr, uid, vals, context=context)
self.ira_model.unlink(cr, uid, [ira_id], context=context)
def test_name_get_resname(self):
"""Test _name_get_resname function """
cr, uid, vals, context = self.cr, self.uid, self.vals, self.context
ira_id = self.ira_model.create(cr, uid, vals, context=context)
self.assertEquals(self.ira_model._name_get_resname(
cr, uid, ira_id, obj=None, method=None,
context=context)[ira_id], vals['res_name'])
def test_get_related_model_documents(self):
cr, uid, vals = self.cr, self.uid, self.vals.copy()
context = self.context
context['model'] = 'res.partner'
context['model_id'] = self.partner_id_1
ira_id = self.ira_model.create(cr, uid, vals, context=context)
res = self.ira_model._get_related_model_documents(
cr, uid, ira_id, field_name=None, args=None, context=context)
self.assertEqual(res[0], ('id', 'in', [ira_id]))

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
@ -21,5 +21,3 @@
##############################################################################
from . import document_wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution