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)]