[FIX] product: Validate URLs on documents
Added a validation for URLs on product.document to resolve an issue where incomplete links on documents will redirect to a local URL instead of an external URL. Thus leading to a page that does not exist. e.g.: youtube.com instead of https://www.youtube.com This seemed like the proper course of action as there would be no reason to not validate as any URL within the database can still be formatted properly and work the same. api.constrains does not seem to work upon creation on this model, so I opted to use the api.onchange. opw-3698591 closes odoo/odoo#155806 Signed-off-by: Ryan Cen (ryce) <ryce@odoo.com> Co-authored-by: Morgane Demesmaeker (edm) <69820391+Demesmaeker@users.noreply.github.com>
This commit is contained in:
co-authored by
Morgane Demesmaeker
parent
5396941380
commit
bd32465d92
@@ -2055,6 +2055,17 @@ msgstr ""
|
||||
msgid "Please enter a positive whole number."
|
||||
msgstr ""
|
||||
|
||||
#. module: product
|
||||
#. odoo-python
|
||||
#: code:addons/product/models/product_document.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Please enter a valid URL.\n"
|
||||
"Example: https://www.odoo.com\n"
|
||||
"\n"
|
||||
"Invalid URL: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: product
|
||||
#. odoo-python
|
||||
#: code:addons/product/models/product_pricelist_item.py:0
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ProductDocument(models.Model):
|
||||
@@ -20,6 +21,16 @@ class ProductDocument(models.Model):
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
|
||||
@api.onchange('url')
|
||||
def _onchange_url(self):
|
||||
for attachment in self:
|
||||
if attachment.type == 'url' and attachment.url and\
|
||||
not attachment.url.startswith(('https://', 'http://', 'ftp://')):
|
||||
raise ValidationError(_(
|
||||
"Please enter a valid URL.\nExample: https://www.odoo.com\n\nInvalid URL: %s",
|
||||
attachment.url
|
||||
))
|
||||
|
||||
#=== CRUD METHODS ===#
|
||||
|
||||
@api.model_create_multi
|
||||
|
||||
Reference in New Issue
Block a user