[FIX] delivery: Prevent Deliveries product category deletion

Purpose
=======

Lots of tickets are issues when the end user deleted this product
category, leading to the impossibility to install another carrier
as this category is referenced by all the specific carriers products

Ticket example: 3789116

closes odoo/odoo#158626

Taskid: 3802440
X-original-commit: 9383b6f4a5ef0394588c522efcc92e6f37a245cb
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Yannick Tivisse
2024-03-22 11:20:11 +00:00
parent fb3ce4fc9e
commit 091dcc31a5
3 changed files with 24 additions and 0 deletions
+8
View File
@@ -807,6 +807,14 @@ msgid ""
"\n"
msgstr ""
#. module: delivery
#: code:addons/delivery/models/product_category.py:0
#, python-format
msgid ""
"You cannot delete the deliveries product category as it is used on the "
"delivery carriers products."
msgstr ""
#. module: delivery
#: model:ir.actions.act_window,name:delivery.action_delivery_zip_prefix_list
msgid "Zip Prefix"
+1
View File
@@ -3,6 +3,7 @@
from . import delivery_carrier
from . import delivery_price_rule
from . import delivery_zip_prefix
from . import product_category
from . import res_partner
from . import sale_order
from . import sale_order_line
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, _
from odoo.exceptions import UserError
class ProductCategory(models.Model):
_inherit = "product.category"
@api.ondelete(at_uninstall=False)
def _unlink_except_delivery_category(self):
delivery_category = self.env.ref('delivery.product_category_deliveries', raise_if_not_found=False)
if delivery_category and delivery_category in self:
raise UserError(_("You cannot delete the deliveries product category as it is used on the delivery carriers products."))