Multi is the default api for methods, it is not necessary to explicitly decorate methods with it, adds clutter and most people use it because they see that the rest of the code uses it. Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class IrAttachment(models.Model):
|
|
_inherit = 'ir.attachment'
|
|
|
|
def _post_add_create(self):
|
|
""" Overrides behaviour when the attachment is created through the controller
|
|
"""
|
|
super(IrAttachment, self)._post_add_create()
|
|
for record in self:
|
|
record.register_as_main_attachment(force=False)
|
|
|
|
def register_as_main_attachment(self, force=True):
|
|
""" Registers this attachment as the main one of the model it is
|
|
attached to.
|
|
"""
|
|
self.ensure_one()
|
|
if not self.res_model:
|
|
return
|
|
related_record = self.env[self.res_model].browse(self.res_id)
|
|
# message_main_attachment_id field can be empty, that's why we compare to False;
|
|
# we are just checking that it exists on the model before writing it
|
|
if related_record and hasattr(related_record, 'message_main_attachment_id'):
|
|
if force or not related_record.message_main_attachment_id:
|
|
related_record.message_main_attachment_id = self
|