[12.0] Add base_fileurl_field

This commit is contained in:
Akim Juillerat
2019-03-13 19:18:07 +01:00
parent a7207cc3e7
commit d83aca68e6
13 changed files with 297 additions and 0 deletions
@@ -0,0 +1,44 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = 'res.partner'
name = fields.Char()
url_file = fields.FileURL(
storage_location='s3',
filename='url_file_fname',
storage_path='partner'
)
url_file_fname = fields.Char()
url_image = fields.FileURL(
storage_location='s3',
filename='url_image_fname',
storage_path='partner_image',
)
url_image_fname = fields.Char()
@api.constrains('url_file', 'url_file_fname')
def _check_url_file_fname(self):
rec = self.search([('url_file_fname', '=', self.url_file_fname)])
if len(rec) > 1:
raise ValidationError(_(
"This file name is already used on an existing record. "
"Please use another file name or delete the url_file on :\n"
"Model: %s Id: %s" % (self._name, rec.id)
))
@api.constrains('url_image', 'url_image_fname')
def _check_url_image_fname(self):
rec = self.search([('url_image_fname', '=', self.url_image_fname)])
if len(rec) > 1:
raise ValidationError(_(
"This file name is already used on an existing record. "
"Please use another file name or delete the url_image on :\n"
"Model: %s Id: %s" % (self._name, rec.id)
))