[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 <edm@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user