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

[16.0][ADD] stock_move_negative_stock_location #1801

Open
wants to merge 1 commit into
base: 16.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
6 changes: 6 additions & 0 deletions setup/stock_move_negative_stock_location/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,
)
85 changes: 85 additions & 0 deletions stock_move_negative_stock_location/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
==================================
Stock Move Negative Stock Location
==================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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_negative_stock_location
: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_negative_stock_location
: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|

When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
For stock moves with negative quantities, this module sets the source location with the return
picking type default destination location. Like that destination location is properly set on the return move.

**Table of contents**

.. contents::
:local:

Usage
=====

In `Returns`` picking type set the default destination location as `Stock`
Create a stock move from Stock to Customer with a negative quantity and validate it.
That move will be converted into a stock move from Customer to Stock with a positive quantity.

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_negative_stock_location%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
~~~~~~~

* Camptocamp
* BCIM

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

* Telmo Santos <[email protected]>
* Sébastien Alix <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[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.

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_move_negative_stock_location>`_ 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_negative_stock_location/__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_negative_stock_location/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Move Negative Stock Location",
"version": "16.0.1.0.0",
"category": "Stock",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp, BCIM, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["stock"],
"installable": True,
}
1 change: 1 addition & 0 deletions stock_move_negative_stock_location/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move
43 changes: 43 additions & 0 deletions stock_move_negative_stock_location/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import models
from odoo.tools.float_utils import float_compare


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

def _action_confirm(self, merge=True, merge_into=False):
"""Override to set the location_id of negative return moves to the default
location_dest_id of the return picking type."""
neg_r_moves = self.filtered(
lambda move: float_compare(
move.product_uom_qty, 0, precision_rounding=move.product_uom.rounding
)
< 0
)
self = self.with_context(neg_r_moves=neg_r_moves.ids)
return super()._action_confirm(merge=merge, merge_into=merge_into)

def set_negative_return_moves_location(self):
"""Set the location_id of negative return moves to the default location_dest_id
of the return picking type."""
neg_r_moves = self.browse(self.env.context["neg_r_moves"])
for move in neg_r_moves:
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to get methods not depending on context but on current recordset, easier to test and understand:

Suggested change
neg_r_moves = self.browse(self.env.context["neg_r_moves"])
for move in neg_r_moves:
for move in self:

if move.picking_type_id.return_picking_type_id.default_location_dest_id:
move.location_id = (
move.picking_type_id.return_picking_type_id.default_location_dest_id
)

def _check_company(self, fnames=None):
# Set the location_id of negative return moves to the default location_dest_id
# of the return picking type
# We hook into this method used in stock.move._action_confirm
# (see https://github.com/odoo/odoo/blob/
# 3a63c90fff615b70881131e11d7375af2ae082a6/addons/stock/models/stock_move.py
# #L1381C14-L1381C27)
# to be able to invert location_id and location_dest_id
if self.env.context.get("neg_r_moves"):
self.set_negative_return_moves_location()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And handle the context only where it is needed (if in later version Odoo adds a hook for instance, we could trash easily this context handling without touching the business method set_negative_return_moves_location:

Suggested change
self.set_negative_return_moves_location()
neg_moves = self.browse(self.env.context.get("neg_r_moves")).exists()
neg_moves.set_negative_return_moves_location()

return super()._check_company(fnames=fnames)
3 changes: 3 additions & 0 deletions stock_move_negative_stock_location/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Telmo Santos <[email protected]>
* Sébastien Alix <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[email protected]>
3 changes: 3 additions & 0 deletions stock_move_negative_stock_location/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
When making a stock move with a negative quantity, Odoo converts it to a positive return move and the locations are inverted.

For stock moves with negative quantities, this module sets the source location with the return
picking type default destination location. Like that destination location is properly set on the return move.
3 changes: 3 additions & 0 deletions stock_move_negative_stock_location/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
In `Returns`` picking type set the default destination location as `Stock`
Create a stock move from Stock to Customer with a negative quantity and validate it.
That move will be converted into a stock move from Customer to Stock with a positive quantity.
Loading
Loading