From dc9f3680c510ff2c59c78627988d14febcf413f0 Mon Sep 17 00:00:00 2001 From: Demesmaeker Date: Mon, 8 Apr 2024 09:47:14 +0200 Subject: [PATCH] [FIX] sale_pdf_quote_builder: ensure only pdf inside quote When creating a product document, it was still possible to save something that wasn't a pdf. The check only happened when modifying it. opw-3802795 closes odoo/odoo#160879 Signed-off-by: Morgane Demesmaeker --- .../models/product_document.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/sale_pdf_quote_builder/models/product_document.py b/addons/sale_pdf_quote_builder/models/product_document.py index a9accae1015..77c348b0d77 100644 --- a/addons/sale_pdf_quote_builder/models/product_document.py +++ b/addons/sale_pdf_quote_builder/models/product_document.py @@ -1,6 +1,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import _, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -20,11 +20,8 @@ class ProductDocument(models.Model): "header pages and the quote table. ", ) - def write(self, vals): - res = super().write(vals) - if vals.keys() & {'attached_on', 'mimetype'}: - if any( - doc.attached_on == 'inside' and not doc.mimetype.endswith('pdf') for doc in self - ): + @api.constrains('attached_on', 'datas') + def _check_attached_on_and_datas_compatibility(self): + for doc in self: + if doc.attached_on == 'inside' and not (doc.datas and doc.mimetype.endswith('pdf')): raise ValidationError(_("Only PDF documents can be attached inside a quote.")) - return res