Skip to content

Commit

Permalink
[IMP] stock_restrict_lot: validate lot moved is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
aleuffre committed Dec 1, 2023
1 parent 6161534 commit a215e49
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
8 changes: 7 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:f758aba4cb49703bdebb2d5df39af78820093588d52f5b031e7c721c32a65b8b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -62,6 +62,12 @@ Contributors
* Florian da Costa <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

* Ooops404

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>

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

Expand Down
24 changes: 24 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,26 @@ 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.filtered(lambda x: x.restrict_lot_id and x.move_line_ids):
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(x.display_name for x in move_line_lot),
move_restrict_lot=move.restrict_lot_id.display_name,
)
)
6 changes: 6 additions & 0 deletions stock_restrict_lot/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
* Florian da Costa <[email protected]>
* Michael Tietz (MT Software) <[email protected]>

* Ooops404

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>
7 changes: 6 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:f758aba4cb49703bdebb2d5df39af78820093588d52f5b031e7c721c32a65b8b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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,11 @@ <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</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
38 changes: 38 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,40 @@ 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):
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()

0 comments on commit a215e49

Please sign in to comment.