diff --git a/crm_claim_extra_ref_dependency/README.rst b/crm_claim_extra_ref_dependency/README.rst new file mode 100644 index 00000000..612b742d --- /dev/null +++ b/crm_claim_extra_ref_dependency/README.rst @@ -0,0 +1,30 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================== +Crm claim extra ref dependency +============================== + +* Before deleting a purchase order, sales order, or picking, verify that they + are not referenced in any claims. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Alfredo de la Fuente diff --git a/crm_claim_extra_ref_dependency/__init__.py b/crm_claim_extra_ref_dependency/__init__.py new file mode 100644 index 00000000..9186ee3a --- /dev/null +++ b/crm_claim_extra_ref_dependency/__init__.py @@ -0,0 +1 @@ +from . import model diff --git a/crm_claim_extra_ref_dependency/__manifest__.py b/crm_claim_extra_ref_dependency/__manifest__.py new file mode 100644 index 00000000..85425366 --- /dev/null +++ b/crm_claim_extra_ref_dependency/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "CRM Claim Extra Ref Dependency", + "version": "16.0.1.0.0", + "author": "AvanzOSC", + "category": "CRM Claim", + "license": "AGPL-3", + "website": "https://github.com/avanzosc/crm-addons", + "depends": ["crm_claim_extra_ref", "purchase", "sale", "stock"], + "data": [], + "installable": True, + "auto_install": True, +} diff --git a/crm_claim_extra_ref_dependency/i18n/ca_ES.po b/crm_claim_extra_ref_dependency/i18n/ca_ES.po new file mode 100644 index 00000000..0b71731f --- /dev/null +++ b/crm_claim_extra_ref_dependency/i18n/ca_ES.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_claim_extra_ref_dependency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-01-28 12:22+0000\n" +"PO-Revision-Date: 2026-01-28 12:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_purchase_order +msgid "Purchase Order" +msgstr "Comanda de compra" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_sale_order +msgid "Sales Order" +msgstr "Comanda de venda" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_stock_picking +msgid "Transfer" +msgstr "Transferència" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/stock_picking.py:0 +#, python-format +msgid "" +"You cannot delete the picking: %(picking_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/purchase_order.py:0 +#, python-format +msgid "" +"You cannot delete the purchase order: %(purchase_name)s, because it is being" +" used in the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/sale_order.py:0 +#, python-format +msgid "" +"You cannot delete the sale order: %(sale_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" diff --git a/crm_claim_extra_ref_dependency/i18n/crm_claim_extra_ref_dependency.pot b/crm_claim_extra_ref_dependency/i18n/crm_claim_extra_ref_dependency.pot new file mode 100644 index 00000000..d8efa5c4 --- /dev/null +++ b/crm_claim_extra_ref_dependency/i18n/crm_claim_extra_ref_dependency.pot @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_claim_extra_ref_dependency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-01-28 12:21+0000\n" +"PO-Revision-Date: 2026-01-28 12:21+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/stock_picking.py:0 +#, python-format +msgid "" +"You cannot delete the picking: %(picking_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/purchase_order.py:0 +#, python-format +msgid "" +"You cannot delete the purchase order: %(purchase_name)s, because it is being" +" used in the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/sale_order.py:0 +#, python-format +msgid "" +"You cannot delete the sale order: %(sale_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" diff --git a/crm_claim_extra_ref_dependency/i18n/en_US.po b/crm_claim_extra_ref_dependency/i18n/en_US.po new file mode 100644 index 00000000..a09bf1db --- /dev/null +++ b/crm_claim_extra_ref_dependency/i18n/en_US.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_claim_extra_ref_dependency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-01-28 12:22+0000\n" +"PO-Revision-Date: 2026-01-28 12:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/stock_picking.py:0 +#, python-format +msgid "" +"You cannot delete the picking: %(picking_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/purchase_order.py:0 +#, python-format +msgid "" +"You cannot delete the purchase order: %(purchase_name)s, because it is being" +" used in the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/sale_order.py:0 +#, python-format +msgid "" +"You cannot delete the sale order: %(sale_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" diff --git a/crm_claim_extra_ref_dependency/i18n/es.po b/crm_claim_extra_ref_dependency/i18n/es.po new file mode 100644 index 00000000..4bf618d4 --- /dev/null +++ b/crm_claim_extra_ref_dependency/i18n/es.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_claim_extra_ref_dependency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-01-28 12:22+0000\n" +"PO-Revision-Date: 2026-01-28 12:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_sale_order +msgid "Sales Order" +msgstr "Órdenes de venta" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_stock_picking +msgid "Transfer" +msgstr "Transferir" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/stock_picking.py:0 +#, python-format +msgid "" +"You cannot delete the picking: %(picking_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" +"No puede borrar el albarán: %(picking_name)s, porque está siendo usado en" +" la reclamación: %(claim_name)s." + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/purchase_order.py:0 +#, python-format +msgid "" +"You cannot delete the purchase order: %(purchase_name)s, because it is being" +" used in the claim: %(claim_name)s." +msgstr "" +"No puede borrar el pedido de compra: %(purchase_name)s, porque está" +" siendo usado en la reclamación: %(claim_name)s." + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/sale_order.py:0 +#, python-format +msgid "" +"You cannot delete the sale order: %(sale_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" +"No puede borrar el pedido de venta: %(sale_name)s, porque está siendo usado" +" en la reclamación: %(claim_name)s." diff --git a/crm_claim_extra_ref_dependency/i18n/fr.po b/crm_claim_extra_ref_dependency/i18n/fr.po new file mode 100644 index 00000000..18e48e37 --- /dev/null +++ b/crm_claim_extra_ref_dependency/i18n/fr.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_claim_extra_ref_dependency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-01-28 12:22+0000\n" +"PO-Revision-Date: 2026-01-28 12:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_purchase_order +msgid "Purchase Order" +msgstr "Bon de commande" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_sale_order +msgid "Sales Order" +msgstr "Bon de commande" + +#. module: crm_claim_extra_ref_dependency +#: model:ir.model,name:crm_claim_extra_ref_dependency.model_stock_picking +msgid "Transfer" +msgstr "Transfert" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/stock_picking.py:0 +#, python-format +msgid "" +"You cannot delete the picking: %(picking_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/purchase_order.py:0 +#, python-format +msgid "" +"You cannot delete the purchase order: %(purchase_name)s, because it is being" +" used in the claim: %(claim_name)s." +msgstr "" + +#. module: crm_claim_extra_ref_dependency +#. odoo-python +#: code:addons/crm_claim_extra_ref_dependency/model/sale_order.py:0 +#, python-format +msgid "" +"You cannot delete the sale order: %(sale_name)s, because it is being used in" +" the claim: %(claim_name)s." +msgstr "" diff --git a/crm_claim_extra_ref_dependency/model/__init__.py b/crm_claim_extra_ref_dependency/model/__init__.py new file mode 100644 index 00000000..375fa910 --- /dev/null +++ b/crm_claim_extra_ref_dependency/model/__init__.py @@ -0,0 +1,3 @@ +from . import purchase_order +from . import sale_order +from . import stock_picking diff --git a/crm_claim_extra_ref_dependency/model/purchase_order.py b/crm_claim_extra_ref_dependency/model/purchase_order.py new file mode 100644 index 00000000..246ce162 --- /dev/null +++ b/crm_claim_extra_ref_dependency/model/purchase_order.py @@ -0,0 +1,26 @@ +# Copyright 2026 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import _, exceptions, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def unlink(self): + claim_obj = self.env["crm.claim"] + for purchase in self: + ref = ("purchase.order,%(purchase_id)s") % { + "purchase_id": purchase.id, + } + claim = claim_obj.search([("model_ref_id", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref2", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref3", "=", ref)]) + if claim: + error = _( + "You cannot delete the purchase order: %(purchase_name)s, " + "because it is being used in the claim: %(claim_name)s." + ) % {"purchase_name": purchase.name, "claim_name": claim.code} + raise exceptions.ValidationError(error) + return super().unlink() diff --git a/crm_claim_extra_ref_dependency/model/sale_order.py b/crm_claim_extra_ref_dependency/model/sale_order.py new file mode 100644 index 00000000..c6feb9cf --- /dev/null +++ b/crm_claim_extra_ref_dependency/model/sale_order.py @@ -0,0 +1,26 @@ +# Copyright 2026 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import _, exceptions, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def unlink(self): + claim_obj = self.env["crm.claim"] + for sale in self: + ref = ("sale.order,%(sale_id)s") % { + "sale_id": sale.id, + } + claim = claim_obj.search([("model_ref_id", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref2", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref3", "=", ref)]) + if claim: + error = _( + "You cannot delete the sale order: %(sale_name)s, " + "because it is being used in the claim: %(claim_name)s." + ) % {"sale_name": sale.name, "claim_name": claim.code} + raise exceptions.ValidationError(error) + return super().unlink() diff --git a/crm_claim_extra_ref_dependency/model/stock_picking.py b/crm_claim_extra_ref_dependency/model/stock_picking.py new file mode 100644 index 00000000..a13826fb --- /dev/null +++ b/crm_claim_extra_ref_dependency/model/stock_picking.py @@ -0,0 +1,26 @@ +# Copyright 2026 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import _, exceptions, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def unlink(self): + claim_obj = self.env["crm.claim"] + for picking in self: + ref = ("stock.picking,%(picking_id)s") % { + "picking_id": picking.id, + } + claim = claim_obj.search([("model_ref_id", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref2", "=", ref)]) + if not claim: + claim = claim_obj.search([("ref3", "=", ref)]) + if claim: + error = _( + "You cannot delete the picking: %(picking_name)s, " + "because it is being used in the claim: %(claim_name)s." + ) % {"picking_name": picking.name, "claim_name": claim.code} + raise exceptions.ValidationError(error) + return super().unlink() diff --git a/setup/crm_claim_extra_ref_dependency/odoo/addons/crm_claim_extra_ref_dependency b/setup/crm_claim_extra_ref_dependency/odoo/addons/crm_claim_extra_ref_dependency new file mode 120000 index 00000000..424e50d2 --- /dev/null +++ b/setup/crm_claim_extra_ref_dependency/odoo/addons/crm_claim_extra_ref_dependency @@ -0,0 +1 @@ +../../../../crm_claim_extra_ref_dependency \ No newline at end of file diff --git a/setup/crm_claim_extra_ref_dependency/setup.py b/setup/crm_claim_extra_ref_dependency/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/crm_claim_extra_ref_dependency/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)