Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3142 มุมมอง

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 22
1607
odoo 13: inverse name in comodel แก้ไขแล้ว
3
พ.ย. 22
3581
1
พ.ย. 22
3964
1
พ.ค. 22
3369
0
ก.พ. 22
1995