-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_move_negative_stock_location |
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, | ||
) |
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_move |
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: | ||||||||
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() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||
return super()._check_company(fnames=fnames) |
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]> |
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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. |
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. |
There was a problem hiding this comment.
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: