0
votes

With the admin user I can do everything, add, delete, modify, etc. As it should be. when i add new user with email configuration well done(can send and receive emails on openerp messaging module), but when i call my function send email from my custom module :

  <button name="send_email" string="Notifier Participants" states="open" type="object" icon="gtk-jump-to"/>

My function :

def send_email(self, cr, uid, ids, context=None):
    res_id=''
    objects_review = self.browse(cr, uid, ids, context=context)
    for object_review in objects_review:
        participant_names=''

        for user_id in object_review.user_ids:
            participant_names += '<tr><td>'+user_id.name+'<td></tr>'

    email_template_obj = self.pool.get('email.template')
    template_ids = email_template_obj.search(cr, uid, [], context=context) 
    if template_ids:
        current_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
        values = email_template_obj.generate_email(cr, uid, template_ids[0], ids, context=context)
        values['subject'] = object_review.name
        values['email_from'] = current_user.email
        values['email_to'] = object_review.participant_emails
        values['body_html'] = 'Bonjour, </br>  Convocation à la revue
        :</br> <table><tr><td>Revue :
        </td>'+'<td>'+str(object_review.name)+'</td></tr><tr>
        <td>Référence</td><td>'+str(object_review.reference)+'</td>
        </tr><tr><td>Date de la Revue</td>
        <td>'+str(object_review.date)+'</td></tr><tr><td>
        Lieu de la Revue</td><td>'+str(object_review.lieu)+'
        </td></tr><tr><td>Type de la Revue</td>
        <td>'+str(object_review.type.name)+'</td></tr><tr><table>
        <th>Participants</th>'+participant_names+'</table></tr>
        <tr><td>Object :</td><td>'+str(object_review.objet)
        or ''+'</td></tr></table>'
        values['body'] = '<table><tr><td> </td></tr></table>'
        values['res_id'] = False
        mail_mail_obj = self.pool.get('mail.mail')
        msg_id = mail_mail_obj.create(cr, uid, values, context=context)
        mail_mail_obj.send(cr, uid, [msg_id], context=context) 
        #email_template_obj.send_mail(cr, uid, template_ids[0], ids[0], force_send=True, context=context)
        return True

I got this error :

{'body': u'

Hello,

\n\n \n ', 'attachments': [], 'attachment_ids': [], 'auto_delete': True, 'email_recipients': False, 'body_html': u'Bonjour, Convocation \xe0 la revue : Revue :dfR\xe9f\xe9rence/001/2015Date de la Revue2015-09-16 14:57:32Lieu de la RevueFalseType de la RevueNoneParticipantsAdministratorObject :False', 'mail_server_id': False, 'email_to': u'[email protected]', 'reply_to': False, 'email_cc': False, 'model': u'document.page.history', 'res_id': False, 'email_from': u'[email protected]', 'subject': u'df'} 2015-09-16 14:59:57,552 5688 WARNING tist openerp.osv.orm: No such field(s) in model mail.mail: attachments, email_recipients. 2015-09-16 14:59:57,564 5688 ERROR tist openerp.netsvc: Access Denied The requested operation cannot be completed due to security restrictions. Please contact your system administrator.

(Document type: Message, Operation: create) Traceback (most recent call last): File "/home/nadia/barid/server2/openerp15-9-15/openerp/netsvc.py", line 306, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/nadia/barid/server2/openerp15-9-15/openerp/service/web_services.py", line 632, in dispatch res = fn(db, uid, *params) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/audittrail/audittrail.py", line 532, in execute_cr return fct_src(cr, uid, model, method, *args, **kw) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/mgmtsystem_review/mgmtsystem_review.py", line 129, in send_email msg_id = mail_mail_obj.create(cr, uid, values, context=context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/fetchmail/fetchmail.py", line 305, in create res = super(mail_mail, self).create(cr, uid, values, context=context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/mail/mail_mail.py", line 93, in create return super(mail_mail, self).create(cr, uid, values, context=context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/orm.py", line 4489, in create record_id = self.pool.get(table).create(cr, user, tocreate[table], context=parent_context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/mail/mail_message.py", line 754, in create newid = super(mail_message, self).create(cr, uid, values, context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/osv/orm.py", line 4615, in create self.check_access_rule(cr, user, [id_new], 'create', context=context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/portal/mail_message.py", line 63, in check_access_rule return super(mail_message, self).check_access_rule(cr, uid, ids=ids, operation=operation, context=context) File "/home/nadia/barid/server2/openerp15-9-15/openerp/addons/mail/mail_message.py", line 744, in check_access_rule (self._description, operation)) except_osv: (u'Access Denied', u'The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: Message, Operation: create)')

i used the function send_mail instead of send and i have same problem

so i created a rule on model mail.message :

<record id="mes_email_rule" model="ir.rule">
        <field name="name">Email send</field>
        <field name="model_id" ref="mail.model_mail_message"/>
        <field name="domain_force">[(1,'=',1)]</field>
        <field name="groups" eval="[(4, ref('base.group_user'))]"/>
        <field eval="True" name="perm_unlink"/>
        <field eval="True" name="perm_write"/>
        <field eval="True" name="perm_read"/>
        <field eval="True" name="perm_create"/>

but still have the same problem.

1

1 Answers

0
votes

I resolved this by creating an action server with i call from my button to send email so i don't use the function send_email anymore.