Reviewers: ,


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

Affected files:
  M move.py


Index: move.py
===================================================================

--- a/move.py
+++ b/move.py
@@ -601,6 +601,7 @@
     @classmethod
     def __setup__(cls):
         super(Line, cls).__setup__()
+        cls._check_modify_include = ['reconciliation']
         cls._sql_constraints += [
             ('credit_debit',
                 'CHECK(credit * debit = 0.0)',
@@ -1247,19 +1248,21 @@
         '''
         Check if the lines can be modified
         '''
-        journal_period_done = []
-        for line in lines:
-            if line.move.state == 'posted':
-                cls.raise_user_error('modify_posted_move', (
-                        line.move.rec_name,))
-            if line.reconciliation:
-                cls.raise_user_error('modify_reconciled', (
-                        line.rec_name,))
-            journal_period = (line.journal.id, line.period.id)
-            if journal_period not in journal_period_done:
-                cls.check_journal_period_modify(line.period,
-                        line.journal)
-                journal_period_done.append(journal_period)
+        if not Transaction().context.get('account_move_line_check_modify',
+                False):
+            journal_period_done = []
+            for line in lines:
+                if line.move.state == 'posted':
+                    cls.raise_user_error('modify_posted_move', (
+                            line.move.rec_name,))
+                if line.reconciliation:
+                    cls.raise_user_error('modify_reconciled', (
+                            line.rec_name,))
+                journal_period = (line.journal.id, line.period.id)
+                if journal_period not in journal_period_done:
+                    cls.check_journal_period_modify(line.period,
+                            line.journal)
+                    journal_period_done.append(journal_period)

     @classmethod
     def delete(cls, lines):
@@ -1271,16 +1274,26 @@

     @classmethod
     def write(cls, lines, vals):
-        Move = Pool().get('account.move')
+        allow_write = True
+        for line in lines:
+            if line.move_state == 'posted':
+                keys = cls._check_modify_include
+                for key in vals.keys():
+                    if key not in keys:
+                        vals.pop(key, False)
+                allow_write &= bool(vals.keys())
+        with Transaction().set_context(
+                account_move_line_check_modify=allow_write):
+            Move = Pool().get('account.move')

-        if len(vals) > 1 or 'reconciliation' not in vals:
-            cls.check_modify(lines)
-        moves = [x.move for x in lines]
-        super(Line, cls).write(lines, vals)
+            if len(vals) > 1 or 'reconciliation' not in vals:
+                cls.check_modify(lines)
+            moves = [x.move for x in lines]
+            super(Line, cls).write(lines, vals)

-        Transaction().timestamp = {}
+            Transaction().timestamp = {}

-        Move.validate_move(list(set(l.move for l in lines) | set(moves)))
+ Move.validate_move(list(set(l.move for l in lines) | set(moves)))

     @classmethod
     def create(cls, vlist):



Reply via email to