OdooMindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
all_companies = self.env['res.company'].search([])
for lead in self:
if not lead.company_id:
lead.user_company_ids = all_companies
else:
lead.user_company_ids = lead.company_id