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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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.
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
@Niyas,
I have tried but not working
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})
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
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