Exemplo n.º 1
0
def _sms_send(self, cr, uid, data, context):
    service = netsvc.LocalService("object_proxy")

    res_ids = service.execute(cr.dbname, uid, 'res.partner.address', 'search', [('partner_id','in',data['ids']),('type','=','default')])
    res = service.execute(cr.dbname, uid, 'res.partner.address', 'read', res_ids, ['mobile'])

    nbr = 0
    for r in res:
        to = r['mobile']
        if to:
            tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
            nbr += 1
    return {'sms_sent': nbr}
Exemplo n.º 2
0
def _sms_send(cr, uid, data, context, adr):
    import re
    # change the [[field]] tags with the partner address values
    pattern = re.compile('\[\[\S+\]\]')
    fields = pattern.findall(data['form']['text'])
    texts = []
    for field in fields:
        text = getattr(adr, field[2:-2])
        if text and field[-5:-2] == '_id':  # State or country
            text = text.name
        texts.append(text or '')
    sms = pattern.sub('%s', data['form']['text'])
    sms = sms % tuple(texts)
    #print sms

    to = adr.mobile
    to = to.replace(' ', '')
    if adr.country_id and adr.country_id.code in (
            'ES', 'CT') and to[:1] == '6':  # Spain mobiles begin with 6
        to = '34' + to
    sms = ' '.join(sms.split('\n'))  # Conversion of '\n' to ' ' is necessary
    sms_sent = unicode(sms, 'utf-8').encode('latin1')
    if data['form']['email_http']:
        # Connection by Email
        text = 'user:'******'form']['user'] + '\npassword:'******'form'][
            'password'] + '\napi_id:' + data['form'][
                'app_id'] + '\nto:' + to + '\ntext:' + sms_sent
        #print text
        tools.email_send(data['form']['email'],
                         ['*****@*****.**'], '', text)
    else:
        # Connection by http
        tools.sms_send(data['form']['user'], data['form']['password'],
                       data['form']['app_id'], sms_sent, to)

    # Add a partner event
    c_id = pooler.get_pool(cr.dbname).get('res.partner.canal').search(
        cr, uid, [('name', 'ilike', 'SMS'), ('active', '=', True)])
    c_id = c_id and c_id[0] or False
    pooler.get_pool(cr.dbname).get('res.partner.event').create(
        cr, uid, {
            'name': 'SMS sent to ' + adr.mobile,
            'partner_id': adr.partner_id.id,
            'description': sms,
            'canal_id': c_id,
            'user_id': uid,
        })
Exemplo n.º 3
0
def _sms_send(self, cr, uid, data, context):
    service = netsvc.LocalService("object_proxy")

    res_ids = service.execute(cr.dbname, uid, 'res.partner.address', 'search', [('partner_id','in',data['ids']),('type','=','default')])
    res = service.execute(cr.dbname, uid, 'res.partner.address', 'read', res_ids, ['mobile'])

    nbr = 0
    for r in res:
        to = r['mobile']
        if to:
            tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], unicode(data['form']['text'], 'utf-8').encode('latin1'), to)
            nbr += 1

    data['form']['nbr'] = nbr
    if data['form']['event']:
        return 'open'
    return 'ok'
Exemplo n.º 4
0
    def sms_send(self, cr, uid, ids, context):
        """
            to send sms

            @param cr: the current row, from the database cursor.
            @param uid: the current user’s ID for security checks.
            @param ids: the ID or list of IDs
            @param context: A standard dictionary
            @return: number indicating the acknowledgement
        """
        nbr = 0

        for data in self.browse(cr, uid, ids, context):
            tools.sms_send(data.user, data.password, data.app_id,
                           tools.ustr(data.text), data.mobile_to)
            nbr += 1
        return {}
    def sms_send(self, cr, uid, ids, context):
        """
            to send sms

            @param cr: the current row, from the database cursor.
            @param uid: the current user’s ID for security checks.
            @param ids: the ID or list of IDs
            @param context: A standard dictionary
            @return: number indicating the acknowledgement
        """             
        nbr = 0
        
        for data in self.browse(cr, uid, ids, context) :
            tools.sms_send(
                    data.user,
                    data.password, 
                    data.app_id, 
                    tools.ustr(data.text), 
                    data.mobile_to)
            nbr += 1
        return {}
Exemplo n.º 6
0
def _sms_send(cr, uid, data, context, adr):
    import re
    # change the [[field]] tags with the partner address values
    pattern = re.compile('\[\[\S+\]\]')
    fields = pattern.findall(data['form']['text'])
    texts = []
    for field in fields:
        text = getattr(adr, field[2:-2])
        if text and field[-5:-2]=='_id': # State or country
            text = text.name
        texts.append(text or '')
    sms = pattern.sub('%s', data['form']['text'])
    sms = sms % tuple(texts)
    #print sms

    to = adr.mobile
    to = to.replace(' ','')
    if adr.country_id and adr.country_id.code in ('ES', 'CT') and to[:1] == '6': # Spain mobiles begin with 6
        to = '34'+to
    sms = ' '.join( sms.split('\n') ) # Conversion of '\n' to ' ' is necessary
    sms_sent = unicode(sms, 'utf-8').encode('latin1')
    if data['form']['email_http']:
        # Connection by Email
        text = 'user:'******'form']['user'] + '\npassword:'******'form']['password'] + '\napi_id:' + data['form']['app_id'] + '\nto:' + to + '\ntext:' + sms_sent
        #print text
        tools.email_send(data['form']['email'], ['*****@*****.**'], '', text)
    else:
        # Connection by http
        tools.sms_send(data['form']['user'], data['form']['password'], data['form']['app_id'], sms_sent, to)

    # Add a partner event
    c_id = pooler.get_pool(cr.dbname).get('res.partner.canal').search(cr ,uid, [('name','ilike','SMS'),('active','=',True)])
    c_id = c_id and c_id[0] or False
    pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
            {'name': 'SMS sent to ' + adr.mobile,
             'partner_id': adr.partner_id.id,
             'description': sms,
             'canal_id': c_id,
             'user_id': uid, })
Exemplo n.º 7
0
    def run(self, cr, uid, ids, context={}):
        logger = netsvc.Logger()
        
        for action in self.browse(cr, uid, ids, context):
            obj_pool = self.pool.get(action.model_id.model)
            obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
            cxt = {
                'context':context, 
                'object': obj, 
                'time':time,
                'cr': cr,
                'pool' : self.pool,
                'uid' : uid
            }
            expr = eval(str(action.condition), cxt)
            if not expr:
                continue
            
            if action.state=='client_action':
                if not action.action_id:
                    raise osv.except_osv(_('Error'), _("Please specify an action to launch !")) 
                result = self.pool.get(action.action_id.type).read(cr, uid, action.action_id.id, context=context)
                return result

            if action.state=='code':
                localdict = {
                    'self': self.pool.get(action.model_id.model),
                    'context': context,
                    'time': time,
                    'ids': ids,
                    'cr': cr,
                    'uid': uid,
                    'obj':obj
                }
                exec action.code in localdict
                if 'action' in localdict:
                    return localdict['action']

            if action.state == 'email':
                user = config['email_from']
                address = str(action.email)
                try:
                    address =  eval(str(action.email), cxt)
                except:
                    pass
                
                if not address:
                    raise osv.except_osv(_('Error'), _("Please specify the Partner Email address !"))
                if not user:
                    raise osv.except_osv(_('Error'), _("Please specify server option --smtp-from !"))
                
                subject = self.merge_message(cr, uid, str(action.subject), action, context)
                body = self.merge_message(cr, uid, str(action.message), action, context)
                
                if tools.email_send(user, [address], subject, body, debug=False, subtype='html') == True:
                    logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (address))
                else:
                    logger.notifyChannel('email', netsvc.LOG_ERROR, 'Failed to send email to : %s' % (address))

            if action.state == 'trigger':
                wf_service = netsvc.LocalService("workflow")
                model = action.wkf_model_id.model
                obj_pool = self.pool.get(action.model_id.model)
                res_id = self.pool.get(action.model_id.model).read(cr, uid, [context.get('active_id')], [action.trigger_obj_id.name])
                id = res_id [0][action.trigger_obj_id.name]
                wf_service.trg_validate(uid, model, int(id), action.trigger_name, cr)

            if action.state == 'sms':
                #TODO: set the user and password from the system
                # for the sms gateway user / password
                api_id = ''
                text = action.sms
                to = self.get_mobile(cr, uid, action, context)
                #TODO: Apply message mearge with the field
                if tools.sms_send(user, password, api_id, text, to) == True:
                    logger.notifyChannel('sms', netsvc.LOG_INFO, 'SMS successfully send to : %s' % (action.address))
                else:
                    logger.notifyChannel('sms', netsvc.LOG_ERROR, 'Failed to send SMS to : %s' % (action.address))
            
            if action.state == 'other':
                res = []
                for act in action.child_ids:
                    context['active_id'] = context['active_ids'][0]
                    result = self.run(cr, uid, [act.id], context)
                    if result:
                        res.append(result)
                    
                return res
            
            if action.state == 'loop':
                obj_pool = self.pool.get(action.model_id.model)
                obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
                cxt = {
                    'context':context, 
                    'object': obj, 
                    'time':time,
                    'cr': cr,
                    'pool' : self.pool,
                    'uid' : uid
                }
                expr = eval(str(action.expression), cxt)
                context['object'] = obj
                for i in expr:
                    context['active_id'] = i.id
                    result = self.run(cr, uid, [action.loop_action.id], context)
            
            if action.state == 'object_write':
                res = {}
                for exp in action.fields_lines:
                    euq = exp.value
                    if exp.type == 'equation':
                        obj_pool = self.pool.get(action.model_id.model)
                        obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
                        cxt = {'context':context, 'object': obj, 'time':time}
                        expr = eval(euq, cxt)
                    else:
                        expr = exp.value
                    res[exp.col1.name] = expr

                if not action.write_id:
                    if not action.srcmodel_id:
                        obj_pool = self.pool.get(action.model_id.model)
                        obj_pool.write(cr, uid, [context.get('active_id')], res)
                    else:
                        write_id = context.get('active_id')
                        obj_pool = self.pool.get(action.srcmodel_id.model)
                        obj_pool.write(cr, uid, [write_id], res)
                        
                elif action.write_id:
                    obj_pool = self.pool.get(action.srcmodel_id.model)
                    rec = self.pool.get(action.model_id.model).browse(cr, uid, context.get('active_id'))
                    id = eval(action.write_id, {'object': rec})
                    try:
                        id = int(id)
                    except:
                        raise osv.except_osv(_('Error'), _("Problem in configuration `Record Id` in Server Action!"))
                    
                    if type(id) != type(1):
                        raise osv.except_osv(_('Error'), _("Problem in configuration `Record Id` in Server Action!"))
                    write_id = id
                    obj_pool.write(cr, uid, [write_id], res)

            if action.state == 'object_create':
                res = {}
                for exp in action.fields_lines:
                    euq = exp.value
                    if exp.type == 'equation':
                        obj_pool = self.pool.get(action.model_id.model)
                        obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
                        expr = eval(euq, {'context':context, 'object': obj, 'time':time})
                    else:
                        expr = exp.value
                    res[exp.col1.name] = expr

                obj_pool = None
                res_id = False
                obj_pool = self.pool.get(action.srcmodel_id.model)
                res_id = obj_pool.create(cr, uid, res)
                cr.commit()
                if action.record_id:
                    self.pool.get(action.model_id.model).write(cr, uid, [context.get('active_id')], {action.record_id.name:res_id})

        return False