[IMP] base: use many2one_reference for res_id on ir.attachment
This helps for updating inverse fields without making queries. Due to this change, a `flush` has to be added in the portal attachment test to actually compute the inverse after the change of `res_id`.
This commit is contained in:
committed by
Sébastien Theys
parent
afdfdbfa5b
commit
5d97c47e54
@@ -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.
|
||||
|
||||
@@ -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')],
|
||||
|
||||
Reference in New Issue
Block a user