'Insert missing translations for `field` on `records`.'

@api.model
def insert_missing(self, field, records):

    records = records.with_context(lang=None)
    external_ids = records.get_external_id()
    if callable(field.translate):
        query = "    INSERT    INTO    ir_translation    (lang,    type,    name,    res_id,    src,    value,    module)\n                                                                                                SELECT    l.code,    'model',    %(name)s,    %(res_id)s,    %(src)s,    %(src)s,    %(module)s\n                                                                                                FROM    res_lang    l\n                                                                                                WHERE    l.active    AND    NOT    EXISTS    (\n                                                                                                                SELECT    1    FROM    ir_translation\n                                                                                                                WHERE    lang=l.code    AND    type='model'    AND    name=%(name)s    AND    res_id=%(res_id)s    AND    src=%(src)s\n                                                                                                );\n                                                                                "
        for record in records:
            module = external_ids[record.id].split('.')[0]
            src = (record[field.name] or None)
            for term in set(field.get_trans_terms(src)):
                self._cr.execute(query, {'name': ('%s,%s' % (field.model_name, field.name)), 'res_id': record.id, 'src': term, 'module': module})
    else:
        query = "    INSERT    INTO    ir_translation    (lang,    type,    name,    res_id,    src,    value,    module)\n                                                                                                SELECT    l.code,    'model',    %(name)s,    %(res_id)s,    %(src)s,    %(src)s,    %(module)s\n                                                                                                FROM    res_lang    l\n                                                                                                WHERE    l.active    AND    l.code    !=    'en_US'    AND    NOT    EXISTS    (\n                                                                                                                SELECT    1    FROM    ir_translation\n                                                                                                                WHERE    lang=l.code    AND    type='model'    AND    name=%(name)s    AND    res_id=%(res_id)s\n                                                                                                );\n                                                                                                UPDATE    ir_translation    SET    src=%(src)s\n                                                                                                WHERE    type='model'    AND    name=%(name)s    AND    res_id=%(res_id)s;\n                                                                                "
        for record in records:
            module = external_ids[record.id].split('.')[0]
            self._cr.execute(query, {'name': ('%s,%s' % (field.model_name, field.name)), 'res_id': record.id, 'src': (record[field.name] or None), 'module': module})
    self._modified_model(field.model_name)
