Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Action to create Project from sales order

Subscribe

Get notified when there's activity on this post

This question has been flagged
actionprojectsales.order
4 Replies
1793 Views
Avatar
Phred

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})


0
Avatar
Discard
Avatar
JB
Best Answer

Hello,

Please Refer the code:

1.Python code:

from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = "sale.order"


    project_id = fields.Many2one("project.project", string="Project")


    def action_create_project(self):

        Project = self.env["project.project"]

        for order in self:

            if not order.project_id:

                project = Project.create({

                    "name": order.name,

                    "partner_id": project.id

        return True


2. Xml Code

<record id="view_order_form_inherit_project" model="ir.ui.view">

    <field name="name">sale.order.form.inherit.project</field>

    <field name="model">sale.order</field>

    <field name="inherit_id" ref="sale.view_order_form"/>

    <field name="arch" type="xml">

        <header position="inside">

            <button name="action_create_project"

                    type="object"

                    string="Create Project"

                    class="btn-primary"

                    attrs="{'invisible': [('project_id','!=',False)]}"/>

        </header>

        <sheet position="after">

            <field name="project_id"/>

        </sheet>

    </field>

</record>


0
Avatar
Discard
Chris TRINGHAM

This isn't an answer to the question that has been asked!

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Please refer to the code:


from odoo import api, fields, models

from odoo.exceptions import UserError


class SaleOrder(models.Model):

    _inherit = "sale.order"


    project_id = fields.Many2one('project.project', string="Project")


    def action_create_project(self):

        for order in self:

            if order.project_id:

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


            seq = self.env['ir.sequence'].next_by_code('project.seq') or order.name

            opp_name = order.opportunity_id.name if order.opportunity_id else ""

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


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

                'name': project_name,

                'partner_id': order.partner_id.id,

            })

            order.project_id = project.id


Hope it helps.

0
Avatar
Discard
Avatar
D Enterprise
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

0
Avatar
Discard
Avatar
Ruchita
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.

-1
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Lifemiles teléfono ¿Cómo puedo llamar al soporte de Lifemiles?
action project
Avatar
0
Oct 25
3
How to show sales order data in the projects module Solved
project sales.order related_fields
Avatar
1
Jun 22
6949
Set project_id on new tasks automatically
action project automated
Avatar
3
Feb 20
4368
How to make a new save button? Solved
action project custom
Avatar
Avatar
1
Jul 19
15858
How to access my DNS?
action project chrome service
Avatar
0
Nov 25
40
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now