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

« back to all changes in this revision

Viewing changes to dm/document.py

  • Committer: Fabien Pinckaers
  • Date: 2009-02-19 18:51:09 UTC
  • mfrom: (3561.1.22 trunk-extra-addons)
  • Revision ID: fp@tinyerp.com-20090219185109-3e8hojbs42yh26ly
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
            order = dm_customer_order.browse(cr,uid,order_id)
55
55
            customer_ids = map(lambda x:x.customer_id.id,order)
56
56
            plugins = d.document_template_id.plugin_ids
57
 
            for plugin in plugins:
58
 
                args={}
59
 
                if plugin.field.name:
60
 
                    args['field_name']=str(plugin.field.name)
61
 
                    args['field_type']=str(plugin.field.ttype)
62
 
                    args['field_relation']=str(plugin.field.relation)
63
 
                path = os.path.join(os.getcwd(), "addons/dm/dm_ddf_plugins",cr.dbname)
64
 
                plugin_name = plugin.file_fname.split('.')[0]
65
 
                arguments = plugin.argument_ids
66
 
                for a in arguments:
67
 
                    args[str(a.name)]=str(a.value)
68
 
                import sys
69
 
                sys.path.append(path)
70
 
                X =  __import__(plugin_name)
71
 
                plugin_func = getattr(X,plugin_name)
72
 
                plugin_value = plugin_func(cr,uid,customer_ids,**args)
73
 
 
74
 
                map(lambda x :dm_plugins_value.create(cr,uid,
75
 
                            {'date':time.strftime('%Y-%m-%d'),
76
 
                             'customer_id':x[0],
77
 
                             'plugin_id':plugin.id,
78
 
                             'value' : x[1]}),
79
 
                            plugin_value
80
 
                            )
 
57
            if plugins:
 
58
                for plugin in plugins:
 
59
                    args={}
 
60
                    if plugin.type=='fields':
 
61
                        args['object']=str(plugin.object)
 
62
                        args['field_name']=str(plugin.field.name)
 
63
                        args['field_type']=str(plugin.field.ttype)
 
64
                        args['field_relation']=str(plugin.field.relation)
 
65
                            
 
66
                        path = os.path.join(os.getcwd(), "addons/dm/")
 
67
                        plugin_name = 'customer_function'
 
68
                    else :
 
69
                        arguments = plugin.argument_ids
 
70
                        for a in arguments:
 
71
                            args[str(a.name)]=str(a.value)
 
72
                        path = os.path.join(os.getcwd(), "addons/dm/dm_ddf_plugins",cr.dbname)
 
73
                        plugin_name = plugin.file_fname.split('.')[0]
 
74
                    import sys
 
75
                    sys.path.append(path)
 
76
                    X =  __import__(plugin_name)
 
77
                    plugin_func = getattr(X,plugin_name)
 
78
                    plugin_value = plugin_func(cr,uid,customer_ids,**args)
 
79
                    if plugin.store_value : 
 
80
                        map(lambda x :dm_plugins_value.create(cr,uid,
 
81
                                    {'date':time.strftime('%Y-%m-%d'),
 
82
                                     'customer_id':x[0],
 
83
                                     'plugin_id':plugin.id,
 
84
                                     'value' : x[1]}),
 
85
                                    plugin_value
 
86
                                    )
81
87
        return True
82
88
    
83
89
    def _data_get(self, cr, uid, ids, name, arg, context):
118
124
            desc = 'Value of the field must be of type %s or plugin may be crashed'%arg[1] 
119
125
            vals = {'name':arg[0],'note':desc,'plugin_id':id,'value':' '}
120
126
            new_id = self.pool.get('dm.plugin.argument').create(cr,uid,vals)
121
 
        print uid
122
127
        if '__description__' in dir(X):
123
128
            self.write(cr,uid,id,{'note':X.__description__})
124
129
        return True
125
130
    
126
131
    _columns = {
127
132
        'name' : fields.char('DDF Plugin Name', size=64),
 
133
        'store_value' : fields.boolean('Store Value'),
 
134
        'code' : fields.char('Code', size=64),
128
135
        'file_id': fields.function(_data_get,method=True,fnct_inv=_data_set,string='File Content',type="binary"),
129
136
        'file_fname': fields.char('Filename',size=64),
130
137
        'argument_ids' : fields.one2many('dm.plugin.argument', 'plugin_id', 'Argument List'),
131
138
        'note' : fields.text('Description'),
132
 
        'field' : fields.many2one('ir.model.fields','Customers Field',
133
 
               domain=[('model_id','=','Partner')],
134
 
               context={'model':'res.partner'}),      
 
139
        'type' : fields.selection([('fields','Customer'),('dynamic','Dynamic')], 'Type', required=True),
 
140
        'field' : fields.many2one('ir.model.fields','Customers Field'),
 
141
        'object' : fields.many2one('ir.model','Object',),      
 
142
                     
135
143
     }
 
144
    _sql_constraints = [
 
145
        ('code_uniq', 'UNIQUE(code)', 'The code must be unique!'),
 
146
    ]    
 
147
    
136
148
dm_ddf_plugin()
137
149
 
138
150
class dm_plugin_argument(osv.osv):
224
236
class dm_offer_document(osv.osv):
225
237
    _name = "dm.offer.document"
226
238
    _rec_name = 'name'
227
 
    
 
239
 
 
240
    def default_get(self, cr, uid, fields, context=None):
 
241
        value = super(dm_offer_document, self).default_get(cr, uid, fields, context)
 
242
        if 'step_id' in context and context['step_id']:
 
243
            offer = self.pool.get('dm.offer')
 
244
            offer_id = offer.search(cr, uid, [('step_ids','in',[context['step_id']])])
 
245
            browse_id = offer.browse(cr, uid, offer_id)[0]
 
246
            value['lang_id'] = browse_id.lang_orig.id
 
247
            value['copywriter_id'] = browse_id.copywriter_id.id
 
248
        return value
 
249
        
228
250
    def _has_attchment_fnc(self, cr, uid, ids, name, arg, context={}):
229
251
        res={}
230
252
        for id in ids :