Package etl :: Package component :: Package input :: Module openobject_in
[hide private]
[frames] | no frames]

Source Code for Module etl.component.input.openobject_in

 1  # -*- encoding: utf-8 -*- 
 2  ############################################################################## 
 3  # 
 4  #    ETL system- Extract Transfer Load system 
 5  #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved 
 6  #    $Id$ 
 7  # 
 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. 
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 General Public License for more details. 
17  # 
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/>. 
20  # 
21  ############################################################################## 
22  """ 
23  Reads data from Open Object model. 
24   
25  Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>) 
26  GNU General Public License 
27  """ 
28   
29  from etl.component import component 
30   
31 -class openobject_in(component):
32 """ 33 This is an ETL Component that use to read data from open object model. 34 Type : Data Component. 35 Computing Performance : Streamline. 36 Input Flows : 0. 37 * .* : Nothing. 38 Output Flows : 0-x. 39 * .* : Returns the main flow with data from open object model 40 """ 41
42 - def __init__(self, openobject_connector, model, domain=[], fields=[], context={}, name='component.input.openerp_in', transformer=None, row_limit=0):
43 """ 44 Required Parameters 45 openobject_connector : Object of Openobject connector. 46 model : Name of Open Object model. 47 domain : Domain List to put domain. 48 fields : Fields List. 49 context : Context Values. 50 51 Extra Parameters 52 row_limit : Row Limit.If row limit is 0,all records are fetched. 53 name : Name of Component. 54 transformer : Transformer object to transform string data into particular type. 55 """ 56 super(openobject_in, self).__init__(name=name, connector=openobject_connector, transformer=transformer,row_limit=row_limit) 57 self._type = 'component.input.openerp_in' 58 self.model = model 59 self.domain = domain 60 self.context = context 61 self.fields = fields
62
63 - def __copy__(self):
64 res = openobject_in(self.connector, self.model, self.domain, self.fields, self.context, self.name, self.transformer, self.row_limit) 65 return res
66
67 - def process(self):
68 import socket 69 import xmlrpclib 70 import datetime 71 rows = [] 72 connector = self.connector.open() 73 ids = self.connector.execute(connector, 'execute', self.model, 'search', self.domain, 0, self.row_limit, False, self.context, False) 74 rows = self.connector.execute(connector, 'execute', self.model, 'read', ids, self.fields, self.context) 75 self.connector.close(connector) 76 for row in rows: 77 if row: 78 yield row, 'main'
79
80 -def test():
81 from etl_test import etl_test 82 import etl 83 file_conn = etl.connector.openobject_connector('http://localhost:8069', 'trunk', 'admin', 'admin', con_type='xmlrpc') 84 test = etl_test.etl_component_test(openobject_in(file_conn, 'res.country',[('name', '=', 'Algeria')])) 85 # test.check_input({'main':[{'name':'Elec Import'}]}) 86 test.check_output([{'name': 'Algeria', 'code': 'DZ', 'id': 61}], 'main') # to be update 87 res = test.output() 88 print res
89 if __name__ == '__main__': 90 test() 91