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

i have multiple companies setup.

i have sale form there is a field called workflow_process_id, 

i want this field having different default value based on which company_id

e.g. if company_id = 1 open the sale form, this workflow_id is 'workflow a'

how should i retrieve the company_id and modify this routine?


class SaleOrder(models.Model):    

​_inherit = "sale.order"
    ​workflow_process_id = fields.Many2one( 

  comodel_name="sale.workflow.process",        string="Automatic Workflow",

        ondelete="restrict",    )

아바타
취소
베스트 답변

Hii,

You can add option in company form to set the default workflow for each companies.

Add a Many2one Field in the Company Model:




and define the field in company form view also

after this modify the default_get function of sale.order model as below:




With these changes, users can select the default workflow for each company through the company form, and that selected workflow will be used as the default value for the workflow_process_id field when creating a sale order.


Hope this will help you
Thanks

아바타
취소
베스트 답변

you can try this way:
from odoo import models, fields, api


class SaleOrder(models.Model):

_inherit = "sale.order"


workflow_process_id = fields.Many2one(

comodel_name="sale.workflow.process",

string="Automatic Workflow",

ondelete="restrict",

)


@api.model

def create(self, vals):

# Check if company_id is present in vals

if 'company_id' in vals:

company_id = vals['company_id']

default_workflow = self.env['sale.workflow.process'].search([

('company_id', '=', company_id),

], limit=1)

if default_workflow:

vals['workflow_process_id'] = default_workflow.id


return super(SaleOrder, self).create(vals)


  1. We override the create method of the sale.order model.
  2. We check if the company_id is present in the values being passed to the method.
  3. We search for a sale.workflow.process record with a matching company_id.
  4. If a matching record is found, we set the workflow_process_id field to the ID of that record in the vals dictionary.
  5. Finally, we call the original create method to actually create the sale order.

Make sure to replace 'sale.workflow.process' with the actual model name of the workflow process, and adjust any other field names or model names as needed based on your actual Odoo configuration.

아바타
취소
관련 게시물 답글 화면 활동
1
12월 22
1649
3
11월 22
3623
1
11월 22
3998
1
5월 22
3394
0
2월 22
2014