Skip to content

Commit

Permalink
[ADD] sale_stock_prebook_cancel_line: Glue addon
Browse files Browse the repository at this point in the history
This addon is a technical module that ensures that the computation of the cancelled quantity on a sale order line is correct even when a prebooking is involved. Cancelled prebooked quantities must not be taken into account in the computation of the cancelled quantity on the sale order line.
  • Loading branch information
lmignon committed Dec 19, 2024
1 parent 5bd8959 commit bb781c6
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_stock_prebook_cancel_line/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions sale_stock_prebook_cancel_line/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Stock Prebook Cancel Line",
"summary": """Takes into account prebook pickings into the computation
of cancelled qty on the sale order lines""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": [
"sale_stock_prebook",
"sale_order_line_cancel",
],
"auto_install": True,
"data": [],
"demo": [],
}
2 changes: 2 additions & 0 deletions sale_stock_prebook_cancel_line/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order_line
from . import stock_move
19 changes: 19 additions & 0 deletions sale_stock_prebook_cancel_line/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _check_moves_to_cancel(self, moves):
self.ensure_one()
if self.move_ids.filtered("used_for_sale_reservation"):
raise UserError(
_(
"You cannot cancel a line with prebooked moves. "
"Please cancel the related prebooked moves first."
)
)
14 changes: 14 additions & 0 deletions sale_stock_prebook_cancel_line/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class StockMove(models.Model):

_inherit = "stock.move"

def _is_move_to_take_into_account_for_qty_canceled(self):
self.ensure_one()
res = super()._is_move_to_take_into_account_for_qty_canceled()
return res and not self.used_for_sale_reservation
1 change: 1 addition & 0 deletions sale_stock_prebook_cancel_line/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Laurent Mignon <[email protected]> (https://www.acsone.eu)
3 changes: 3 additions & 0 deletions sale_stock_prebook_cancel_line/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- ALCYON Belux
1 change: 1 addition & 0 deletions sale_stock_prebook_cancel_line/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This addon is a technical module that ensures that the computation of the cancelled quantity on a sale order line is correct even when a prebooking is involved. Cancelled prebooked quantities must not be taken into account in the computation of the cancelled quantity on the sale order line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_stock_prebook_cancel_line/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_sale_stock_prebook_cancel_line
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import Command

from odoo.addons.sale_order_line_cancel.tests.common import TestSaleOrderLineCancelBase


class TestSaleStockPrebookCancelLine(TestSaleOrderLineCancelBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.draft_order = cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
"warehouse_id": cls.warehouse.id,
"order_line": [
Command.create(
{
"name": cls.product_1.name,
"product_id": cls.product_1.id,
"product_uom_qty": 10,
"product_uom": cls.product_1.uom_id.id,
"price_unit": 1,
}
)
],
}
)

def test_cancel_prebook_line_no_qty_cancelled(self):
"""If we cancel a prebook move line, the qty cancelled should be 0 on the
sale order line
"""
self.draft_order.reserve_stock()
picking_reservations = self.draft_order._get_reservation_pickings()
self.assertEqual(len(picking_reservations), 1)
picking_reservations.move_ids._action_cancel()
self.assertEqual(picking_reservations.move_ids.state, "cancel")
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0)

def test_cancel_prebook_picking_no_qty_cancelled(self):
"""If we cancel a prebook move line, the qty cancelled should be 0 on the
sale order line
"""
self.draft_order.reserve_stock()
picking_reservations = self.draft_order._get_reservation_pickings()
self.assertEqual(len(picking_reservations), 1)
picking_reservations.action_cancel()
self.assertEqual(picking_reservations.state, "cancel")
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0)

def test_cancel_prebook_no_qty_cancelled(self):
"""If we cancel a prebook move line, the qty cancelled should be 0 on the
sale order line
"""
self.draft_order.reserve_stock()
picking_reservations = self.draft_order._get_reservation_pickings()
self.assertEqual(len(picking_reservations), 1)
self.draft_order.release_reservation()
self.assertFalse(picking_reservations.exists())
self.assertEqual(self.draft_order.order_line.product_qty_canceled, 0)
6 changes: 6 additions & 0 deletions setup/sale_stock_prebook_cancel_line/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,
)
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
odoo_test_helper
odoo-addon-sale-stock-prebook @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3481/head#subdirectory=setup/sale_stock_prebook
odoo-addon-sale-order-line-cancel @ git+https://github.com/OCA/sale-workflow.git@refs/pull/2357/head#subdirectory=setup/sale_order_line_cancel

0 comments on commit bb781c6

Please sign in to comment.