diff --git a/addons/account/tests/test_portal_attachment.py b/addons/account/tests/test_portal_attachment.py index 2aa1b4eff2c..182c0d33a9b 100644 --- a/addons/account/tests/test_portal_attachment.py +++ b/addons/account/tests/test_portal_attachment.py @@ -32,7 +32,7 @@ class TestUi(tests.HttpCase): files = [('file', ('test.txt', b'test', 'plain/text'))] res = self.url_open(url=create_url, data=create_data, files=files) self.assertEqual(res.status_code, 400) - self.assertTrue("you do not have the rights" in res.text) + self.assertIn("you do not have the rights", res.text) # Test public user can create attachment with token create_data['access_token'] = invoice._portal_ensure_token() @@ -73,7 +73,7 @@ class TestUi(tests.HttpCase): res = self.opener.post(url=remove_url, json={'params': remove_data}) self.assertEqual(res.status_code, 200) self.assertTrue(self.env['ir.attachment'].search([('id', '=', create_res['id'])])) - self.assertTrue("you do not have the rights" in res.text) + self.assertIn("you do not have the rights", res.text) # Test attachment can be removed with token if "pending" state remove_data['access_token'] = create_res['access_token'] @@ -95,13 +95,14 @@ class TestUi(tests.HttpCase): res = self.opener.post(url=remove_url, json={'params': remove_data}) self.assertEqual(res.status_code, 200) self.assertTrue(self.env['ir.attachment'].search([('id', '=', attachment.id)])) - self.assertTrue("not in a pending state" in res.text) + self.assertIn("not in a pending state", res.text) # Test attachment can't be removed if attached to a message attachment.write({ 'res_model': 'mail.compose.message', 'res_id': 0, }) + attachment.flush() message = self.env['mail.message'].create({ 'attachment_ids': [(6, 0, attachment.ids)], }) @@ -112,7 +113,7 @@ class TestUi(tests.HttpCase): res = self.opener.post(url=remove_url, json={'params': remove_data}) self.assertEqual(res.status_code, 200) self.assertTrue(attachment.exists()) - self.assertTrue("it is linked to a message" in res.text) + self.assertIn("it is linked to a message", res.text) message.unlink() # Test attachment can't be associated if no attachment token. diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index d98a52b8ef1..11eacf623fc 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -281,7 +281,8 @@ class IrAttachment(models.Model): res_name = fields.Char('Resource Name', compute='_compute_res_name') res_model = fields.Char('Resource Model', readonly=True, help="The database object this attachment will be attached to.") res_field = fields.Char('Resource Field', readonly=True) - res_id = fields.Integer('Resource ID', readonly=True, help="The record id this is attached to.") + res_id = fields.Many2oneReference('Resource ID', model_field='res_model', + readonly=True, help="The record id this is attached to.") company_id = fields.Many2one('res.company', string='Company', change_default=True, default=lambda self: self.env.company) type = fields.Selection([('url', 'URL'), ('binary', 'File')],