This question has been flagged
5 Replies
4632 Views

I have a problem that one custom module have on Button it should shows the no of unread messages in inbox, when we click on that its directly go to inbox view of messaging.i don't know how to solve it, if anybody have idea about this problem , please share, or any suggestion also welcome  to solve this problem.

Thanks

Logicious.

Avatar
Discard

@Axel Mendoza:- Thanks axel, I am familiar with how to add button in our form view, but i am not familiar with how to redirect the view, if you have any example of similar cases please give a chance to make it happen, Thanks , Logicious

let me update the previos answer

@Axel: thanks Axel , i got one error "unread_count " doesn't defined in your system, and also i tried to remove that one, then again the error arise parsing opt/odoo/odoo somthing similar to this.

Best Answer

Yes this could be done in a form, like this:

<div class="oe_right oe_button_box" name="buttons">
    <button class="oe_inline oe_stat_button" type="object" name="open_inbox" icon="fa-envelope" context="{'partner_id': partner_id}">
        <field string="Unread" name="unread_count" widget="statinfo"/>
    </button>
</div>

With that code in your form view you will see a button that show the number of unread messages in your inbox using the field unread_count that you need to implement as a function field for return the integer number. Also you need to implement a method open_inbox that returns the action view definition, or you could directly define your button type="action" and the name="%(action_record_id)d"

This code is using ir.actions.client because that is the type of action for the inbox

def open_inbox(self, cr, uid, ids, context=None):
    mod_obj = self.pool.get('ir.model.data')
    act_obj = self.pool.get('ir.actions.client')
    res_id = mod_obj.xmlid_to_res_id(cr, uid, 'mail.action_mail_inbox_feeds', raise_if_not_found=True)
    result = act_obj.read(cr, uid, [res_id], context=context)[0]
    return result
Avatar
Discard
Best Answer

Try this function:- I write this function to get the messages for my own purpose, you just make the code as your needs,

def inbox_tree_view(self, cr, uid, ids, context):
project_obj=self.pool.get('project.project')
msg_obj=self.pool.get('mail.message')
data=self.browse(cr,uid,ids[0])
matter_name=data.name

message_ids = msg_obj.search(cr, uid, [])
domain_id_list=[]
for message_id in message_ids:
matter_name_messahe=msg_obj.browse(cr,uid,message_id).parent_id.record_name
if matter_name==matter_name_messahe:
domain_id_list.append(message_id)


print'domain_id_list-----------',domain_id_list
domain = [('id','in', domain_id_list)]
res_id = ids and ids[0] or False
print"ppppppppppppppppppp", res_id
return {
'name': _('Inbox Messages'),
'domain': domain,
'res_model': 'mail.message',
'type': 'ir.actions.act_window',
'view_id': False,
'view_mode': 'tree,form',
'view_type': 'form',
'limit': 80,
'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
}

Avatar
Discard