Hi,
Set the Opportunity's company_id explicitly via context or payload
When creating an opportunity programmatically or via API, you must ensure the company_id is properly passed and respected , and also the context should match.
But you're saying that sending company_id in the payload is not working — that's usually because of one of these issues:
Use correct company_id + context
When using RPC or API, do both:
# Example using XML-RPC
models.execute_kw(
db, uid, password,
'crm.lead', 'create',
[{
'name': 'New Opportunity',
'partner_id': partner_id,
'company_id': company_a_id, # make sure this is correct
}],
{'context': {'company_id': company_a_id}}
)
This ensures Odoo applies correct company rules for computed fields and security.
Set the default company of the user temporarily while creating
If you're in a custom module , or working with a user session, you can temporarily force the user's default company before creating the opportunity:
with self.env.company.id
return super().create(vals)
This ensures that even if no company_id is passed, it falls back to the current active company (not the user's default).
Fix user session or force company switch in frontend
If you're using the UI or web controller, Odoo uses the current active company (top-right selector). You need to either:
-
Make sure the user switches to the correct company before creating a sales order.
-
OR modify your workflow to automatically switch the company in session , if needed (only doable via custom frontend logic).
i hope it is use full