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][MIG] sale_order_restrict_cancel_existing_invoice #2598

Merged
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
89 changes: 89 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
===========================================
Sale Order Restrict Cancel Existing Invoice
===========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https:/OCA/sale-workflow/tree/10.0/sale_order_restrict_cancel_existing_invoice
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-10-0/sale-workflow-10-0-sale_order_restrict_cancel_existing_invoice
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/10.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module restrict Sale Order cancellation if a confirmed invoice linked
to that Sale exists.

**Table of contents**

.. contents::
:local:

Usage
=====

* Create a Sale Order and confirm it (and deliver products if needed)
* Create Invoice and confirm it
* On Sale Order, try to click on 'Cancel'. An error should occur

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https:/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https:/OCA/sale-workflow/issues/new?body=module:%20sale_order_restrict_cancel_existing_invoice%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Denis Roussel <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-rousseldenis| image:: https:/rousseldenis.png?size=40px
:target: https:/rousseldenis
:alt: rousseldenis

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-rousseldenis|

This module is part of the `OCA/sale-workflow <https:/OCA/sale-workflow/tree/10.0/sale_order_restrict_cancel_existing_invoice>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_order_restrict_cancel_existing_invoice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Order Restrict Cancel Existing Invoice",
"summary": """
Allows to restrict sale order cancelling if an invoice exists""",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"maintainers": ["rousseldenis"],
"category": "Sales",
"development_status": "Production/Stable",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https:/OCA/sale-workflow",
"depends": ["sale"],
}
40 changes: 40 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/i18n/ca.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_restrict_cancel_existing_invoice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-03-26 10:46+0000\n"
"Last-Translator: Daniel Martinez Vila <[email protected]>\n"
"Language-Team: none\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,field_description:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Confirmed invoice ids"
msgstr "Identificadors de factura confirmats"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model,name:sale_order_restrict_cancel_existing_invoice.model_sale_order
msgid "Sales Order"
msgstr "Comanda de venda"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,help:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Technical field in order to retrieve confirmed invoices"
msgstr "Camp tècnic per recuperar factures confirmades"

#. module: sale_order_restrict_cancel_existing_invoice
#: code:addons/sale_order_restrict_cancel_existing_invoice/models/sale_order.py:37
#, python-format
msgid "You cannot cancel a Sale Order for which a confirmed invoice exists!"
msgstr ""
"No podeu cancel·lar una comanda de venda per a la qual existeix una factura "
"confirmada!"
40 changes: 40 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_restrict_cancel_existing_invoice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-03-26 10:46+0000\n"
"Last-Translator: Daniel Martinez Vila <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,field_description:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Confirmed invoice ids"
msgstr "ID de factura confirmados"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model,name:sale_order_restrict_cancel_existing_invoice.model_sale_order
msgid "Sales Order"
msgstr "Órdenes de venta"

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,help:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Technical field in order to retrieve confirmed invoices"
msgstr "Campo técnico para recuperar facturas confirmadas"

#. module: sale_order_restrict_cancel_existing_invoice
#: code:addons/sale_order_restrict_cancel_existing_invoice/models/sale_order.py:37
#, python-format
msgid "You cannot cancel a Sale Order for which a confirmed invoice exists!"
msgstr ""
"¡No puede cancelar una orden de venta para la que existe una factura "
"confirmada!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_restrict_cancel_existing_invoice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \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: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,field_description:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Confirmed invoice ids"
msgstr ""

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model,name:sale_order_restrict_cancel_existing_invoice.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_order_restrict_cancel_existing_invoice
#: model:ir.model.fields,help:sale_order_restrict_cancel_existing_invoice.field_sale_order_confirmed_invoice_ids
msgid "Technical field in order to retrieve confirmed invoices"
msgstr ""

#. module: sale_order_restrict_cancel_existing_invoice
#: code:addons/sale_order_restrict_cancel_existing_invoice/models/sale_order.py:37
#, python-format
msgid "You cannot cancel a Sale Order for which a confirmed invoice exists!"
msgstr ""

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
40 changes: 40 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError


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

confirmed_invoice_ids = fields.Many2many(
comodel_name="account.move",
compute="_compute_confirmed_invoice_ids",
help="Technical field in order to retrieve confirmed invoices",
)

def _get_confirmed_invoice_states(self):
"""
Return the invoice states that should avoid order cancel
:return:
"""
return ["posted"]

@api.depends("invoice_ids")
def _compute_confirmed_invoice_ids(self):
states = self._get_confirmed_invoice_states()
for sale in self:
Saran440 marked this conversation as resolved.
Show resolved Hide resolved
sale.confirmed_invoice_ids = sale.invoice_ids.filtered(
lambda invoice, states=states: invoice.state in states
)

def action_cancel(self):
if any(sale.confirmed_invoice_ids for sale in self):
raise UserError(
_(
"You cannot cancel a Sale Order for which a confirmed "
"invoice exists!"
)
)
return super(SaleOrder, self).action_cancel()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Denis Roussel <[email protected]>
* Saran Lim. <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module restrict Sale Order cancellation if a confirmed invoice linked
to that Sale exists.
3 changes: 3 additions & 0 deletions sale_order_restrict_cancel_existing_invoice/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Create a Sale Order and confirm it (and deliver products if needed)
* Create Invoice and confirm it
* On Sale Order, try to click on 'Cancel'. An error should occur
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading