Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] sale_cancel_restrict #2933

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added sale_cancel_restrict/README.rst
Empty file.
4 changes: 4 additions & 0 deletions sale_cancel_restrict/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
17 changes: 17 additions & 0 deletions sale_cancel_restrict/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Sale Cancel Restrict",
"version": "15.0.1.0.0",
"author": "ForgeFlow," "Odoo Community Association (OCA)",
"category": "Sale",
"license": "AGPL-3",
"website": "https:/OCA/sale-workflow",
"depends": ["sale_stock"],
"data": [
"views/res_config_settings_views.xml",
],
"auto_install": False,
"installable": True,
}
6 changes: 6 additions & 0 deletions sale_cancel_restrict/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import sale_order
from . import res_company
from . import res_config_settings
9 changes: 9 additions & 0 deletions sale_cancel_restrict/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class Company(models.Model):
_inherit = "res.company"

enable_sale_cancel_restrict = fields.Boolean(default=False)
12 changes: 12 additions & 0 deletions sale_cancel_restrict/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

enable_sale_cancel_restrict = fields.Boolean(
related="company_id.enable_sale_cancel_restrict",
readonly=False,
)
35 changes: 35 additions & 0 deletions sale_cancel_restrict/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, models
from odoo.exceptions import ValidationError


class SaleOrder(models.Model):
_inherit = "sale.order"

def _show_cancel_wizard(self):
if (
not self.env.context.get("disable_cancel_warning")
and self.env.company.enable_sale_cancel_restrict
):
for rec in self:
if any(delivery.state == "done" for delivery in rec.picking_ids):
raise ValidationError(
_(
"You cannot cancel the SO: %s as it "
"has some transfers already done."
)
% rec.name
)
if any(invoice.state != "cancel" for invoice in rec.invoice_ids):
raise ValidationError(
_(
"You cannot cancel the SO: %s as "
"it has some invoices in draft "
"or posted state. Please cancel them "
"to be able to cancel the SO."
)
% rec.name
)
return super()._show_cancel_wizard()
1 change: 1 addition & 0 deletions sale_cancel_restrict/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* David Jiménez <[email protected]>
2 changes: 2 additions & 0 deletions sale_cancel_restrict/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When you try to cancel a sales order, if there is some delivery done or
an invoice not cancelled will prevent the sales order from being cancelled.
6 changes: 6 additions & 0 deletions sale_cancel_restrict/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you need to:

* Enable Sale Cancel Confirmed Invoice at Sales -> Settings -> Enable Sale Cancel Restrict.
* Click at "Cancel Order" button from a sales order which state equal
to Sales Order
* It will show an alert that prevents the sale order from being cancelled.
Binary file added sale_cancel_restrict/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading