diff --git a/CHANGELOG b/CHANGELOG
index 1e843ecdb7..5ee6de1d83 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Change probability into conversion probability
* Manage readonly state on Opportunity Line
Version 4.0.0 - 2016-05-02
diff --git a/opportunity.py b/opportunity.py
index beb2b855ba..b577073c03 100644
--- a/opportunity.py
+++ b/opportunity.py
@@ -8,7 +8,7 @@ from sql.aggregate import Max, Count, Sum
from sql.conditionals import Case
from sql.functions import Extract
-from trytond.model import ModelView, ModelSQL, Workflow, fields, Check
+from trytond.model import ModelView, ModelSQL, Workflow, fields
from trytond import backend
from trytond.pyson import Eval, In, If, Get, Bool
from trytond.transaction import Transaction
@@ -85,7 +85,12 @@ class SaleOpportunity(Workflow, ModelSQL, ModelView):
states=_STATES_STOP, depends=_DEPENDS_STOP)
state = fields.Selection(STATES, 'State', required=True, select=True,
sort=False, readonly=True)
- probability = fields.Integer('Conversion Probability', required=True,
+ conversion_probability = fields.Float('Conversion Probability',
+ digits=(1, 4), required=True,
+ domain=[
+ ('conversion_probability', '>=', 0),
+ ('conversion_probability', '<=', 1),
+ ],
states={
'readonly': ~Eval('state').in_(
['opportunity', 'lead', 'converted']),
@@ -138,16 +143,18 @@ class SaleOpportunity(Workflow, ModelSQL, ModelView):
where=sale.id == sale_id))
table.drop_column('sale', exception=True)
+ # Migration from 4.0: change probability into conversion probability
+ if table.column_exist('probability'):
+ cursor.execute(*sql_table.update(
+ [sql_table.conversion_probability],
+ [sql_table.probability / 100.0]))
+ table.drop_column('probability')
+ table.drop_constraint('check_percentage')
+
@classmethod
def __setup__(cls):
super(SaleOpportunity, cls).__setup__()
cls._order.insert(0, ('start_date', 'DESC'))
- t = cls.__table__()
- cls._sql_constraints += [
- ('check_percentage',
- Check(t, (t.probability >= 0) & (t.probability <= 100)),
- 'Probability must be between 0 and 100.')
- ]
cls._error_messages.update({
'delete_cancel': ('Sale Opportunity "%s" must be cancelled '
'before deletion.'),
@@ -199,8 +206,8 @@ class SaleOpportunity(Workflow, ModelSQL, ModelView):
return Date.today()
@staticmethod
- def default_probability():
- return 50
+ def default_conversion_probability():
+ return 0.5
@staticmethod
def default_company():
diff --git a/view/opportunity_form.xml b/view/opportunity_form.xml
index dab6448e4f..f3e82e3b44 100644
--- a/view/opportunity_form.xml
+++ b/view/opportunity_form.xml
@@ -17,8 +17,12 @@ this repository contains the full copyright notices and license terms. -->
-
-
+
+
+
+
+
diff --git a/view/opportunity_tree.xml b/view/opportunity_tree.xml
index 14f57f3db0..900f6d9b14 100644
--- a/view/opportunity_tree.xml
+++ b/view/opportunity_tree.xml
@@ -11,5 +11,7 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
+