Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
882 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
===================== | ||
CRM stage probability | ||
===================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fcrm-lightgray.png?logo=github | ||
:target: https://github.com/OCA/crm/tree/13.0/crm_stage_probability | ||
:alt: OCA/crm | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/crm-13-0/crm-13-0-crm_stage_probability | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/111/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module restore the CRM feature from Odoo <= 12.0 with lead probability | ||
according to its stage. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20crm_stage_probability%0Aversion:%2013.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 | ||
~~~~~~~ | ||
|
||
* Camptocamp | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Akim Juillerat <akim.juillerat@camptocamp.com> | ||
|
||
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. | ||
|
||
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/13.0/crm_stage_probability>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
{ | ||
"name": "CRM stage probability", | ||
"summary": "Define fixed probability on the stages", | ||
"version": "13.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Sales/CRM", | ||
"website": "https://github.com/OCA/crm", | ||
"author": "Camptocamp, Odoo Community Association (OCA), Odoo SA", | ||
"license": "AGPL-3", | ||
"depends": ["crm"], | ||
"data": [ | ||
"views/crm_lead.xml", | ||
"views/crm_stage.xml", | ||
"wizard/crm_lead_stage_probability_update.xml", | ||
"data/crm_stage.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo noupdate="1"> | ||
<record model="crm.stage" id="crm.stage_lead1"> | ||
<field name="on_change" eval="True" /> | ||
<field name="probability">10</field> | ||
</record> | ||
<record model="crm.stage" id="crm.stage_lead2"> | ||
<field name="on_change" eval="True" /> | ||
<field name="probability">30</field> | ||
</record> | ||
<record model="crm.stage" id="crm.stage_lead3"> | ||
<field name="on_change" eval="True" /> | ||
<field name="probability">70</field> | ||
</record> | ||
<record model="crm.stage" id="crm.stage_lead4"> | ||
<field name="on_change" eval="True" /> | ||
<field name="probability">100</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import crm_lead | ||
from . import crm_stage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import api, fields, models, tools | ||
|
||
|
||
class CrmLead(models.Model): | ||
|
||
_inherit = "crm.lead" | ||
|
||
def _default_probability(self): | ||
if "default_stage_id" in self._context: | ||
stage_id = self._context.get("default_stage_id") | ||
else: | ||
stage_id = self._default_stage_id() | ||
if stage_id: | ||
return self.env["crm.stage"].browse(stage_id).probability | ||
return 10 | ||
|
||
is_stage_probability = fields.Boolean( | ||
compute="_compute_is_stage_probability", readonly=True | ||
) | ||
stage_probability = fields.Float(related="stage_id.probability", readonly=True) | ||
probability = fields.Float(default=lambda self: self._default_probability()) | ||
|
||
@api.depends("probability", "stage_id", "stage_id.probability") | ||
def _compute_is_stage_probability(self): | ||
for lead in self: | ||
lead.is_stage_probability = ( | ||
tools.float_compare(lead.probability, lead.stage_probability, 2) == 0 | ||
) | ||
|
||
@api.depends("probability", "automated_probability") | ||
def _compute_is_automated_probability(self): | ||
for lead in self: | ||
if lead.probability != lead.stage_id.probability: | ||
super(CrmLead, lead)._compute_is_automated_probability() | ||
continue | ||
lead.is_automated_probability = False | ||
|
||
def _update_probability(self): | ||
self = self.with_context(_auto_update_probability=True) | ||
return super()._update_probability() | ||
|
||
@api.model | ||
def _onchange_stage_id_values(self, stage_id): | ||
""" returns the new values when stage_id has changed """ | ||
if not stage_id: | ||
return {} | ||
stage = self.env["crm.stage"].browse(stage_id) | ||
if stage.on_change: | ||
return {"probability": stage.probability} | ||
return {} | ||
|
||
@api.onchange("stage_id") | ||
def _onchange_stage_id(self): | ||
res = super()._onchange_stage_id() | ||
values = self._onchange_stage_id_values(self.stage_id.id) | ||
self.update(values) | ||
return res | ||
|
||
def write(self, vals): | ||
# Avoid to update probability with automated_probability on | ||
# _update_probability if the stage is set as on_change | ||
# If the stage is not set as on_change, auto PLS will be applied | ||
if ( | ||
self.env.context.get("_auto_update_probability") | ||
and "probability" in vals | ||
and "stage_id" not in vals | ||
): | ||
vals.update(self._onchange_stage_id_values(self.stage_id.id)) | ||
# Force to use the probability from the stage if set as on_change | ||
if vals.get("stage_id") and "probability" not in vals: | ||
vals.update(self._onchange_stage_id_values(vals.get("stage_id"))) | ||
return super().write(vals) | ||
|
||
def action_set_stage_probability(self): | ||
self.write({"probability": self.stage_id.probability}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2020 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import fields, models | ||
|
||
|
||
class CrmStage(models.Model): | ||
|
||
_inherit = "crm.stage" | ||
|
||
probability = fields.Float( | ||
"Probability (%)", | ||
required=True, | ||
default=10.0, | ||
help="This percentage depicts the default/average probability of the " | ||
"Case for this stage to be a success", | ||
) | ||
on_change = fields.Boolean( | ||
"Change Probability Automatically", | ||
help="Setting this stage will change the probability automatically on " | ||
"the opportunity.", | ||
) | ||
|
||
_sql_constraints = [ | ||
( | ||
"check_probability", | ||
"check(probability >= 0 and probability <= 100)", | ||
"The probability should be between 0% and 100%!", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Odoo SA | ||
* Akim Juillerat <akim.juillerat@camptocamp.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module restore the CRM feature from Odoo <= 12.0 with lead probability | ||
according to its stage. |
Oops, something went wrong.