Skip to content
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
6 changes: 6 additions & 0 deletions setup/stock_move_propagate_cancel/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
101 changes: 101 additions & 0 deletions stock_move_propagate_cancel/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
===========================
Stock Move Propagate Cancel
===========================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_move_propagate_cancel
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_move_propagate_cancel
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/stock-logistics-workflow&target_branch=16.0
:alt: Try me on Runboat

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

This module improves the stock move cancel propagation of Odoo stock module.
In base stock module, a cancelation of destination stock move is only made if all previous stock moves are canceled.
This modules aims to propagate the cancelation even if only part of the previous moves is canceled.

In case of chained stock moves, if you partially transfer a stock move and cancel the backorder, the destination stock move will be splitted and partially canceled to match what has really been transfered.

**Table of contents**

.. contents::
:local:

Known issues / Roadmap
======================

This module aims to manage most of cancelation cases among chained stock moves. But the subject can become really complex as anything is possible in Odoo.
One can change the quantity of a chained move for example resulting in an inconsistent situation when all part of the chain don't have the same quantity.

We can also have scenarios where a stock move have multiple destination moves, each with a different destination location. In this case, if the initial stock move is partially canceled, Odoo can't know on which destination move the propagation should be canceled.

For all these cases the module does nothing to avoid making a mistake.

The module works with the following rules :
In case of a cancelation of a stock move with the cancelation propagation option activated, odoo finds the quantity of the siblings move which has not been canceled (either it is done or waiting to be processed).
Then, it will only propagate the cancelation on the destination moves if the quantity of those moves (done or to do) is equal or bigger than the previous moves.

So, in these situations, the module doesn't cancel anything rather than risking to cancel the wrong destinaton moves/quantities.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-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://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_move_propagate_cancel%0Aversion:%2016.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
~~~~~~~

* Akretion

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

* Florian da Costa <[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-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
:target: https://github.com/florian-dacosta
:alt: florian-dacosta

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

|maintainer-florian-dacosta|

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_move_propagate_cancel>`_ 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 stock_move_propagate_cancel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions stock_move_propagate_cancel/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Stock Move Propagate Cancel",
"summary": "Manage stock move partial cancel propagation",
"version": "16.0.1.1.0",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["florian-dacosta"],
"license": "AGPL-3",
"installable": True,
"depends": ["stock"],
}
1 change: 1 addition & 0 deletions stock_move_propagate_cancel/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
64 changes: 64 additions & 0 deletions stock_move_propagate_cancel/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from odoo import models


class StockMove(models.Model):
_inherit = "stock.move"

def _action_cancel(self):
for move in self:
if move.propagate_cancel:
siblings = move.move_dest_ids.mapped("move_orig_ids") - move
siblings_states = siblings.mapped("state")
# this is the case of cancel propagation already managed in the stock
# module
if all(state == "cancel" for state in siblings_states):
continue
not_cancel_orig_qty = sum(
siblings.filtered(lambda m: m.state != "cancel").mapped(
"product_qty"
)
)
not_cancel_dest_qty = sum(
# we need to check dest move from orig move because when a move is
# split, it looses the link toward done dest move.
# the orig moves of an ongoing move always contain all orig though
# so we have to check the orig moves of the ongoing dest move of the
# move we are canceling.
move.move_dest_ids.move_orig_ids.move_dest_ids.filtered(
lambda m: m.state != "cancel"
).mapped("product_qty")
)
if not_cancel_dest_qty > not_cancel_orig_qty:
available_dest_qty_to_cancel = sum(
self.move_dest_ids.filtered(
lambda m: m.state not in ("done", "cancel")
).mapped("product_qty")
)
cancelable_dest_qty = min(
available_dest_qty_to_cancel,
not_cancel_dest_qty - not_cancel_orig_qty,
)
to_cancel_qty = min(move.product_qty, cancelable_dest_qty)
self._propagate_cancel(to_cancel_qty)
return super()._action_cancel()

def _propagate_cancel(self, qty):
self.ensure_one()
dest_moves = self.move_dest_ids.filtered(
lambda m: m.state not in ("cancel", "done")
)
# Avoid propagating qty if dest moves go in different location because we
# can't know on which make the propagation.
if len(dest_moves.location_dest_id) > 1:
return
for dest_move in dest_moves:
if dest_move.product_qty > qty:
new_move_vals = dest_move._split(dest_move.product_qty - qty)
new_moves = self.create(new_move_vals)
new_moves.with_context(bypass_entire_pack=True)._action_confirm(
merge=False
)
dest_move._action_cancel()
qty -= dest_move.product_qty
if qty <= 0:
break
1 change: 1 addition & 0 deletions stock_move_propagate_cancel/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <[email protected]>
5 changes: 5 additions & 0 deletions stock_move_propagate_cancel/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module improve the stock cancel propagation of Odoo stock module.
In base stock module, a cancelation of destination stock move is only made if all previous stock moves are canceled.
This modules aims to propagate the cancelation even if only part of the previous move is canceled.

In case of chained stock moves, if you transfer a stock move and cancel the backorder, the destination stock move will be splitted and partially canceled to match what has really been transfered.
12 changes: 12 additions & 0 deletions stock_move_propagate_cancel/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This module aims to manage most of cancelation cases among chained stock moves. But the subject can become really complex as anything is possible in Odoo.
One can change the quantity of a chained move for example resulting in an inconsistent situation when all part of the chain don't have the same quantity.

We can also have scenarios where a stock move have multiple destination moves, each with a different destination location. In this case, if the initial stock move is partially canceled, Odoo can't know on which destination move the propagation should be canceled.

For all these cases the module does nothing to avoid making a mistake.

The module works with the following rules :
In case of a cancelation of a stock move with the cancelation propagation option activated, odoo find the quantity of the siblings move which has not been canceled (either it is done or waiting to be processed).
Then, it wil only propagate the cancelation on the destination moves if those keep a quantity of products done or to do equal or bigger than the previous moves.

So, in these situations, the module don't cancel anything rather than risking to cancel the wrong destinaton moves/quantities.
Loading