Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
992 Vistas

I am updating multiple of users when a crm.team or crm.lead is updated. The problem is, it's working in my local but not working in the server


I already make sure I upgrade the right module (more than 5 times) and I already try upgrade it with the terminal. And the code still not working


I show the variable in the view, it looks like the value only update the first time after upgrade because the value is filled but when any change after that, it's not changing


[Update 1]

I pass --dev=xml​ in the service and it works. But I read that we shouldn't pass this argument in production. But if I didn't do it, there will be no change when updating the value


Below is the code



class CrmLead(models.Model):
    _inherit = 'crm.lead'

    def write(self, vals):
        res = super(CrmLead, self).write(vals)

        # user_ids = self.user_id
        user_ids = self.env['res.users'].search([])
        if user_ids:
            self._update_visible_crm_lead_ids(user_ids)
        return res

    def _update_visible_crm_lead_ids(self, users):
        """
        1. Check the user. If the user is leader, get the members user_id. If not, just get user_id
        2. Get all crm_lead that has the user_id that we got from the first step
        3. Replace all visible_crm_lead_ids with the new one
        """
        for user in users:
            crm_team_based_on_leader = self.env['crm.team'].search([('user_id', '=', user.id)])
            all_user_to_get_all_crm_lead = user.ids
            if crm_team_based_on_leader:
                all_user_to_get_all_crm_lead = all_user_to_get_all_crm_lead + crm_team_based_on_leader.member_ids.ids
                all_user_to_get_all_crm_lead = list(set(all_user_to_get_all_crm_lead))
               
            all_crm_lead = self.env['crm.lead'].search([('user_id', 'in', all_user_to_get_all_crm_lead)]).ids

            user.visible_crm_lead_ids = [(6, 0, all_crm_lead)]
Avatar
Descartar
Mejor respuesta

Hi,
May be some code difference or extra apps in the production ? Also ensure your code is working in production by adding some logger in it.

Thanks

Avatar
Descartar
Autor

I use git to store the code. I check the latest commit in git and the latest pull on the server. Both are the same. I added some loggers to make sure the code is being executed and it is. But I don't know if it is the right data since there are already hundreds of data. I put some logger at first and last of the function to make sure the code is executed thoroughly.

Publicaciones relacionadas Respuestas Vistas Actividad
1
may 25
407
2
nov 24
992
0
nov 24
879
2
oct 24
812
0
ago 24
799