feat(inventory): add support for selling in negative stock

Implement functionality to allow sales even when stock is insufficient, tracking pending quantities and resolving them when new stock arrives via incoming documents. This includes new fields in Sale model (is_pending_cost, pending_quantity), updates to batch manager for negative write-offs, and signal handlers for automatic processing.

- Add is_pending_cost and pending_quantity fields to Sale model
- Modify write_off_by_fifo to support allow_negative flag and return pending quantity
- Update incoming document service to allocate pending sales to new batches
- Enhance sale processor and signals to handle pending sales
- Remove outdated tests.py file
- Add migration for new Sale fields
This commit is contained in:
2026-01-04 12:27:10 +03:00
parent 123f330a26
commit a03f3df086
7 changed files with 223 additions and 570 deletions

View File

@@ -0,0 +1,30 @@
# Generated by Django 5.0.10 on 2026-01-04 06:53
from decimal import Decimal
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0002_initial'),
('orders', '0002_initial'),
('products', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='sale',
name='is_pending_cost',
field=models.BooleanField(default=False, help_text="True если продажа создана без партий (продажа 'в минус')", verbose_name='Ожидает себестоимости'),
),
migrations.AddField(
model_name='sale',
name='pending_quantity',
field=models.DecimalField(decimal_places=3, default=Decimal('0'), help_text='Количество, ожидающее привязки к партиям при приёмке', max_digits=10, verbose_name='Ожидающее количество'),
),
migrations.AddIndex(
model_name='sale',
index=models.Index(fields=['is_pending_cost'], name='inventory_s_is_pend_81a3db_idx'),
),
]