Reviewers: ,

Description:
stock: Factorize field checks on StockMove write method

Please review this at http://codereview.tryton.org/891002/

Affected files:
  M move.py


Index: move.py
diff --git a/move.py b/move.py
index 1c05feb80a86678a8e92a0ae1cccecb42d52916c..c439e143aab7067e55f833d8540742d1b368522a 100644
--- a/move.py
+++ b/move.py
@@ -100,6 +100,12 @@ class Move(Workflow, ModelSQL, ModelView):
     @classmethod
     def __setup__(cls):
         super(Move, cls).__setup__()
+        cls._deny_modify_assigned = ['product', 'uom', 'quantity',
+            'from_location', 'to_location', 'company', 'unit_price',
+            'currency']
+        cls._deny_modify_done = (cls._deny_modify_assigned +
+            ['planned_date', 'effective_date', 'state'])
+
         cls._sql_constraints += [
             ('check_move_qty_pos',
'CHECK(quantity >= 0.0)', 'Move quantity must be positive'),
@@ -563,15 +569,13 @@ class Move(Workflow, ModelSQL, ModelView):

     @classmethod
     def write(cls, moves, vals):
- if reduce(lambda x, y: x or y in vals, ('product', 'uom', 'quantity',
-                'from_location', 'to_location', 'company', 'unit_price',
-                'currency'), False):
+        vals_set = set(vals)
+        if set(cls._deny_modify_assigned) & vals_set:
             for move in moves:
-                if move.state in ('assigned', 'done', 'cancel'):
+                if move.state == 'assigned':
                     cls.raise_user_error('modify_assigned_done_cancel',
                         (move.rec_name,))
-        if reduce(lambda x, y: x or y in vals,
-                ('planned_date', 'effective_date', 'state'), False):
+        if set(cls._deny_modify_done) & vals_set:
             for move in moves:
                 if move.state in ('done', 'cancel'):
                     cls.raise_user_error('modify_assigned_done_cancel',


Reply via email to