Skip to Content
Menu
This question has been flagged
3 Replies
5853 Views

Please give me code sample to achieve this scenario in cron job

I want method to check two fields values in two different classes. If the two field values match, then change all users status to expire except a user called Mark John.

Avatar
Discard
Author

from odoo import models, fields, api, _

class ResUsers(models.Model):

_inherit = "res.users"

@api.multi

def action_button_test(self):

# Code works

self.search([('login', '!=', 'admin')]).write({'active': False})

return True

The above code work well. But i want to check the value of field name "phone" in res.company and value of field name "mobile" in res.partner. So if value of phone and mobile does not match, then self.search([('login', '!=', 'admin')]).write({'active': False})

else

self.search([('active', '=', False)]).write({'active': True})

Please, what do i need to do to make it work.

Thanks in advance

Best Answer

Hi,

You can try something like this,


Code:

model1_rec = env['model1_name'].search([],limit=1)
model2_rec = env['model2_name'].search([],limit=1)
if model1_rec and model2_rec:
  if model1_rec.field_name == model2_rec.field_name:
    users = env['res.users'].search([('name', '!=', 'Mark John')])
    for user in users:
      user.write({'field_name': new_value})


Thanks

Avatar
Discard
Author Best Answer

@Niyas,

I have tried but not working

Avatar
Discard

model1_rec = env['model1_name'].search([],limit=1)

model2_rec = env['model2_name'].search([],limit=1)

if model1_rec and model2_rec:

if model1_rec.field_name == model2_rec.field_name:

users = self.env['res.users'].search([('name', '!=', 'Mark John')])

for user in users:

user.write({'field_name': new_value})