Skip to Content
मेन्यू
This question has been flagged
2 Replies
318 Views

I want to be able to create a project from the sales order. Odoo seems to only allow this for a sales order with 'service' products, but I want to create a project for any sales order, regardless of the product.


The only way I can work out to achieve this is with an 'execute code' server action, as below.


This seems to achieve what I want, however as I am on an enterprise license I have to pay extra to use the code, so I am hoping there is a simpler solution to this. Also my python experience is quite limited and I am unsure if I have coded this in a reliable way...


Does anyone know of a better solution to this problem? any help is much appreciated.

if record.project_id:
    raise UserError("This Sales Order already has a linked project.")
   
# Get sequence number
seq = env['ir.sequence'].next_by_code('project.seq')

# Combine with opportunity name if available
if record.opportunity_id:
    opp_name = record.opportunity_id.name
else:
    opp_name = ""

if opp_name:
    project_name = f"{seq} | {opp_name}"
else:
    project_name = seq

# Create project
project = env['project.project'].create({
    'name': project_name,
    'partner_id': record.partner_id.id,
    'use_documents': False,
})

record.write({'project_id': project.id})


Avatar
Discard
Best Answer

In Odoo, a project is typically created from a Sales Order when you sell a service product that is configured to trigger project creation.

✅ Steps:

  1. Go to Sales > Products and open the service product.
  2. Set:
    • Product Type: Service
    • Service Invoicing Policy: Based on Milestones or Timesheets on Tasks
    • Service Tracking: Choose one of the following:
      • Create a task in an existing project
      • Create a new project but no task
      • Create a new project and task
  3. When you confirm a Sales Order containing that product, Odoo will automatically create the project or task depending on your selection.

You can then manage the project from the Projects module.

Avatar
Discard
Best Answer

Hi,

if record. project_id:

    raise UserError("This Sales Order already has a linked project.")


# Get sequence value or fallback

seq = env['ir.sequence'].next_by_code('project.seq') or 'NEW/PROJECT'


# Get opportunity name if exists

opp_name = record.opportunity_id.name if record.opportunity_id else ''


# Build project name

project_name = f"{seq} | {opp_name}" if opp_name else seq


# Create new project

project = env['project.project'].create({

    'name': project_name,

    'partner_id': project.id })

try this 
i hope it is use full

Avatar
Discard
Related Posts Replies Views Activity
1
जून 22
6164
3
फ़र॰ 20
3594
1
जुल॰ 19
14994
1
अप्रैल 24
1433
0
सित॰ 23
1349