Skip to Content
Menu
This question has been flagged
1 Reply
2545 Views

If system user is a sales man, he can't see the right phonecall count in Calls smart button in res.partner form view ( it always shows 0 ), although when clicking the smart button he can see the right number of phone calls in phone calls list view.

my method is :
def _logged_phonecall_count(self, cr, uid, ids, field_name, arg, context=None):
            res = {}           
            for partner in self.browse(cr, uid, ids, context):
                logged = [] 
                for call in partner.phonecall_ids:
                    if call.state == 'done':
                        logged.append(call)
                res[partner.id] = len(logged)
            return res

the method returns the right number of phone calls in all cases, but if the user is a sales man it always disaplays 0 in the smart button count, and the sales man has access to those phonecalls

Avatar
Discard
Best Answer

I assume you found a way to fix this. But in case you didn't or someone has the same problem (which I also had), here is a solution that works for me. 

The thing is that Odoo doesn't count the calls from a "child" customer, so you need to edit the "_compute_phonecall_count" so that it counts every call the "parent" customer has done AND the customers derivated from him, which is esentially, their children. Here's my solution:

def_compute_phonecall_count(self):

    """Calculate number of phonecalls."""

    for partner in self:

        phonecall_count = 0

        phonecall_count += self.env["crm.phonecall"].search_count(

            [("partner_id", "=", partner.id)]

        )

        partner_childs = self.env["res.partner"].search(

            [("parent_id", "=", partner.id)]

        )

        phonecall_count += self.env["crm.phonecall"].search_count(

            [("partner_id", "in", partner_childs.ids)]

        )

        partner.phonecall_count = phonecall_count

Hope that helps someone :)

Avatar
Discard