feat: add devaluation support to stock movements

- Add 'devaluation' to stock movement types
- Add validation to ensure trackable items for devaluation
- Improve error handling for devaluation operations
This commit is contained in:
Dries Peeters
2026-01-12 20:09:00 +01:00
parent c8f7b13b89
commit 61bead4cb2
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class StockMovement(db.Model):
id = db.Column(db.Integer, primary_key=True)
movement_type = db.Column(
db.String(20), nullable=False, index=True
) # 'adjustment', 'transfer', 'sale', 'rent', 'purchase', 'return', 'waste'
) # 'adjustment', 'transfer', 'sale', 'rent', 'purchase', 'return', 'waste', 'devaluation'
stock_item_id = db.Column(db.Integer, db.ForeignKey("stock_items.id"), nullable=False, index=True)
warehouse_id = db.Column(db.Integer, db.ForeignKey("warehouses.id"), nullable=False, index=True)
quantity = db.Column(db.Numeric(10, 2), nullable=False) # Positive for additions, negative for removals
+3
View File
@@ -983,6 +983,9 @@ def new_movement():
# Process devaluation if enabled
if devalue_enabled:
if not item.is_trackable:
raise ValueError(_("Stock item is not trackable. Devaluation requires trackable items."))
base_cost = item.default_cost or Decimal("0")
if base_cost <= 0:
raise ValueError(_("Stock item must have a default cost to perform devaluation"))