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

I have a email field  sender_address  computed like:

    sender_address = fields.Char(
string='Sender email address', readonly=True, store=True,
compute='_compute_sender_address', index=True)
@api.multi
@api.depends('sender')
def _compute_sender_address(self):
for email in self:
if email.sender:
matches = re.search(r'<(.*@.*)>', email.sender)
if matches:
email.sender_address = matches.group(1).lower()
else:
email.sender_address = email.sender.lower()
else:
email.sender_address = False

Then I would like to use this email address to get res.users id:

    # get sender user_id
sender_id = fields.Many2one(
string='Sender User ID', comodel_name='res.users', readonly=True, store=True,
compute='_compute_sender_id', index=True)
@api.multi
@api.depends('sender_address')
def _compute_sender_id(self):
for email in self:
if email.sender_address:
email.sender_id = self.env['res.users'].search([('email', 'ilike', 'email.sender_address')], limit=1)
else:
email.sender_id = False

 print send_address is correct, but no sender_id.

There's no error in log, please help me how to find problem.


Avatar
Discard
Best Answer

Hi,

Just change this line

email.sender_id = self.env['res.users'].search
        ([('email', 'ilike', 'email.sender_address')], limit=1)
 

Thanks

Avatar
Discard
Author

Thanks @Niyas for your quick response. I tried it but not success.

But I change it to follow, it works now:

sender_mail = str(email.sender_address)

if email.sender_address:

email.sender_id = self.env['res.users'].search([('email', 'ilike', sender_mail)], limit=1)

So email.email.sender_address was not string and it was the problem right (y)

Related Posts Replies Views Activity
2
Mar 18
4220
2
Jul 24
414
1
Jan 24
424
2
Apr 24
1953
1
Aug 23
12549