Files
dealerhub/backend/apps/inventory/migrations/0001_initial.py
T

104 lines
7.5 KiB
Python

# Generated by Django 5.2.12 on 2026-09-06 17:42
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('catalog', '0001_initial'),
('core', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Warehouse',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('code', models.CharField(max_length=64)),
('name', models.CharField(max_length=128)),
('location', models.CharField(blank=True, default='', max_length=255)),
('is_active', models.BooleanField(default=True)),
('is_default', models.BooleanField(default=False, help_text='默认仓库')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': '仓库',
'db_table': 'inventory_warehouse',
'ordering': ['code'],
'unique_together': {('tenant', 'code')},
},
),
migrations.CreateModel(
name='StockMovement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('movement_type', models.CharField(choices=[('inbound', '入库'), ('outbound', '出库'), ('lock', '锁定'), ('unlock', '释放'), ('adjust', '盘点')], max_length=16)),
('source_type', models.CharField(choices=[('purchase', '采购入库'), ('sale', '销售出库'), ('transfer', '调拨'), ('adjust', '盘点调整'), ('manual', '手工')], default='manual', max_length=16)),
('source_ref', models.CharField(blank=True, default='', help_text='来源单据号', max_length=64)),
('quantity', models.DecimalField(decimal_places=4, help_text='本次变动数量(正数)', max_digits=18)),
('unit_cost', models.DecimalField(decimal_places=4, default=0, help_text='单位成本', max_digits=18)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='movements', to='catalog.product')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='movements', to='inventory.warehouse')),
],
options={
'verbose_name_plural': '库存流水',
'db_table': 'inventory_movement',
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['tenant', 'warehouse', '-created_at'], name='inventory_m_tenant__e8039f_idx'), models.Index(fields=['tenant', 'product', '-created_at'], name='inventory_m_tenant__bc5789_idx'), models.Index(fields=['source_type', 'source_ref'], name='inventory_m_source__9a2f80_idx')],
},
),
migrations.CreateModel(
name='Stock',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_deleted', models.BooleanField(default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('ext_data', models.JSONField(blank=True, default=dict)),
('source_channel', models.CharField(blank=True, default='manual', max_length=32)),
('on_hand', models.DecimalField(decimal_places=4, default=0, max_digits=18)),
('locked', models.DecimalField(decimal_places=4, default=0, max_digits=18)),
('avg_cost', models.DecimalField(decimal_places=4, default=0, max_digits=18)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('org', models.ForeignKey(blank=True, help_text='所属组织(多机构预留)', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.org')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stocks', to='catalog.product')),
('tenant', models.ForeignKey(help_text='所属租户', on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.tenant')),
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stocks', to='inventory.warehouse')),
],
options={
'verbose_name_plural': '库存账面',
'db_table': 'inventory_stock',
'ordering': ['warehouse', 'product'],
'indexes': [models.Index(fields=['tenant', 'warehouse', 'product'], name='inventory_s_tenant__80269e_idx'), models.Index(fields=['tenant', 'product'], name='inventory_s_tenant__fa0b11_idx')],
'unique_together': {('tenant', 'warehouse', 'product')},
},
),
]