Forbid to cancel stock move used for anglo-saxon accounting
Closes #13597
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Forbid to cancel stock move used for anglo-saxon accounting
|
||||
|
||||
Version 7.2.0 - 2024-04-29
|
||||
--------------------------
|
||||
|
||||
@@ -7,6 +7,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="text">The invoice line "%(line)s" is linked to stock moves of other products than "%(product)s".
|
||||
This may compute a wrong COGS.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_move_cancel_anglo_saxon">
|
||||
<field name="text">You cannot cancel move "%(move)s" because it is used for anglo-saxon accounting.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_move_delete_anglo_saxon">
|
||||
<field name="text">You cannot delete move "%(move)s" because it is used for anglo-saxon accounting.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_move_quantity_greater">
|
||||
<field name="text">Anglo-Saxon quantity cannot be greater than quantity.</field>
|
||||
</record>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user