diff --git a/addons/product/i18n/product.pot b/addons/product/i18n/product.pot index 4513e590355..fc75f8df117 100644 --- a/addons/product/i18n/product.pot +++ b/addons/product/i18n/product.pot @@ -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 diff --git a/addons/product/models/product_document.py b/addons/product/models/product_document.py index 6b5cdc503d0..a0a0ad3b7ac 100644 --- a/addons/product/models/product_document.py +++ b/addons/product/models/product_document.py @@ -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