Files
Yannick Payot d17d229b13 Change CI to GitHub actions
Use copier template from oca/oca-addons-repo-template

Apply linting
2023-05-24 18:22:55 +02:00

47 lines
1.6 KiB
Python

# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import _, api, fields, models
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)
)
)