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

[14.0][IMP] stock_restrict_lot: validate lot moved is correct #1443

Merged
merged 1 commit into from
Dec 7, 2023
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
10 changes: 9 additions & 1 deletion stock_restrict_lot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Stock Restrict Lot
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:eda908988d0c0cca699354725723eb9100a2f990718c4961eb3713121f51da5d
!! source digest: sha256:0074198b06ddce65e1b735c863db45b56b188c3257ff230c1efbf6a709e75585
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -62,6 +62,14 @@ Contributors
* Florian da Costa <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

* Ooops404

* Francesco Foresti <[email protected]>

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>

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

Expand Down
26 changes: 26 additions & 0 deletions stock_restrict_lot/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


class StockMove(models.Model):
Expand Down Expand Up @@ -92,3 +93,28 @@ def _split(self, qty, restrict_partner_id=False):
if vals_list and self.restrict_lot_id:
vals_list[0]["restrict_lot_id"] = self.restrict_lot_id.id
return vals_list

def _action_done(self, cancel_backorder=False):
res = super()._action_done(cancel_backorder=cancel_backorder)
self._check_lot_consistent_with_restriction()
return res

def _check_lot_consistent_with_restriction(self):
"""
Check that the lot set on move lines
is the same as the restricted lot set on the move
"""
for move in self:
if not (move.restrict_lot_id and move.move_line_ids):
continue
move_line_lot = move.mapped("move_line_ids.lot_id")
if move.restrict_lot_id != move_line_lot:
raise UserError(
_(
"The lot(s) %(move_line_lot)s being moved is "
"inconsistent with the restriction on "
"lot %(move_restrict_lot)s set on the move",
move_line_lot=", ".join(move_line_lot.mapped("display_name")),
move_restrict_lot=move.restrict_lot_id.display_name,
)
)
8 changes: 8 additions & 0 deletions stock_restrict_lot/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
* Florian da Costa <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

* Ooops404
aleuffre marked this conversation as resolved.
Show resolved Hide resolved

* Francesco Foresti <[email protected]>

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>
10 changes: 9 additions & 1 deletion stock_restrict_lot/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Stock Restrict Lot</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:eda908988d0c0cca699354725723eb9100a2f990718c4961eb3713121f51da5d
!! source digest: sha256:0074198b06ddce65e1b735c863db45b56b188c3257ff230c1efbf6a709e75585
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_restrict_lot"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_restrict_lot"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module add a field to restrict a stock move to a specific lot.
Expand Down Expand Up @@ -407,6 +407,14 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Florian da Costa &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
<li>Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</li>
<li>Ooops404<ul>
<li>Francesco Foresti &lt;<a class="reference external" href="mailto:francesco.foresti&#64;ooops404.com">francesco.foresti&#64;ooops404.com</a>&gt;</li>
</ul>
</li>
<li>PyTech SRL<ul>
<li>Alessandro Uffreduzzi &lt;<a class="reference external" href="mailto:alessandro.uffreduzzi&#64;pytech.it">alessandro.uffreduzzi&#64;pytech.it</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
43 changes: 43 additions & 0 deletions stock_restrict_lot/tests/test_restrict_lot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import UserError
from odoo.tests.common import SavepointCase


Expand Down Expand Up @@ -271,3 +272,45 @@ def test_compute_quantites(self):
product.invalidate_cache()
product = product.with_context(lot_id=lot2.id)
self.assertEqual(product.outgoing_qty, 1)

def test_move_validation_inconsistent_lot(self):
aleuffre marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that an error is raised when performing a move _action_done()
if the lot restriction on the move is inconsistent with the
lot in the move line
"""
lot2 = self.env["stock.production.lot"].create(
{
"name": "lot2",
"product_id": self.product.id,
"company_id": self.warehouse.company_id.id,
}
)
self._update_product_stock(1, lot2.id)

move = self.env["stock.move"].create(
{
"product_id": self.product.id,
"location_id": self.warehouse.lot_stock_id.id,
"location_dest_id": self.customer_loc.id,
"product_uom_qty": 1,
"product_uom": self.product.uom_id.id,
"name": "test",
"warehouse_id": self.warehouse.id,
"restrict_lot_id": self.lot.id,
}
)
move_line = self.env["stock.move.line"].create(
{
"move_id": move.id,
"product_id": move.product_id.id,
"qty_done": 1,
"product_uom_id": move.product_uom.id,
"location_id": move.location_id.id,
"location_dest_id": move.location_dest_id.id,
"lot_id": lot2.id,
}
)
self.assertRaises(UserError, move._action_done)
move_line.lot_id = self.lot
move._action_done()
Loading