1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
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 General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
from osv import fields,osv
25
class search_database_wizard(osv.osv_memory):
27
Search a string in database setting up un listed database and return result
28
and the possibility to go in search in actual DB (res.partner)
31
_name = 'search.database.wizard'
33
def return_view(self, cr, uid, name, res_id):
34
'''General purpose function that return dict action for next step of
38
'name': 'Searched partners',
40
'view_mode': 'tree,form',
41
'res_model': 'res.partner',
42
'type': 'ir.actions.act_window',
44
'domain': str([('id', 'in', res_id)]),
48
def search_text_in_other_database(self,cr, uid, ids, context=None):
49
''' Search button in wizard windows, search in other DB list and
50
comunicate existence in other DB res.partner finded in list box
54
# TODO parametrizzare:
63
# Read data in wizard form:
64
wiz_proxy=self.browse(cr, uid, ids, context=context)
65
search_string=wiz_proxy[0].name
67
db_ids = self.pool.get('search.database').search(cr, uid, [('search','=', True)])
69
if db_ids: # if there is some DB in list:
70
for db in self.pool.get('search.database').browse(cr, uid, db_ids, context=context):
72
sock = xmlrpclib.ServerProxy('http://' + server + ':' + port + '/xmlrpc/common', allow_none=True)
73
uid_extra = sock.login(dbname ,user ,pwd)
74
sock = xmlrpclib.ServerProxy('http://' + server + ':' + port + '/xmlrpc/object', allow_none=True)
76
partner_ids = sock.execute(dbname, uid_extra, pwd, 'res.partner', 'search', [('name', 'ilike', search_string),])
78
partner_read = sock.execute(dbname, uid_extra, pwd, 'res.partner', 'read', partner_ids)
79
for partner in partner_read:
80
finded_result += "[%s] %s - (%s - %s) %s - %s\n"%(dbname, partner['name'], partner['city'] or "", partner['country'] and partner['country'][1], partner['phone'] or "", partner['email'] or "")
82
partner_current_ids=len(self.pool.get('res.partner').search(cr, uid, [('name', 'ilike', search_string)], context=context))
83
# Change fields (status) of the wizard:
84
wiz_result=self.write(cr, uid, ids, {'state': 'find',
85
'find': finded_result,
86
'current': partner_current_ids,
90
def search_text_in_database(self,cr, uid, ids, context=None):
91
''' Search button in wizard windows, search in current DB and
92
comunicate existence in other DB res.partner finded
98
# Read data in wizard form:
99
wiz_proxy=self.browse(cr, uid, ids, context=context)
100
search_string=wiz_proxy[0].name
102
# Cerco nell'attuale DB i partner che possono andare bene:
103
partner_ids=self.pool.get('res.partner').search(cr, uid, [('name', 'ilike', search_string)], context=context)
105
return self.return_view(cr, uid, '', partner_ids)
108
'name':fields.char('Text to search', size=60, required=True, readonly=False),
109
'find': fields.text('Finded in other DB'),
110
'current': fields.integer('Find current DB'),
111
'state':fields.selection([
113
('find','Find in other DB'),
114
],'State', select=True, readonly=True),
118
'state': lambda *a: 'search',
119
'current': lambda *a: 0,
121
search_database_wizard()
122
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: