Skip to content

Commit

Permalink
[IMP] sale_stock_prebook: Do not allow to set quantity done
Browse files Browse the repository at this point in the history
on reserved stock moves
  • Loading branch information
lmignon authored and mt-software-de committed Feb 7, 2025
1 parent af037f9 commit 57f3768
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion sale_stock_prebook/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale Stock Prebook
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:aed36ba76df99d50d42777ac488e6dc77420d6966a044bf7cd1f6a8d0dd97ad5
!! source digest: sha256:c262f3d0d45546530ef14056caae0e4f81a04ccbb70a5f8f9600ebda66e382f0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -66,6 +66,7 @@ Contributors
~~~~~~~~~~~~

* Michael Tietz (MT Software) <[email protected]>
* Laurent Mignon <[email protected]> (https://www.acsone.eu/)

Maintainers
~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion sale_stock_prebook/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
# Copyright 2025 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models

Expand Down Expand Up @@ -31,7 +32,8 @@ def _action_confirm(self):

def _prepare_reserve_procurement_group_values(self):
self.ensure_one()
values = self.order_line[0]._prepare_procurement_group_vals()
line = fields.first(self.order_line)
values = line._prepare_procurement_group_vals()
values["name"] = f"Reservation for {values['name']}"
return values

Expand Down
18 changes: 15 additions & 3 deletions sale_stock_prebook/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
# Copyright 2025 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

used_for_sale_reservation = fields.Boolean(default=False)

@api.constrains("used_for_sale_reservation", "quantity_done")
def _check_used_for_sale_reservation(self):
for move in self:
if move.used_for_sale_reservation and move.quantity_done:
raise ValidationError(
_(
"You cannot set a quantity done on a move used for sale reservation"
)
)

def _action_assign(self):
self = self.filtered(lambda m: not m.used_for_sale_reservation)
return super(StockMove, self)._action_assign()
new_self = self.filtered(lambda m: not m.used_for_sale_reservation)
return super(StockMove, new_self)._action_assign()
1 change: 1 addition & 0 deletions sale_stock_prebook/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Michael Tietz (MT Software) <[email protected]>
* Laurent Mignon <[email protected]> (https://www.acsone.eu/)
3 changes: 2 additions & 1 deletion sale_stock_prebook/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Sale Stock Prebook</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:aed36ba76df99d50d42777ac488e6dc77420d6966a044bf7cd1f6a8d0dd97ad5
!! source digest: sha256:c262f3d0d45546530ef14056caae0e4f81a04ccbb70a5f8f9600ebda66e382f0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_stock_prebook"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_stock_prebook"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-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>Add process to prebook a sale order’s stock before confirming it</p>
Expand Down Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<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>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt; (<a class="reference external" href="https://www.acsone.eu/">https://www.acsone.eu/</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
8 changes: 7 additions & 1 deletion sale_stock_prebook/tests/test_sale_stock_prebook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
# Copyright 2025 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError
from odoo.tests import tagged

from .common import TestSaleStockPrebookCase
Expand Down Expand Up @@ -49,3 +50,8 @@ def test_40_action_assign(self):
self.assertFalse(self.sale.picking_ids.move_lines.move_line_ids)
with self.assertRaises(UserError):
self.sale.picking_ids.button_validate()

def test_50_process_move(self):
self.sale.reserve_stock()
with self.assertRaisesRegex(ValidationError, "You cannot set a quantity done"):
self.sale.picking_ids.move_lines.quantity_done = 3

0 comments on commit 57f3768

Please sign in to comment.