From d50aa61cf70acb9e71c7317b56b3502985cdbf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 12 Sep 2018 15:13:09 +0200 Subject: [PATCH] [IMP] sale_management: prevent from archiving default template This will prevent confusion from the user at a later time. PR: #26801 task-1876864 --- addons/sale_management/models/sale_order_template.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/sale_management/models/sale_order_template.py b/addons/sale_management/models/sale_order_template.py index 6c4f1518657..a81c103415b 100644 --- a/addons/sale_management/models/sale_order_template.py +++ b/addons/sale_management/models/sale_order_template.py @@ -30,6 +30,15 @@ class SaleOrderTemplate(models.Model): help="This e-mail template will be sent on confirmation. Leave empty to send nothing.") active = fields.Boolean(default=True, help="If unchecked, it will allow you to hide the quotation template without removing it.") + @api.multi + def write(self, vals): + if 'active' in vals and not vals.get('active'): + template_id = self.env['ir.default'].get('sale.order', 'sale_order_template_id') + for template in self: + if template_id and template_id == template.id: + raise UserError('Before archiving "%s" please select another default template in the settings.' % template.name) + return super(SaleOrderTemplate, self).write(vals) + class SaleOrderTemplateLine(models.Model): _name = "sale.order.template.line"