# HG changeset patch
# User Etienne Ferriere <etienne.ferriere@xcg-consulting.fr>
# Date 1528279946 -7200
#      Wed Jun 06 12:12:26 2018 +0200
# Branch 10.0
# Node ID 120224ee69e0c22ab7275490a5708a1ab779ad61
# Parent  366e2faa25e78d195bf851147383d175e7f970d8
Corrected a bug in the 'write' method override. Sometimes, the field, giving the
created analytic code name, is not immediately filled in the first write
processes, and only filled afterwards.

diff --git a/MetaAnalytic.py b/MetaAnalytic.py
--- a/MetaAnalytic.py
+++ b/MetaAnalytic.py
@@ -575,7 +575,8 @@
 
             context = self.env.context
             code_vals = {}
-            new = False
+            news = []
+            standard_process = False
 
             if sync_parent:
                 cp = self._get_code_parent(vals)
@@ -607,31 +608,31 @@
                     code_vals['name'] = vals[name_col]
                 if description_col in vals:
                     code_vals['description'] = vals[description_col]
-                codes = {rec: getattr(rec, column) for rec in self}
+                standard_process = True
 
             res = super(superclass, self).write(vals, **kwargs)
 
-            news = []
-
             # If updating records with no code, create these.
-            if codes:
+            if standard_process:
                 code_obj = self.env['analytic.code']
 
-                for rec, code in codes.iteritems():
+                for rec in self:
+
+                    code = getattr(rec, column)
 
                     rec_code_vals = code_vals.copy()
                     rec_vals = dict().copy()
 
-                    if 'name' not in rec_code_vals:
+                    if not rec_code_vals.get('name'):
                         rec_code_vals['name'] = \
                             rec.read([name_col])[0][name_col]
-                    if 'description' not in code_vals:
+                    if not rec_code_vals.get('description'):
                         rec_code_vals['description'] = (
                             self.read([description_col])[0]
                             [description_col]
                         )
 
-                    if not code and not getattr(rec, column):
+                    if not code and rec_code_vals.get('name'):
                         news.append(rec.id)
                         rec_code_vals['nd_id'] = rec._get_bound_dimension_id()
                         rec_code_vals['origin_id'] = \