My question is:
I am automatically tagging customers depending on the analytic account from sales orders. Does a .write() always write on the record even when the value is already there? Should I be doing a check with an if statement to see if the tag has already been set? If so, how do I check that? I tried a few things and couldn't figure it out.
*Edit: I should have noted that my code is working well but I'm just wondering if I should be checking if the category_id value is already there before the write happens and if so how to check. I am still very much in the learning stage of Odoo development*
My code:
contact_tag_id = None project_id = record.project_id.id project_id_name = record.project_id.name partner_id = record.partner_id.commercial_partner_id.id if project_id == 44: contact_tag_id = 4 if project_id == 49: contact_tag_id = 6 if project_id == 48: contact_tag_id = 3 #Add the tag to contact if contact_tag_id != None: project_id = contact_tag_id env['res.partner'].search([('id','=',partner_id)]).sudo().write({'category_id': [(4, contact_tag_id)]})
i haven't known your model and type of variable, so i can't fix your code