diff --git a/odoo/addons/base/tests/test_translate.py b/odoo/addons/base/tests/test_translate.py index 449723a4150..f83ac3ff252 100644 --- a/odoo/addons/base/tests/test_translate.py +++ b/odoo/addons/base/tests/test_translate.py @@ -696,7 +696,7 @@ class TestTranslationWrite(TransactionCase): self.assertEqual(belgium.with_context(lang='en_US').vat_label, '') self.assertEqual(belgium.with_context(lang='nl_NL').vat_label, '') - def test_cresate_emtpy_false(self): + def test_create_empty_false(self): self._test_create_empty(False) # feature removed @@ -1040,6 +1040,21 @@ class TestXMLTranslation(TransactionCase): self.assertEqual(view.with_context(lang='fr_FR').arch_db, '
Pain et fromage
Fourchette2
') self.assertEqual(view.with_context(lang='nl_NL').arch_db, view_nl) + +class TestHTMLTranslation(TransactionCase): + def test_write_non_existing(self): + html = ''' +

My First Heading

+

My first paragraph.

+''' + company = self.env['res.company'].browse(9999) + company.report_footer = html + self.assertHTMLEqual(company.report_footer, html) + # flushing on non-existing records does not break for scalar fields; the + # same behavior is expected for translated fields + company.flush_recordset() + + @tagged('post_install', '-at_install') class TestLanguageInstallPerformance(TransactionCase): def test_language_install(self): diff --git a/odoo/fields.py b/odoo/fields.py index a6498458645..d7dbac69743 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1738,7 +1738,8 @@ class _String(Field): record.flush_recordset([self.name]) cr = record.env.cr cr.execute(f'SELECT "{self.name}" FROM "{record._table}" WHERE id = %s', (record.id,)) - return cr.fetchone()[0] + res = cr.fetchone() + return res[0] if res else None def write(self, records, value): if not self.translate or value is False or value is None: