1
0
forked from erp-dev/erp
This commit is contained in:
2025-11-03 17:55:30 +08:00
commit 9fde654e2f
77 changed files with 7831 additions and 0 deletions

0
stock/__init__.py Normal file
View File

30
stock/admin.py Normal file
View File

@@ -0,0 +1,30 @@
from django.contrib import admin
from . import models
@admin.register(models.PurchaseOrder)
class PurchaseOrderAdmin(admin.ModelAdmin):
list_display = ('id', 'supplier', 'order_date', 'total_amount')
search_fields = ('supplier__name',)
list_filter = ('order_date',)
ordering = ('-order_date',)
@admin.register(models.Inventory)
class InventoryAdmin(admin.ModelAdmin):
list_display = (
'id',
'product',
'product_color',
'warehouse',
'quantity',
'num_of_rolls',
'minimum_quantity',
'updated_at',
)
search_fields = ('product__name', 'warehouse__name')
list_filter = ('warehouse',)
@admin.display(description='颜色')
def product_color(self, obj):
return obj.product.color

7
stock/apps.py Normal file
View File

@@ -0,0 +1,7 @@
from django.apps import AppConfig
class StockConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'stock'
verbose_name = '库存相关'

View File

@@ -0,0 +1,38 @@
# Generated by Django 5.2.7 on 2025-11-03 04:08
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='ProductCategory',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='类别名称')),
('description', models.TextField(blank=True, null=True, verbose_name='类别描述')),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='产品名')),
('human_id', models.CharField(max_length=100, verbose_name='产品编号')),
('color', models.CharField(blank=True, max_length=50, null=True, verbose_name='颜色')),
('width_size', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True, verbose_name='宽幅')),
('single_price', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='单价')),
('spec', models.CharField(blank=True, max_length=100, null=True, verbose_name='规格')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
('unit', models.CharField(default='', max_length=20, verbose_name='单位')),
('category', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='products', to='stock.productcategory', verbose_name='产品类别')),
],
),
]

View File

@@ -0,0 +1,21 @@
# Generated by Django 5.2.7 on 2025-11-03 04:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='product',
options={'verbose_name': '产品资料', 'verbose_name_plural': '产品资料'},
),
migrations.AlterModelOptions(
name='productcategory',
options={'verbose_name': '产品类别', 'verbose_name_plural': '产品类别'},
),
]

View File

@@ -0,0 +1,29 @@
# Generated by Django 5.2.7 on 2025-11-03 04:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0002_alter_product_options_alter_productcategory_options'),
]
operations = [
migrations.CreateModel(
name='Supplier',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='供应商名称')),
('area', models.CharField(blank=True, max_length=100, null=True, verbose_name='地区')),
('email', models.EmailField(blank=True, max_length=254, null=True, verbose_name='电子邮箱')),
('mobile', models.CharField(blank=True, max_length=20, null=True, verbose_name='手机')),
('contact', models.TextField(blank=True, null=True, verbose_name='联系人')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
],
options={
'verbose_name': '供应商',
'verbose_name_plural': '供应商',
},
),
]

View File

@@ -0,0 +1,43 @@
# Generated by Django 5.2.7 on 2025-11-03 04:24
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0003_supplier'),
]
operations = [
migrations.AlterField(
model_name='product',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='productcategory',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name='supplier',
name='id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
migrations.CreateModel(
name='PurchaseOrder',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('order_date', models.DateField(verbose_name='订单日期')),
('total_amount', models.DecimalField(decimal_places=2, max_digits=15, verbose_name='总金额')),
('remarks', models.TextField(blank=True, null=True, verbose_name='备注')),
('supplier', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='purchase_orders', to='stock.supplier', verbose_name='供应商')),
],
options={
'verbose_name': '采购单',
'verbose_name_plural': '采购单',
},
),
]

View File

@@ -0,0 +1,58 @@
# Generated by Django 5.2.7 on 2025-11-03 04:29
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0004_alter_product_id_alter_productcategory_id_and_more'),
]
operations = [
migrations.AddField(
model_name='product',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='创建时间'),
preserve_default=False,
),
migrations.AddField(
model_name='product',
name='updated_at',
field=models.DateTimeField(auto_now=True, verbose_name='更新时间'),
),
migrations.AddField(
model_name='productcategory',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='创建时间'),
preserve_default=False,
),
migrations.AddField(
model_name='productcategory',
name='updated_at',
field=models.DateTimeField(auto_now=True, verbose_name='更新时间'),
),
migrations.AddField(
model_name='purchaseorder',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='创建时间'),
preserve_default=False,
),
migrations.AddField(
model_name='purchaseorder',
name='updated_at',
field=models.DateTimeField(auto_now=True, verbose_name='更新时间'),
),
migrations.AddField(
model_name='supplier',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='创建时间'),
preserve_default=False,
),
migrations.AddField(
model_name='supplier',
name='updated_at',
field=models.DateTimeField(auto_now=True, verbose_name='更新时间'),
),
]

View File

@@ -0,0 +1,29 @@
# Generated by Django 5.2.7 on 2025-11-03 04:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0005_product_created_at_product_updated_at_and_more'),
]
operations = [
migrations.CreateModel(
name='BankAccount',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100, verbose_name='名称')),
('auto_number', models.CharField(max_length=50, verbose_name='自动编号')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
('attachment', models.FileField(blank=True, null=True, upload_to='bank_accounts/', verbose_name='附件')),
],
options={
'verbose_name': '银行账户',
'verbose_name_plural': '银行账户',
},
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.7 on 2025-11-03 05:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0006_bankaccount'),
]
operations = [
migrations.AddField(
model_name='productcategory',
name='product_prefix',
field=models.CharField(blank=True, max_length=5, null=True, verbose_name='产品编号前缀'),
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.7 on 2025-11-03 05:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0007_productcategory_product_prefix'),
]
operations = [
migrations.AlterField(
model_name='product',
name='human_id',
field=models.CharField(blank=True, max_length=100, verbose_name='产品编号'),
),
migrations.AlterField(
model_name='productcategory',
name='product_prefix',
field=models.CharField(max_length=5, verbose_name='产品编号前缀'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.7 on 2025-11-03 05:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0008_alter_product_human_id_and_more'),
]
operations = [
migrations.AlterField(
model_name='product',
name='single_price',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True, verbose_name='单价'),
),
]

View File

@@ -0,0 +1,27 @@
# Generated by Django 5.2.7 on 2025-11-03 05:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0009_alter_product_single_price'),
]
operations = [
migrations.CreateModel(
name='ProdictUnit',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=20, verbose_name='单位名称')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
],
options={
'verbose_name': '产品单位',
'verbose_name_plural': '产品单位',
},
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 5.2.7 on 2025-11-03 05:28
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0010_prodictunit'),
]
operations = [
migrations.AlterField(
model_name='product',
name='unit',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='products', to='stock.prodictunit', verbose_name='单位'),
),
]

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.2.7 on 2025-11-03 05:34
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0011_alter_product_unit'),
]
operations = [
migrations.RenameModel(
old_name='ProdictUnit',
new_name='ProductUnit',
),
]

View File

@@ -0,0 +1,31 @@
# Generated by Django 5.2.7 on 2025-11-03 05:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0012_rename_prodictunit_productunit'),
]
operations = [
migrations.CreateModel(
name='WareHouse',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100, verbose_name='仓库名称')),
('location', models.CharField(blank=True, max_length=200, null=True, verbose_name='仓库地址')),
('contact', models.CharField(blank=True, max_length=100, null=True, verbose_name='联系人')),
('mobile', models.CharField(blank=True, max_length=20, null=True, verbose_name='手机')),
('area', models.CharField(blank=True, max_length=100, null=True, verbose_name='地区')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
],
options={
'verbose_name': '仓库资料',
'verbose_name_plural': '仓库资料',
},
),
]

View File

@@ -0,0 +1,46 @@
# Generated by Django 5.2.7 on 2025-11-03 06:06
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0013_warehouse'),
]
operations = [
migrations.DeleteModel(
name='BankAccount',
),
migrations.RemoveField(
model_name='product',
name='category',
),
migrations.RemoveField(
model_name='product',
name='unit',
),
migrations.RemoveField(
model_name='purchaseorder',
name='supplier',
),
migrations.DeleteModel(
name='WareHouse',
),
migrations.DeleteModel(
name='ProductCategory',
),
migrations.DeleteModel(
name='Product',
),
migrations.DeleteModel(
name='ProductUnit',
),
migrations.DeleteModel(
name='PurchaseOrder',
),
migrations.DeleteModel(
name='Supplier',
),
]

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.2.7 on 2025-11-03 06:11
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('basic_info', '0002_delete_purchaseorder'),
('stock', '0014_delete_bankaccount_remove_product_category_and_more'),
]
operations = [
migrations.CreateModel(
name='PurchaseOrder',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('order_date', models.DateField(verbose_name='订单日期')),
('total_amount', models.DecimalField(decimal_places=2, max_digits=15, verbose_name='总金额')),
('remarks', models.TextField(blank=True, null=True, verbose_name='备注')),
('supplier', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='purchase_orders', to='basic_info.supplier', verbose_name='供应商')),
],
options={
'verbose_name': '采购单',
'verbose_name_plural': '采购单',
},
),
]

View File

@@ -0,0 +1,34 @@
# Generated by Django 5.2.7 on 2025-11-03 07:47
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('basic_info', '0011_vehicletype_alter_deviceinfo_options_and_more'),
('stock', '0015_initial'),
]
operations = [
migrations.CreateModel(
name='Inventory',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('quantity', models.IntegerField(verbose_name='数量')),
('minimum_quantity', models.IntegerField(blank=True, null=True, verbose_name='最低库存量')),
('spec', models.CharField(blank=True, max_length=100, null=True, verbose_name='规格')),
('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.product', verbose_name='产品')),
('unit', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.productunit', verbose_name='单位')),
('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.warehouse', verbose_name='仓库')),
],
options={
'verbose_name': '库存',
'verbose_name_plural': '库存',
},
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.7 on 2025-11-03 08:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0016_inventory'),
]
operations = [
migrations.AddField(
model_name='inventory',
name='num_of_rolls',
field=models.IntegerField(blank=True, null=True, verbose_name='匹数'),
),
migrations.AlterField(
model_name='inventory',
name='quantity',
field=models.IntegerField(verbose_name='库存数量'),
),
]

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.2.7 on 2025-11-03 09:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0017_inventory_num_of_rolls_alter_inventory_quantity'),
]
operations = [
migrations.RemoveField(
model_name='inventory',
name='unit',
),
]

View File

46
stock/models.py Normal file
View File

@@ -0,0 +1,46 @@
from django.db import models
from flower.common import ModelBase
from basic_info import models as basic_info_models
class PurchaseOrder(ModelBase):
id = models.BigAutoField(primary_key=True)
supplier = models.ForeignKey(basic_info_models.Supplier, on_delete=models.PROTECT, related_name='purchase_orders', verbose_name='供应商')
order_date = models.DateField(verbose_name='订单日期')
total_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='总金额')
remarks = models.TextField(blank=True, null=True, verbose_name='备注')
def __str__(self):
return f'采购订单 {self.id} - {self.supplier.name}'
class Meta:
verbose_name = '采购单'
verbose_name_plural = '采购单'
class Inventory(ModelBase):
id = models.BigAutoField(primary_key=True)
product = models.ForeignKey(
basic_info_models.Product,
on_delete=models.PROTECT,
related_name='inventories',
verbose_name='产品',
)
warehouse = models.ForeignKey(
basic_info_models.WareHouse,
on_delete=models.PROTECT,
related_name='inventories',
verbose_name='仓库',
)
quantity = models.IntegerField(verbose_name='库存数量')
num_of_rolls = models.IntegerField(null=True, blank=True, verbose_name='匹数')
minimum_quantity = models.IntegerField(null=True, blank=True, verbose_name='最低库存量')
spec = models.CharField(max_length=100, blank=True, null=True, verbose_name='规格')
description = models.TextField(blank=True, null=True, verbose_name='备注描述')
def __str__(self):
return f'库存 {self.product.name} - 仓库: {self.warehouse.name}'
class Meta:
verbose_name = '库存'
verbose_name_plural = '库存'

3
stock/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

9
stock/views.py Normal file
View File

@@ -0,0 +1,9 @@
from ninja import NinjaAPI
router = NinjaAPI()
@router.get('/')
async def index(request):
return {'message': 'Welcome to the Stock API'}