parameters: (self)
return_statement: return True
docstring: Transfer the data from the temp table to ir.translation
docstring_summary: Transfer the data from the temp table to ir.translation
docstring_tokens: Transfer the data from the temp table to ir . translation
function: def finish(self):
          """ Transfer the data from the temp table to ir.translation """
          cr = self._cr
  
          # Step 0: insert rows in batch
          query = """ INSERT INTO %s (name, lang, res_id, src, type, imd_model,
                                      module, imd_name, value, state, comments)
                      VALUES """ % self._table
          for rows in cr.split_for_in_conditions(self._rows):
              cr.execute(query + ", ".join(["%s"] * len(rows)), rows)
  
          _logger.debug("ir.translation.cursor: We have %d entries to process", len(self._rows))
  
          # Step 1: resolve ir.model.data references to res_ids
          cr.execute(""" UPDATE %s AS ti
                            SET res_id = imd.res_id,
                                noupdate = imd.noupdate
                         FROM ir_model_data AS imd
                         WHERE ti.res_id IS NULL
                         AND ti.module IS NOT NULL AND ti.imd_name IS NOT NULL
                         AND ti.module = imd.module AND ti.imd_name = imd.name
                         AND ti.imd_model = imd.model; """ % self._table)
  
          if self._debug:
              cr.execute(""" SELECT module, imd_name, imd_model FROM %s
                             WHERE res_id IS NULL AND module IS NOT NULL """ % self._table)
              for row in cr.fetchall():
                  _logger.info("ir.translation.cursor: missing res_id for %s.%s <%s> ", *row)
  
          # Records w/o res_id must _not_ be inserted into our db, because they are
          # referencing non-existent data.
          cr.execute("DELETE FROM %s WHERE res_id IS NULL AND module IS NOT NULL" % self._table)
  
          count = 0
          # Step 2: insert new or upsert non-noupdate translations
          if self._overwrite:
              cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'code'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, lang, md5(src)) WHERE type = 'code'
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state,
                                                                                                               CASE WHEN %s.comments = 'openerp-web' THEN 'openerp-web' ELSE EXCLUDED.comments END
                                                                                                              )
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % (self._model_table, self._table, self._model_table))
              count += cr.rowcount
              cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'model'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, lang, name, res_id) WHERE type = 'model'
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state, EXCLUDED.comments)
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % (self._model_table, self._table))
              count += cr.rowcount
  
              cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'model_terms'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, name, lang, res_id, md5(src))
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state, EXCLUDED.comments)
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % (self._model_table, self._table))
              count += cr.rowcount
          cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                         SELECT name, lang, res_id, src, type, value, module, state, comments
                         FROM %s
                         WHERE %%s OR noupdate is true
                         ON CONFLICT DO NOTHING;
                     """ % (self._model_table, self._table), [not self._overwrite])
          count += cr.rowcount
  
          if self._debug:
              cr.execute("SELECT COUNT(*) FROM ONLY %s" % self._model_table)
              total = cr.fetchone()[0]
              _logger.debug("ir.translation.cursor: %d entries now in ir.translation, %d common entries with tmp", total, count)
  
          # Step 3: cleanup
          cr.execute("DROP TABLE %s" % self._table)
          self._rows.clear()
          return True
function_tokens: def finish ( self ) : cr = self . _cr # Step 0: insert rows in batch query = """ INSERT INTO %s (name, lang, res_id, src, type, imd_model,
                                      module, imd_name, value, state, comments)
                      VALUES """ % self . _table for rows in cr . split_for_in_conditions ( self . _rows ) : cr . execute ( query + ", " . join ( [ "%s" ] * len ( rows ) ) , rows ) _logger . debug ( "ir.translation.cursor: We have %d entries to process" , len ( self . _rows ) ) # Step 1: resolve ir.model.data references to res_ids cr . execute ( """ UPDATE %s AS ti
                            SET res_id = imd.res_id,
                                noupdate = imd.noupdate
                         FROM ir_model_data AS imd
                         WHERE ti.res_id IS NULL
                         AND ti.module IS NOT NULL AND ti.imd_name IS NOT NULL
                         AND ti.module = imd.module AND ti.imd_name = imd.name
                         AND ti.imd_model = imd.model; """ % self . _table ) if self . _debug : cr . execute ( """ SELECT module, imd_name, imd_model FROM %s
                             WHERE res_id IS NULL AND module IS NOT NULL """ % self . _table ) for row in cr . fetchall ( ) : _logger . info ( "ir.translation.cursor: missing res_id for %s.%s <%s> " , * row ) # Records w/o res_id must _not_ be inserted into our db, because they are # referencing non-existent data. cr . execute ( "DELETE FROM %s WHERE res_id IS NULL AND module IS NOT NULL" % self . _table ) count = 0 # Step 2: insert new or upsert non-noupdate translations if self . _overwrite : cr . execute ( """ INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'code'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, lang, md5(src)) WHERE type = 'code'
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state,
                                                                                                               CASE WHEN %s.comments = 'openerp-web' THEN 'openerp-web' ELSE EXCLUDED.comments END
                                                                                                              )
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % ( self . _model_table , self . _table , self . _model_table ) ) count += cr . rowcount cr . execute ( """ INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'model'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, lang, name, res_id) WHERE type = 'model'
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state, EXCLUDED.comments)
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % ( self . _model_table , self . _table ) ) count += cr . rowcount cr . execute ( """ INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                             SELECT name, lang, res_id, src, type, value, module, state, comments
                             FROM %s
                             WHERE type = 'model_terms'
                             AND noupdate IS NOT TRUE
                             ON CONFLICT (type, name, lang, res_id, md5(src))
                              DO UPDATE SET (name, lang, res_id, src, type, value, module, state, comments) = (EXCLUDED.name, EXCLUDED.lang, EXCLUDED.res_id, EXCLUDED.src, EXCLUDED.type, EXCLUDED.value, EXCLUDED.module, EXCLUDED.state, EXCLUDED.comments)
                              WHERE EXCLUDED.value IS NOT NULL AND EXCLUDED.value != '';
                         """ % ( self . _model_table , self . _table ) ) count += cr . rowcount cr . execute ( """ INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
                         SELECT name, lang, res_id, src, type, value, module, state, comments
                         FROM %s
                         WHERE %%s OR noupdate is true
                         ON CONFLICT DO NOTHING;
                     """ % ( self . _model_table , self . _table ) , [ not self . _overwrite ] ) count += cr . rowcount if self . _debug : cr . execute ( "SELECT COUNT(*) FROM ONLY %s" % self . _model_table ) total = cr . fetchone ( ) [ 0 ] _logger . debug ( "ir.translation.cursor: %d entries now in ir.translation, %d common entries with tmp" , total , count ) # Step 3: cleanup cr . execute ( "DROP TABLE %s" % self . _table ) self . _rows . clear ( ) return True