41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def verifier_stock_suffisant(article_ref, quantite, cursor, depot=None):
|
|
"""Version thread-safe avec lock SQL"""
|
|
try:
|
|
cursor.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE")
|
|
cursor.execute("BEGIN TRANSACTION")
|
|
|
|
try:
|
|
cursor.execute(
|
|
"""
|
|
SELECT SUM(AS_QteSto)
|
|
FROM F_ARTSTOCK WITH (UPDLOCK, ROWLOCK)
|
|
WHERE AR_Ref = ?
|
|
""",
|
|
(article_ref.upper(),),
|
|
)
|
|
|
|
row = cursor.fetchone()
|
|
stock_dispo = float(row[0]) if row and row[0] else 0.0
|
|
|
|
suffisant = stock_dispo >= quantite
|
|
|
|
cursor.execute("COMMIT")
|
|
|
|
return {
|
|
"suffisant": suffisant,
|
|
"stock_disponible": stock_dispo,
|
|
"quantite_demandee": quantite,
|
|
}
|
|
|
|
except Exception:
|
|
cursor.execute("ROLLBACK")
|
|
raise
|
|
|
|
except Exception as e:
|
|
logger.error(f"Erreur vérification stock: {e}")
|
|
raise
|