Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
882 Zobrazení

The issue I have is that I have multiple companies and the Opportunity is created in Company A and the after when I create the Sales Order using that opportunity, I get an error saying opportunity is in a different company than the Sales Order. 

The User had a setting for Default Company and it is set to Company B.

If this is changed to Company A, it works.

The sales order is created in the default company. But the opportunity is not.

I just want to know how to fix this. Is there a way to set Opportunity default company ?

Even when I try send the 'company_id' in the payload when creating the opportunity, it gives and error. 

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

Hi, please check this: https://youtu.be/Cmbo2iGuTBY 
Hope it helps.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
pro 24
1065
0
zář 24
1082
1
bře 21
2278
2
led 24
12978
2
pro 24
1314