Skip to content

Commit

Permalink
Merge d5f17de into 3bca37a
Browse files Browse the repository at this point in the history
  • Loading branch information
grindtildeath committed Jan 14, 2020
2 parents 3bca37a + d5f17de commit 8aacd7f
Show file tree
Hide file tree
Showing 17 changed files with 882 additions and 0 deletions.
74 changes: 74 additions & 0 deletions crm_stage_probability/README.rst
@@ -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.
2 changes: 2 additions & 0 deletions crm_stage_probability/__init__.py
@@ -0,0 +1,2 @@
from . import models
from . import wizard
19 changes: 19 additions & 0 deletions crm_stage_probability/__manifest__.py
@@ -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",
],
}
19 changes: 19 additions & 0 deletions crm_stage_probability/data/crm_stage.xml
@@ -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>
2 changes: 2 additions & 0 deletions crm_stage_probability/models/__init__.py
@@ -0,0 +1,2 @@
from . import crm_lead
from . import crm_stage
77 changes: 77 additions & 0 deletions crm_stage_probability/models/crm_lead.py
@@ -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})
29 changes: 29 additions & 0 deletions crm_stage_probability/models/crm_stage.py
@@ -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%!",
)
]
2 changes: 2 additions & 0 deletions crm_stage_probability/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Odoo SA
* Akim Juillerat <akim.juillerat@camptocamp.com>
2 changes: 2 additions & 0 deletions crm_stage_probability/readme/DESCRIPTION.rst
@@ -0,0 +1,2 @@
This module restore the CRM feature from Odoo <= 12.0 with lead probability
according to its stage.

0 comments on commit 8aacd7f

Please sign in to comment.