From 2d688510d13fcf235574db725daecf265866042f Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 20 Feb 2020 09:57:43 +0000 Subject: [PATCH] [IMP] product: do not allow the deletion of the main product category --- addons/product/models/product.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index a1343337fa8..20e8c4fbb74 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -5,7 +5,7 @@ import logging import re from odoo import api, fields, models, tools, _ -from odoo.exceptions import ValidationError +from odoo.exceptions import UserError, ValidationError from odoo.osv import expression @@ -61,6 +61,11 @@ class ProductCategory(models.Model): def name_create(self, name): return self.create({'name': name}).name_get()[0] + def unlink(self): + main_category = self.env.ref('product.product_category_all') + if main_category in self: + raise UserError(_("You cannot delete this product category, it is the default generic category.")) + class ProductProduct(models.Model): _name = "product.product"