Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
3180 Weergaven

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",    )

Avatar
Annuleer
Beste antwoord

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

Avatar
Annuleer
Beste antwoord

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.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 22
1641
3
nov. 22
3616
1
nov. 22
3994
1
mei 22
3394
0
feb. 22
2012