diff --git a/modules/account_stock_anglo_saxon/CHANGELOG b/modules/account_stock_anglo_saxon/CHANGELOG
index 656aae72cf..a1b82288c4 100644
--- a/modules/account_stock_anglo_saxon/CHANGELOG
+++ b/modules/account_stock_anglo_saxon/CHANGELOG
@@ -1,3 +1,4 @@
+* Forbid to cancel stock move used for anglo-saxon accounting
Version 7.2.0 - 2024-04-29
--------------------------
diff --git a/modules/account_stock_anglo_saxon/message.xml b/modules/account_stock_anglo_saxon/message.xml
index 9a0a995116..2e27c36673 100644
--- a/modules/account_stock_anglo_saxon/message.xml
+++ b/modules/account_stock_anglo_saxon/message.xml
@@ -7,6 +7,12 @@ this repository contains the full copyright notices and license terms. -->
The invoice line "%(line)s" is linked to stock moves of other products than "%(product)s".
This may compute a wrong COGS.
+
+ You cannot cancel move "%(move)s" because it is used for anglo-saxon accounting.
+
+
+ You cannot delete move "%(move)s" because it is used for anglo-saxon accounting.
+
Anglo-Saxon quantity cannot be greater than quantity.
diff --git a/modules/account_stock_anglo_saxon/stock.py b/modules/account_stock_anglo_saxon/stock.py
index f3d26b9c8a..21bc1c4021 100644
--- a/modules/account_stock_anglo_saxon/stock.py
+++ b/modules/account_stock_anglo_saxon/stock.py
@@ -2,7 +2,9 @@
# this repository contains the full copyright notices and license terms.
from decimal import Decimal
-from trytond.model import Check, fields
+from trytond.i18n import gettext
+from trytond.model import Check, ModelView, Workflow, fields
+from trytond.model.exceptions import AccessError
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
@@ -178,3 +180,25 @@ class Move(metaclass=PoolMeta):
default.setdefault(prefix + 'anglo_saxon_quantity',
getattr(cls, 'default_%sanglo_saxon_quantity' % prefix)())
return super(Move, cls).copy(moves, default=default)
+
+ @classmethod
+ @ModelView.button
+ @Workflow.transition('cancelled')
+ def cancel(cls, moves):
+ for move in moves:
+ if move.in_anglo_saxon_quantity or move.out_anglo_saxon_quantity:
+ raise AccessError(
+ gettext('account_stock_anglo_saxon'
+ '.msg_move_cancel_anglo_saxon',
+ move=move.rec_name))
+ super().cancel(moves)
+
+ @classmethod
+ def delete(cls, moves):
+ for move in moves:
+ if move.in_anglo_saxon_quantity or move.out_anglo_saxon_quantity:
+ raise AccessError(
+ gettext('account_stock_anglo_saxon'
+ '.msg_move_delete_anglo_saxon',
+ move=move.rec_name))
+ super().delete(moves)
diff --git a/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst b/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst
index df2a85b143..bccb7e7e11 100644
--- a/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst
+++ b/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst
@@ -388,3 +388,12 @@ Now we will use a product with different unit of measure::
>>> move = Move(purchase.moves[0].id)
>>> move.in_anglo_saxon_quantity
1.0
+
+ >>> move.click('cancel')
+ Traceback (most recent call last):
+ ...
+ AccessError: ...
+ >>> move.delete()
+ Traceback (most recent call last):
+ ...
+ AccessError: ...