Remove warning for inventory in the future

Since #10591 we can skip the warning of stock move in the future for newly
created moves.
This commit is contained in:
Cédric Krier
2025-11-27 16:28:21 +01:00
parent 476065cf11
commit edb3c2c2d4
4 changed files with 7 additions and 36 deletions
@@ -13,7 +13,7 @@ Imports::
>>> from trytond.modules.account_invoice.tests.tools import (
... create_payment_term, set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.stock.exceptions import InventoryFutureWarning
>>> from trytond.modules.stock.exceptions import MoveFutureWarning
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
@@ -25,6 +25,8 @@ Activate modules::
... ['sale_stock_quantity', 'stock_supply'],
... create_company, create_chart)
>>> Warning = Model.get('res.user.warning')
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
@@ -170,8 +172,8 @@ Make an inventory of 3 products in 2 days::
>>> inventory_line.expected_quantity = 5.0
>>> try:
... inventory.click('confirm')
... except InventoryFutureWarning as e:
... Model.get('res.user.warning')(user=config.user, name=e.name).save()
... except MoveFutureWarning as warning:
... Warning(user=config.user, name=warning.name).save()
>>> inventory.click('confirm')
>>> inventory.state
'done'
-4
View File
@@ -36,10 +36,6 @@ class MoveFutureWarning(UserWarning):
pass
class InventoryFutureWarning(UserWarning):
pass
class ProductCostPriceError(ValidationError):
pass
+2 -26
View File
@@ -15,8 +15,7 @@ from trytond.tools import grouped_slice, is_full_text, lstrip_wildcard
from trytond.transaction import Transaction
from trytond.wizard import Button, StateTransition, StateView, Wizard
from .exceptions import (
InventoryCountWarning, InventoryFutureWarning, InventoryValidationError)
from .exceptions import InventoryCountWarning, InventoryValidationError
class Inventory(Workflow, ModelSQL, ModelView, ChatMixin):
@@ -153,29 +152,7 @@ class Inventory(Workflow, ModelSQL, ModelView, ChatMixin):
def confirm(cls, inventories):
pool = Pool()
Move = pool.get('stock.move')
Date = pool.get('ir.date')
Warning = pool.get('res.user.warning')
transaction = Transaction()
today_cache = {}
def in_future(inventory):
if inventory.company not in today_cache:
with Transaction().set_context(company=inventory.company.id):
today_cache[inventory.company] = Date.today()
today = today_cache[inventory.company]
if inventory.date > today:
return inventory
future_inventories = sorted(filter(in_future, inventories))
if future_inventories:
names = ', '.join(i.rec_name for i in future_inventories[:5])
if len(future_inventories) > 5:
names + '...'
warning_name = Warning.format('date_future', future_inventories)
if Warning.check(warning_name):
raise InventoryFutureWarning(warning_name,
gettext('stock.msg_inventory_date_in_the_future',
inventories=names))
moves = []
for inventory in inventories:
keys = set()
@@ -193,8 +170,7 @@ class Inventory(Workflow, ModelSQL, ModelView, ChatMixin):
if moves:
with transaction.set_context(_product_replacement=False):
Move.save(moves)
with transaction.set_context(_skip_warnings=True):
Move.do(moves)
Move.do(moves)
@classmethod
@ModelView.button
-3
View File
@@ -119,9 +119,6 @@ because the type does not support moves and location has existing moves.</field>
<record model="ir.message" id="msg_move_effective_date_in_the_future">
<field name="text">The moves "%(moves)s" have effective dates in the future.</field>
</record>
<record model="ir.message" id="msg_inventory_date_in_the_future">
<field name="text">The inventories "%(inventories)s" have dates in the future.</field>
</record>
<record model="ir.message" id="msg_stock_reporting_company">
<field name="text">Company</field>
</record>