콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
1061 화면

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. 

아바타
취소
베스트 답변

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

아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
0
12월 24
1194
0
9월 24
1230
1
3월 21
2401
2
1월 24
13199
2
12월 24
1515