~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to etl_interface/etl_component/output/openobject_out.py

  • Committer: Harry (Open ERP)
  • Date: 2009-03-18 12:51:34 UTC
  • mto: (3589.27.39 extra)
  • mto: This revision was merged to the branch mainline in revision 3595.
  • Revision ID: hmo@tinyerp.com-20090318125134-ywp6lsse5u9ffcbs
[ETL] etl_interface : new module for etl interface with openerp

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution
 
6
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
7
#    $Id$
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, either version 3 of the License, or
 
12
#    (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
import etl
 
24
import tools
 
25
from osv import osv, fields
 
26
 
 
27
class etl_component_openobject_lines(osv.osv):
 
28
    _name='etl.component.openobject.lines'
 
29
    _columns={              
 
30
              'source_field' : fields.char('Source Field', size=124), 
 
31
              'dest_field' : fields.char('Destination Field', size=124), 
 
32
              'component_id' : fields.many2one('etl.component', 'Model'), 
 
33
    }
 
34
 
 
35
etl_component_openobject_lines()
 
36
 
 
37
class etl_component_open_object_out(osv.osv):
 
38
    _name='etl.component'
 
39
    _inherit = 'etl.component'  
 
40
 
 
41
    _columns={
 
42
              'openobject_field_ids' : fields.one2many('etl.component.openobject.lines', 'component_id', 'Fields'), 
 
43
              'model_id' : fields.many2one('ir.model', 'Model'), 
 
44
              'connector_id' : fields.many2one('etl.connector', 'Connector'),               
 
45
    }
 
46
    
 
47
    def create_instance(self, cr, uid, id, context={}):
 
48
        val=super(etl_component_open_object_out, self).create_instance(cr, uid, id, context)
 
49
        obj_connector=self.pool.get('etl.connector')
 
50
        obj_transformer = self.pool.get('etl.transformer')
 
51
        cmp=self.browse(cr, uid, id)        
 
52
        
 
53
        if cmp.type_id.name == 'output.openobject_out':           
 
54
            conn_instance=False
 
55
            trans_instance=False
 
56
            if cmp.connector_id:                
 
57
                conn_instance=obj_connector.get_instance(cr, uid, cmp.connector_id.id , context)
 
58
                
 
59
            if cmp.transformer_id:                
 
60
                trans_instance=obj_transformer.get_instance(cr, uid, cmp.transformer_id.id, context)       
 
61
           
 
62
            field_ids={}
 
63
            for data in cmp.openobject_field_ids:
 
64
                field_ids[data.source_field] = data.dest_field
 
65
            val = etl.component.output.openobject_out(conn_instance, cmp.model_id.model, field_ids, 'component.output.openobject_out', trans_instance)
 
66
            
 
67
    
 
68
        return val
 
69
            
 
70
etl_component_open_object_out()
 
71
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
72