From 3a038b60f2440bd5c049f635c1a7aa2e311edd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Dec 2013 17:39:11 +0100 Subject: [PATCH] [CLEAN] hr_applicant_document: code cleaning - new module organisation: model-related files in models/, demo in demo/, view data in views/ - code cleaning to lessen the code size bzr revid: tde@openerp.com-20131206163911-qx1k1edogqxg52kv --- addons/hr_applicant_document/__init__.py | 4 +- addons/hr_applicant_document/__openerp__.py | 41 +++++---------- .../hr_applicant.xml} | 0 .../hr_applicant_document.py | 51 ------------------- .../models/hr_applicant.py | 29 +++++++++++ .../hr_applicant.xml} | 0 6 files changed, 42 insertions(+), 83 deletions(-) rename addons/hr_applicant_document/{hr_applicant_document_demo.xml => demo/hr_applicant.xml} (100%) delete mode 100644 addons/hr_applicant_document/hr_applicant_document.py create mode 100644 addons/hr_applicant_document/models/hr_applicant.py rename addons/hr_applicant_document/{hr_applicant_document_view.xml => views/hr_applicant.xml} (100%) diff --git a/addons/hr_applicant_document/__init__.py b/addons/hr_applicant_document/__init__.py index 2b119fed44c..76e07d0ac4f 100644 --- a/addons/hr_applicant_document/__init__.py +++ b/addons/hr_applicant_document/__init__.py @@ -19,6 +19,4 @@ # ############################################################################## -import hr_applicant_document - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +import models diff --git a/addons/hr_applicant_document/__openerp__.py b/addons/hr_applicant_document/__openerp__.py index c79269f5da5..bd8224f1755 100644 --- a/addons/hr_applicant_document/__openerp__.py +++ b/addons/hr_applicant_document/__openerp__.py @@ -1,24 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2010-today OpenERP SA () -# -# 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': 'Applicant Resumes and Letters', @@ -26,17 +6,20 @@ 'category': 'Human Resources', 'sequence': 25, 'summary': 'Search job applications by Index content.', - 'description': """ - This module allows you to search job applications by Index content - of Resumes & Letters. -""", + 'description': """This module allows you to search job applications by content + of resumes and letters.""", 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', - 'images': [], - 'depends': ['hr_recruitment','document'], - 'data': ['hr_applicant_document_view.xml'], - 'demo': ['hr_applicant_document_demo.xml'], - 'test': [], + 'depends': [ + 'hr_recruitment', + 'document' + ], + 'data': [ + 'views/hr_applicant.xml' + ], + 'demo': [ + 'demo/hr_applicant.xml' + ], 'installable': True, 'auto_install': True, 'application': True, diff --git a/addons/hr_applicant_document/hr_applicant_document_demo.xml b/addons/hr_applicant_document/demo/hr_applicant.xml similarity index 100% rename from addons/hr_applicant_document/hr_applicant_document_demo.xml rename to addons/hr_applicant_document/demo/hr_applicant.xml diff --git a/addons/hr_applicant_document/hr_applicant_document.py b/addons/hr_applicant_document/hr_applicant_document.py deleted file mode 100644 index f1566237f32..00000000000 --- a/addons/hr_applicant_document/hr_applicant_document.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2010-today OpenERP SA () -# -# 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, osv - -class hr_applicant(osv.osv): - _inherit = 'hr.applicant' - - def _get_index_content(self, cr, uid, ids, fields, args, context=None): - res = {} - attachment_pool = self.pool.get('ir.attachment') - for id in ids: - res[id] = '' - attachment_ids = attachment_pool.search(cr, uid, [('res_model', '=', 'hr.applicant'), ('res_id', '=', id)], context=context) - for attachment in attachment_pool.browse(cr, uid, attachment_ids, context=context): - # adding index content of all attachments into one in order to find easily from all attachments - res[id] += attachment.index_content or '' - return res - - def _content_search(self, cr, user, obj, name, args, context=None): - record_ids = [] - attachment_pool = self.pool.get('ir.attachment') - args += [('res_model','=','hr.applicant')] - attachment_ids = attachment_pool.search(cr, user, args, context=context) - for attachment in attachment_pool.browse(cr, user, attachment_ids, context=context): - if attachment.res_id not in record_ids: - record_ids.append(attachment.res_id) - return [('id', 'in', record_ids)] - - _columns = { - 'index_content': fields.function(_get_index_content, string='Index Content', \ - fnct_search=_content_search, type="text"), - } - diff --git a/addons/hr_applicant_document/models/hr_applicant.py b/addons/hr_applicant_document/models/hr_applicant.py new file mode 100644 index 00000000000..036ea6c200e --- /dev/null +++ b/addons/hr_applicant_document/models/hr_applicant.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from openerp.osv import fields, osv + + +class hr_applicant(osv.Model): + _inherit = 'hr.applicant' + + def _get_index_content(self, cr, uid, ids, fields, args, context=None): + res = dict.fromkeys(ids, '') + Attachment = self.pool.get('ir.attachment') + attachment_ids = Attachment.search(cr, uid, [('res_model', '=', 'hr.applicant'), ('res_id', 'in', ids)], context=context) + for attachment in Attachment.browse(cr, uid, attachment_ids, context=context): + res[attachment.res_id] += attachment.index_content or '' + return res + + def _content_search(self, cr, user, obj, name, args, context=None): + record_ids = set() + Attachment = self.pool.get('ir.attachment') + args = ['&'] + args + [('res_model', '=', 'hr.applicant')] + att_ids = Attachment.search(cr, user, args, context=context) + record_ids = set(att.res_id for att in Attachment.browse(cr, user, att_ids, context=context)) + return [('id', 'in', list(record_ids))] + + _columns = { + 'index_content': fields.function( + _get_index_content, fnct_search=_content_search, + string='Index Content', type="text"), + } diff --git a/addons/hr_applicant_document/hr_applicant_document_view.xml b/addons/hr_applicant_document/views/hr_applicant.xml similarity index 100% rename from addons/hr_applicant_document/hr_applicant_document_view.xml rename to addons/hr_applicant_document/views/hr_applicant.xml