Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions project_estimation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
==================
Project Estimation
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0faffaf36b0c57e81ee69946cb1d5445d5dae4f3efa82e3e0219d5f7a1fec03e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github
:target: https://github.com/OCA/project/tree/18.0/project_estimation
:alt: OCA/project
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/project-18-0/project-18-0-project_estimation
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is a pre-sales module designed to manage project cost
estimation before confirming a Sales Order.

In many service-based businesses, project discussions start with rough
calculations, scope alignment, and internal margin validation. Creating
a full Project too early can mix pre-sales assumptions with confirmed
execution data. This module separates the estimation phase from the
execution phase.

The purpose of this module is to:

- Provide a structured space for cost calculation before commitment
- Allow internal validation of pricing and margin
- Prevent pollution of confirmed Project data with unvalidated
assumptions
- Enable clean conversion to Sales Order once approved

This module represents the commercial negotiation stage, not the
operational delivery stage.

Once the estimation is validated and approved, it can be converted into
a Sales Order. If the deal does not proceed, the estimation can simply
be cancelled without impacting project reporting.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Go to menu Project > Estimation
2. Create a new Project Estimation
3. Add estimation lines such as services, materials, or working hours.
For each line, define quantity, cost, and price.
4. Review the overall estimation. Adjust pricing or quantities until the
expected margin meets business requirements.
5. Once internally validated, confirm the estimation.
6. Click Create Sales Order. It will generate a Sales Order based on the
estimation lines, and the standard sales workflow continues from
there.
7. If the deal does not proceed, simply cancel the estimation. No
Project or accounting records will be affected.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/project/issues/new?body=module:%20project_estimation%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- `Ecosoft <https://ecosoft.co.th>`__:

- Saran Lim. saranl@ecosoft.co.th

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
:target: https://github.com/Saran440
:alt: Saran440

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Saran440|

This module is part of the `OCA/project <https://github.com/OCA/project/tree/18.0/project_estimation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions project_estimation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizard
24 changes: 24 additions & 0 deletions project_estimation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2026 Ecosoft Co., Ltd (https://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Project Estimation",
"summary": "Pre-sales project cost estimation and margin calculation",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/project",
"depends": ["project", "sale_project"],
"data": [
"data/sequence.xml",
"security/project_estimation_security.xml",
"security/ir.model.access.csv",
"security/res_groups.xml",
"wizard/create_sale_order_view.xml",
"views/res_config_settings_views.xml",
"views/project_estimation_views.xml",
"views/sale_order_view.xml",
],
"development_status": "Alpha",
"maintainers": ["Saran440"],
}
10 changes: 10 additions & 0 deletions project_estimation/data/sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="project_estimation_code_seq" model="ir.sequence">
<field name="name">Project Estimation</field>
<field name="code">project.estimation</field>
<field name="prefix">PEST</field>
<field name="padding">5</field>
<field name="company_id" eval="False" />
</record>
</odoo>
6 changes: 6 additions & 0 deletions project_estimation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import res_config_settings
from . import project_estimation
from . import project_estimation_line
from . import sale_order
214 changes: 214 additions & 0 deletions project_estimation/models/project_estimation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# Copyright 2026 Ecosoft Co., Ltd (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.exceptions import UserError


class ProjectEstimation(models.Model):
_name = "project.estimation"
_inherit = ["mail.thread", "mail.activity.mixin"]
_description = "Project Estimation"
_order = "name desc"

name = fields.Char(
default="/",
required=True,
copy=False,
)
partner_id = fields.Many2one(
comodel_name="res.partner",
required=True,
tracking=True,
)
project_id = fields.Many2one(
comodel_name="project.project",
tracking=True,
)
sale_order_ids = fields.One2many(
comodel_name="sale.order",
inverse_name="project_estimation_id",
copy=False,
)
date = fields.Date(
string="Estimation Date",
default=fields.Date.today,
required=True,
tracking=True,
)
user_id = fields.Many2one(
comodel_name="res.users",
string="Responsible",
default=lambda self: self.env.user,
tracking=True,
)
company_id = fields.Many2one(
comodel_name="res.company",
required=True,
default=lambda self: self.env.company,
)
currency_id = fields.Many2one(
comodel_name="res.currency",
compute="_compute_currency_id",
store=True,
)
line_ids = fields.One2many(
comodel_name="project.estimation.line",
inverse_name="estimation_id",
string="Estimation Lines",
copy=True,
)

amount_untaxed = fields.Monetary(
string="Untaxed Amount", store=True, compute="_compute_amounts", tracking=5
)
amount_tax = fields.Monetary(string="Taxes", store=True, compute="_compute_amounts")
amount_total = fields.Monetary(
string="Total", store=True, compute="_compute_amounts", tracking=4
)

total_cost = fields.Monetary(
compute="_compute_totals",
store=True,
)
total_margin = fields.Monetary(
compute="_compute_totals",
store=True,
)
total_margin_percent = fields.Float(
string="Total Margin (%)",
compute="_compute_totals",
store=True,
)
target_margin = fields.Float(
string="Target Margin (%)",
)
target_sale_price = fields.Monetary(
compute="_compute_target_sale_price",
store=True,
)
expected_profit = fields.Monetary(
compute="_compute_expected_profit",
store=True,
)
state = fields.Selection(
selection=[
("draft", "Draft"),
("confirm", "Confirmed"),
("approved", "Approved"),
("done", "Done"),
("cancelled", "Cancelled"),
],
default="draft",
tracking=True,
)
note = fields.Html(string="Notes")

@api.depends("line_ids.price_subtotal", "currency_id", "company_id")
def _compute_amounts(self):
AccountTax = self.env["account.tax"]
for rec in self:
lines = rec.line_ids.filtered(lambda x: not x.display_type)
base_lines = [
line._prepare_base_line_for_taxes_computation() for line in lines
]
AccountTax._add_tax_details_in_base_lines(base_lines, rec.company_id)
AccountTax._round_base_lines_tax_details(base_lines, rec.company_id)
tax_totals = AccountTax._get_tax_totals_summary(
base_lines=base_lines,
currency=rec.currency_id or rec.company_id.currency_id,
company=rec.company_id,
)
rec.amount_untaxed = tax_totals["base_amount_currency"]
rec.amount_tax = tax_totals["tax_amount_currency"]
rec.amount_total = tax_totals["total_amount_currency"]

@api.depends("company_id")
def _compute_currency_id(self):
for rec in self:
rec.currency_id = rec.company_id.currency_id

@api.depends("line_ids.price_subtotal", "line_ids.margin", "line_ids.cost_subtotal")
def _compute_totals(self):
for rec in self:
rec.total_cost = sum(rec.line_ids.mapped("cost_subtotal"))
rec.total_margin = sum(rec.line_ids.mapped("margin"))
rec.total_margin_percent = (
rec.amount_untaxed and rec.total_margin / rec.amount_untaxed
)

@api.depends("total_cost", "target_margin")
def _compute_target_sale_price(self):
for rec in self:
margin = rec.target_margin
if margin >= 100:
rec.target_sale_price = 0.0
elif margin > 0:
rec.target_sale_price = rec.total_cost / (1 - margin / 100)
else:
rec.target_sale_price = rec.total_cost

@api.depends("target_sale_price", "total_cost")
def _compute_expected_profit(self):
for rec in self:
rec.expected_profit = rec.target_sale_price - rec.total_cost

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", "/") == "/":
vals["name"] = (
self.env["ir.sequence"].next_by_code("project.estimation") or "/"
)
return super().create(vals_list)

def action_confirm(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State transition methods have no precondition checks. For example, action_approve() can be called regardless of the current state. Consider validating the current state before transitioning, e.g.:

def action_approve(self):
    for rec in self:
        if rec.state != 'confirm':
            raise UserError(self.env._("Only confirmed estimations can be approved."))
    return self.write({"state": "approved"})

return self.write({"state": "confirm"})

def action_approve(self):
return self.write({"state": "approved"})

def action_cancel(self):
return self.write({"state": "cancelled"})

def action_done(self):
return self.write({"state": "done"})

def action_draft(self):
return self.write({"state": "draft"})

def action_create_sale_order(self):
"""Open wizard to create a Sale Order from the estimation."""
self.ensure_one()
if not self.line_ids:
raise UserError(self.env._("Please add at least one estimation line."))
return {
"name": self.env._("Create Sale Order"),
"type": "ir.actions.act_window",
"res_model": "project.estimation.create.sale.order",
"view_mode": "form",
"target": "new",
"context": {
"default_estimation_id": self.id,
},
}

def action_view_sale_order(self):
self.ensure_one()
return {
"name": self.env._("Sale Order"),
"type": "ir.actions.act_window",
"res_model": "sale.order",
"view_mode": "list,form",
"domain": [("project_estimation_id", "=", self.id)],
}

def action_view_project(self):
self.ensure_one()
return {
"name": self.env._("Project"),
"type": "ir.actions.act_window",
"res_model": "project.project",
"view_mode": "form",
"res_id": self.project_id.id,
}
Loading
Loading