From 900a8ae064d23ba050ecfeea3a4b46f17d6c5dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 30 Jun 2016 18:53:13 +0200 Subject: [PATCH] Manage readonly state on Opportunity Line issue5628 review27371002 --- CHANGELOG | 2 ++ opportunity.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 58cd7c562c..1e843ecdb7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Manage readonly state on Opportunity Line + Version 4.0.0 - 2016-05-02 * Bug fixes (see mercurial logs for details) * Rename Opportunity reference into number and add reference diff --git a/opportunity.py b/opportunity.py index eebb4a88f7..beb2b855ba 100644 --- a/opportunity.py +++ b/opportunity.py @@ -10,7 +10,7 @@ from sql.functions import Extract from trytond.model import ModelView, ModelSQL, Workflow, fields, Check from trytond import backend -from trytond.pyson import Eval, In, If, Get +from trytond.pyson import Eval, In, If, Get, Bool from trytond.transaction import Transaction from trytond.pool import Pool @@ -429,16 +429,33 @@ class SaleOpportunityLine(ModelSQL, ModelView): __name__ = "sale.opportunity.line" _rec_name = "product" _history = True - opportunity = fields.Many2One('sale.opportunity', 'Opportunity') + _states = { + 'readonly': Eval('opportunity_state').in_( + ['converted', 'won', 'lost', 'cancelled']), + } + _depends = ['opportunity_state'] + + opportunity = fields.Many2One('sale.opportunity', 'Opportunity', + states={ + 'readonly': _states['readonly'] & Bool(Eval('opportunity')), + }, + depends=_depends) + opportunity_state = fields.Function( + fields.Selection(STATES, 'Opportunity State'), + 'on_change_with_opportunity_state') sequence = fields.Integer('Sequence') product = fields.Many2One('product.product', 'Product', required=True, - domain=[('salable', '=', True)]) + domain=[('salable', '=', True)], states=_states, depends=_depends) quantity = fields.Float('Quantity', required=True, - digits=(16, Eval('unit_digits', 2)), depends=['unit_digits']) - unit = fields.Many2One('product.uom', 'Unit', required=True) + digits=(16, Eval('unit_digits', 2)), + states=_states, depends=['unit_digits'] + _depends) + unit = fields.Many2One('product.uom', 'Unit', required=True, + states=_states, depends=_depends) unit_digits = fields.Function(fields.Integer('Unit Digits'), 'on_change_with_unit_digits') + del _states, _depends + @classmethod def __setup__(cls): super(SaleOpportunityLine, cls).__setup__() @@ -459,6 +476,11 @@ class SaleOpportunityLine(ModelSQL, ModelView): table, _ = tables[None] return [Case((table.sequence == Null, 0), else_=1), table.sequence] + @fields.depends('opportunity', '_parent_opportunity.state') + def on_change_with_opportunity_state(self, name=None): + if self.opportunity: + return self.opportunity.state + @fields.depends('unit') def on_change_with_unit_digits(self, name=None): if self.unit: