Compare commits
2 Commits
1ef620cbea
...
5a1cc93b78
Author | SHA1 | Date |
---|---|---|
laoxiao | 5a1cc93b78 | 2 years ago |
laoxiao | 698420c493 | 2 years ago |
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../:\py_workspace\ERP_5\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="django" name="Django">
|
||||
<configuration>
|
||||
<option name="rootFolder" value="$MODULE_DIR$" />
|
||||
<option name="settingsModule" value="ERP_5/settings.py" />
|
||||
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
|
||||
<option name="environment" value="<map/>" />
|
||||
<option name="doNotUseTestRunner" value="false" />
|
||||
<option name="trackFilePattern" value="migrations" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/ERP_5/apps" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/../ERP_5\templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="erp_5" uuid="4bc53945-f65a-487e-8aae-a32e60fe31b7">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306/erp_5</jdbc-url>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,2 @@
|
||||
#n:information_schema
|
||||
!<md> [null, 0, null, null, -2147483648, -2147483648]
|
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
|
||||
<serverData>
|
||||
<paths name="root@192.168.23.3:22 agent">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
<paths name="root@192.168.23.3:22 password">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
</serverData>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,33 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="6">
|
||||
<item index="0" class="java.lang.String" itemvalue="mysqlclient" />
|
||||
<item index="1" class="java.lang.String" itemvalue="install" />
|
||||
<item index="2" class="java.lang.String" itemvalue="Django" />
|
||||
<item index="3" class="java.lang.String" itemvalue="urllib3" />
|
||||
<item index="4" class="java.lang.String" itemvalue="redis" />
|
||||
<item index="5" class="java.lang.String" itemvalue="idna" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="E501" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N802" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (django-3.2.16_env) (3)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ERP_5.iml" filepath="$PROJECT_DIR$/.idea/ERP_5.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/datas/nation_data.sql" dialect="GenericSQL" />
|
||||
<file url="PROJECT" dialect="MySQL" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,4 @@
|
||||
|
||||
from .celery import celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
@ -0,0 +1 @@
|
||||
# 存放所有项目中APP
|
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,9 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BasicInfoConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'basic_info'
|
||||
|
||||
def ready(self):
|
||||
import basic_info.signals
|
@ -0,0 +1,29 @@
|
||||
from rest_framework import serializers
|
||||
from basic_info.models import Nation, Province, City
|
||||
|
||||
|
||||
class NationSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
国家列化器
|
||||
"""
|
||||
class Meta:
|
||||
model = Nation
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ProvinceSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
省份列化器
|
||||
"""
|
||||
class Meta:
|
||||
model = Province
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class CitySerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
城市列化器
|
||||
"""
|
||||
class Meta:
|
||||
model = City
|
||||
fields = '__all__'
|
@ -0,0 +1,24 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from basic_info.models import CustomerModel
|
||||
|
||||
|
||||
class CustomerSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
客户信息的序列化器
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class CustomerFindSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
搜索过滤的序列化器
|
||||
"""
|
||||
name = serializers.CharField(required=False, write_only=True, help_text='客户名称关键字')
|
||||
|
||||
class Meta:
|
||||
model = CustomerModel
|
||||
fields = ['name', 'mobile', 'phone']
|
@ -0,0 +1,12 @@
|
||||
from basic_info.models import SettlementAccountModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class AccountSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
结算账户信息的序列化器
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = SettlementAccountModel
|
||||
fields = '__all__'
|
@ -0,0 +1,24 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from basic_info.models import SupplierModel
|
||||
|
||||
|
||||
class SupplierSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
供应商信息的序列化器
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = SupplierModel
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class SupplierFindSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
搜索过滤的序列化器
|
||||
"""
|
||||
name = serializers.CharField(required=False, write_only=True)
|
||||
|
||||
class Meta:
|
||||
model = SupplierModel
|
||||
fields = ['name', 'mobile', 'phone']
|
@ -0,0 +1,24 @@
|
||||
from basic_info.models import WarehouseModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class WarehouseSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
仓库信息的序列化器
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = WarehouseModel
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
# 用于查询结果的序列化器,因为需要显示负责人的真实名字
|
||||
class WarehouseSearchSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
查询结果的序列化, SlugRelatedField,返回主表的某一个字段值:slug_field可以指定一个需要展示的字段
|
||||
"""
|
||||
leader_user = serializers.SlugRelatedField(slug_field='real_name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = WarehouseModel
|
||||
fields = '__all__'
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,39 @@
|
||||
"""ERP_5 URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import supplier_views, customer_views, area_viewsets, settlement_account_views, warehouse_views
|
||||
from rest_framework_jwt.views import obtain_jwt_token
|
||||
|
||||
urlpatterns = [
|
||||
# path('admin/', admin.site.urls),
|
||||
# path('users/login/', obtain_jwt_token), # 登录并且由JWT签发token
|
||||
# re_path(r'^users/reset/(?P<pk>\d+)/$', user_views.ResetPasswordView.as_view()),
|
||||
|
||||
|
||||
]
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register('suppliers', supplier_views.SupplierViewSet)
|
||||
router.register('customers', customer_views.CustomerViewSet)
|
||||
router.register(r'nation', area_viewsets.NationView) # 国家的视图接口
|
||||
router.register(r'province', area_viewsets.ProvinceView) # 省份的视图接口
|
||||
router.register(r'city', area_viewsets.CityView) # 城市的视图接口
|
||||
router.register(r'warehouses', warehouse_views.WarehouseView) #
|
||||
router.register(r'accounts', settlement_account_views.AccountView) #
|
||||
|
||||
urlpatterns += router.urls
|
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,9 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ErpSystemConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'erp_system'
|
||||
#
|
||||
# def ready(self):
|
||||
# import erp_system.signals
|
@ -0,0 +1,27 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from erp_system.models import DeptModel
|
||||
|
||||
|
||||
class ChildDeptSerializer(serializers.ModelSerializer):
|
||||
children = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = DeptModel
|
||||
fields = ['id', 'name', 'parent', 'children']
|
||||
|
||||
def get_children(self, obj):
|
||||
if obj.children:
|
||||
return ChildDeptSerializer(instance=obj.children, many=True).data
|
||||
return None
|
||||
|
||||
|
||||
class DeptSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
部门的序列化器
|
||||
"""
|
||||
children = ChildDeptSerializer(read_only=True, many=True)
|
||||
|
||||
class Meta:
|
||||
model = DeptModel
|
||||
fields = ['id', 'name', 'parent', 'children']
|
@ -0,0 +1,10 @@
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
|
||||
from erp_system.models import Menu
|
||||
|
||||
|
||||
class MenuSerializer(ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Menu
|
||||
fields = '__all__'
|
@ -0,0 +1,9 @@
|
||||
from rest_framework.serializers import ModelSerializer, ValidationError
|
||||
from erp_system.models import PermissionsModel
|
||||
|
||||
|
||||
# 权限基本的序列化类
|
||||
class PermissionsSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = PermissionsModel
|
||||
fields = '__all__'
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,39 @@
|
||||
"""ERP_5 URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import menu_views, user_views, dept_views, role_views, permission_views
|
||||
|
||||
from rest_framework_jwt.views import obtain_jwt_token
|
||||
|
||||
urlpatterns = [
|
||||
# path('admin/', admin.site.urls),
|
||||
path('users/login/', obtain_jwt_token), # 登录并且由JWT签发token
|
||||
re_path(r'^users/reset/(?P<pk>\d+)/$', user_views.ResetPasswordView.as_view()),
|
||||
|
||||
|
||||
]
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register('menus', menu_views.MenuViewSet)
|
||||
router.register('users/register', user_views.RegisterUserView)
|
||||
router.register('roles', role_views.RolesViewSet)
|
||||
router.register('permissions', permission_views.PermissionViewSet)
|
||||
router.register('dept', dept_views.DeptViewSet)
|
||||
router.register('users', user_views.UserView)
|
||||
|
||||
urlpatterns += router.urls
|
@ -0,0 +1,53 @@
|
||||
from rest_framework import mixins
|
||||
from rest_framework.generics import GenericAPIView
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
|
||||
from ERP_5.utils.base_views import MultipleDestroyMixin
|
||||
from ERP_5.utils.paginations import GlobalPagination
|
||||
from erp_system.models import UserModel
|
||||
from erp_system.serializers.user_serializer import UserAddSerializer, UserUpdateDeleteSerializer, UserGetSerializer, \
|
||||
ResetPasswordSerializer
|
||||
|
||||
|
||||
class RegisterUserView(mixins.CreateModelMixin, GenericViewSet):
|
||||
"""
|
||||
create:
|
||||
用户注册。
|
||||
|
||||
并且把用户注册之后的用户信息返回
|
||||
"""
|
||||
queryset = UserModel.objects.all()
|
||||
serializer_class = UserAddSerializer
|
||||
|
||||
|
||||
class UserView(mixins.RetrieveModelMixin,
|
||||
mixins.UpdateModelMixin,
|
||||
mixins.DestroyModelMixin,
|
||||
mixins.ListModelMixin,
|
||||
MultipleDestroyMixin, # 批量删除用户
|
||||
GenericViewSet):
|
||||
"""
|
||||
没有用户注册和修改用户密码的模型类
|
||||
"""
|
||||
queryset = UserModel.objects.all()
|
||||
pagination_class = GlobalPagination
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action == 'partial_update' or self.action == 'update' or self.action == 'destroy':
|
||||
return UserUpdateDeleteSerializer
|
||||
else:
|
||||
return UserGetSerializer
|
||||
|
||||
|
||||
class ResetPasswordView(mixins.UpdateModelMixin, GenericAPIView):
|
||||
"""
|
||||
patch:
|
||||
用户--重置密码
|
||||
|
||||
用户重置密码, status: 200(成功), return: None
|
||||
"""
|
||||
queryset = UserModel.objects.all()
|
||||
serializer_class = ResetPasswordSerializer
|
||||
|
||||
def patch(self, request, *args, **kwargs):
|
||||
return self.partial_update(request, *args, **kwargs)
|
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class GoodsInfoConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'goods_info'
|
@ -0,0 +1,120 @@
|
||||
from django.db import models
|
||||
|
||||
from django.db import models
|
||||
from ERP_5.utils.base_model import BaseModel
|
||||
|
||||
|
||||
# 货品(商品)类别模型类
|
||||
class GoodsCategoryModel(BaseModel):
|
||||
name = models.CharField(max_length=100, verbose_name='类别名称')
|
||||
number_code = models.CharField('编号', max_length=28, unique=True)
|
||||
remark = models.CharField('备注', max_length=512, blank=True, null=True)
|
||||
order_number = models.IntegerField('排序号码', default=100)
|
||||
parent = models.ForeignKey('self', blank=True, null=True, related_name='children', on_delete=models.SET_NULL)
|
||||
|
||||
class Meta:
|
||||
db_table = 't_category'
|
||||
verbose_name = '商品类别'
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['order_number', 'id']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
# 计量单位模型类
|
||||
class UnitsModel(BaseModel):
|
||||
basic_name = models.CharField(max_length=20, verbose_name='基本单位', unique=True)
|
||||
backup_name = models.CharField('副单位', max_length=20, null=True, blank=True)
|
||||
remark = models.CharField('备注', max_length=512, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 't_units'
|
||||
verbose_name = '计量单位'
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.basic_name}({self.backup_name})'
|
||||
|
||||
|
||||
# 图片或者附件的模型类
|
||||
class AttachmentModel(BaseModel):
|
||||
# 附件文件的类型
|
||||
type_choices = (
|
||||
('image', '图片'),
|
||||
('doc', 'Word文档'),
|
||||
('excel', 'Excel文档'),
|
||||
('zip', '压缩文件'),
|
||||
('other', '其他文件')
|
||||
)
|
||||
"""
|
||||
只要是choices参数的字段 如果你想要获取对应信息 固定写法 get_字段名_display()
|
||||
print(Attachment.a_type)
|
||||
print(Attachment.get_a_type_display())
|
||||
"""
|
||||
a_file = models.FileField('附件或者图片')
|
||||
a_type = models.CharField('附件的类型', max_length=20, blank=True, null=True, choices=type_choices)
|
||||
|
||||
class Meta:
|
||||
db_table = 't_attachment'
|
||||
verbose_name = '附件表'
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return self.a_file.name
|
||||
|
||||
|
||||
# 货品库存 模型类
|
||||
class GoodsInventoryModel(models.Model):
|
||||
# 期初库存数量在创建好之后不能修改
|
||||
init_inventory = models.DecimalField('期初库存数量', max_digits=10, decimal_places=2, default=0)
|
||||
cur_inventory = models.DecimalField('现在库存数量', max_digits=10, decimal_places=2, default=0)
|
||||
lowest_inventory = models.DecimalField('最低安全库存, 0表示不设置', max_digits=10, decimal_places=2, default=0)
|
||||
highest_inventory = models.DecimalField('最高安全库存,0表示不设置', max_digits=10, decimal_places=2, default=0)
|
||||
|
||||
goods = models.ForeignKey('GoodsModel', related_name='inventory_list', on_delete=models.CASCADE, blank=True,
|
||||
null=True)
|
||||
warehouse = models.ForeignKey('basic_info.WarehouseModel', on_delete=models.CASCADE)
|
||||
# 冗余字段,主要目的:减少联表查询的次数
|
||||
warehouse_name = models.CharField('仓库的名称', max_length=50)
|
||||
|
||||
class Meta:
|
||||
db_table = 't_goods_inventory'
|
||||
verbose_name = '货品库存表'
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['id']
|
||||
|
||||
def __str__(self):
|
||||
return self.warehouse_name + str(self.id)
|
||||
|
||||
|
||||
# 货品(商品)模型类
|
||||
class GoodsModel(BaseModel):
|
||||
name = models.CharField(max_length=20, verbose_name='货品名称', unique=True)
|
||||
specification = models.CharField('规格', max_length=50, null=True, blank=True)
|
||||
model_number = models.CharField('型号', max_length=50, null=True, blank=True)
|
||||
color = models.CharField('颜色', max_length=50, null=True, blank=True)
|
||||
basic_weight = models.CharField('基础重量', max_length=50, null=True, blank=True)
|
||||
expiration_day = models.IntegerField('保质期', null=True, blank=True)
|
||||
remark = models.CharField('备注', max_length=512, blank=True, null=True)
|
||||
number_code = models.CharField('编号或者批号', max_length=28, unique=True)
|
||||
purchase_price = models.DecimalField('采购价', max_digits=10, decimal_places=2, blank=True, default=0) # 精确到小数点后两位
|
||||
retail_price = models.DecimalField('零售价', max_digits=10, decimal_places=2, blank=True, default=0) # 精确到小数点后两位
|
||||
sales_price = models.DecimalField('销售价', max_digits=10, decimal_places=2, blank=True, default=0) # 精确到小数点后两位
|
||||
lowest_price = models.DecimalField('最低售价', max_digits=10, decimal_places=2, blank=True, default=0) # 精确到小数点后两位
|
||||
order_number = models.IntegerField('排序号码', default=100)
|
||||
|
||||
units = models.ForeignKey('UnitsModel', on_delete=models.SET_NULL, null=True, blank=True)
|
||||
category = models.ForeignKey('GoodsCategoryModel', on_delete=models.SET_NULL, null=True, blank=True)
|
||||
images_list = models.CharField('商品附件所对应的id列表', max_length=20, null=True, blank=True) # 字段的值为: 1,2,3,4
|
||||
|
||||
class Meta:
|
||||
db_table = 't_goods'
|
||||
verbose_name = '货品表'
|
||||
verbose_name_plural = verbose_name
|
||||
ordering = ['order_number', 'id']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
@ -0,0 +1,21 @@
|
||||
from goods_info.models import AttachmentModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class AttachmentsSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
附件和图片的序列化器
|
||||
"""
|
||||
# source 如果是字段,会显示字段,如果是方法,会执行方法,不用加括号
|
||||
# 附件或者图片的文件名
|
||||
file_name = serializers.CharField(source='a_file.name', read_only=True)
|
||||
|
||||
# 附件或者图片的访问地址
|
||||
file_url = serializers.CharField(source='a_file.url', read_only=True)
|
||||
|
||||
# 附件的文件类型(中文)
|
||||
type_display = serializers.CharField(source='get_a_type_display', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = AttachmentModel
|
||||
fields = ['id', 'a_file', 'a_type', 'file_url', 'file_name', 'type_display']
|
@ -0,0 +1,19 @@
|
||||
from goods_info.models import GoodsCategoryModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class CategorySerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
商品类别的序列化器
|
||||
"""
|
||||
# 树形展示
|
||||
children = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = GoodsCategoryModel
|
||||
fields = ['id', 'number_code', 'remark', 'name', 'order_number', 'parent', 'children']
|
||||
|
||||
def get_children(self, obj):
|
||||
if obj.children:
|
||||
return CategorySerializer(obj.children, many=True).data
|
||||
return None
|
@ -0,0 +1,17 @@
|
||||
from goods_info.models import UnitsModel
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class UnitsSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
计量单位的序列化器
|
||||
"""
|
||||
# 指定新增的属性,是从一个函数中得到值
|
||||
units_name = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = UnitsModel
|
||||
fields = ['id', 'basic_name', 'backup_name', 'delete_flag', 'units_name']
|
||||
|
||||
def get_units_name(self, obj):
|
||||
return str(obj) # 就是调用该对象的__str__函数
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,34 @@
|
||||
"""ERP_5 URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import units_views, attachments_views, goods_category_views, goods_views
|
||||
|
||||
from rest_framework_jwt.views import obtain_jwt_token
|
||||
|
||||
urlpatterns = [
|
||||
# path('admin/', admin.site.urls),
|
||||
|
||||
]
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register('category', goods_category_views.CategoryView)
|
||||
router.register('units', units_views.UnitsView)
|
||||
router.register('attachments', attachments_views.AttachmentView)
|
||||
router.register('goods', goods_views.GoodsInfoViewSet)
|
||||
|
||||
urlpatterns += router.urls
|
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PurchaseInfoConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'purchase_info'
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,31 @@
|
||||
"""ERP_5 URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
# from .views import units_views, attachments_views, goods_category_views, goods_views
|
||||
|
||||
from rest_framework_jwt.views import obtain_jwt_token
|
||||
|
||||
urlpatterns = [
|
||||
# path('admin/', admin.site.urls),
|
||||
|
||||
]
|
||||
|
||||
router = DefaultRouter()
|
||||
# router.register('category', goods_category_views.CategoryView)
|
||||
|
||||
urlpatterns += router.urls
|
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for ERP_5 project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ERP_5.settings')
|
||||
|
||||
application = get_asgi_application()
|
@ -0,0 +1,15 @@
|
||||
import os
|
||||
from celery import Celery
|
||||
from django.conf import settings
|
||||
import django
|
||||
|
||||
# 设置环境变量
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ERP_5.settings.dev')
|
||||
|
||||
# 注册Celery的APP, ERP_5必须是项目名字
|
||||
celery_app = Celery('ERP_5')
|
||||
# 绑定配置文件
|
||||
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# 自动从settings.INSTALLED_APPS注册的应用中加载tasks.py
|
||||
celery_app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
After Width: | Height: | Size: 7.3 MiB |
@ -0,0 +1,126 @@
|
||||
"""
|
||||
Django settings for ERP_5 project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.2.16.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-o!nl319=c4gr)@c)n#@*kq)zil-i(4puha&59&1o*wd0cbrj!5'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'ERP_5.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'ERP_5.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
@ -0,0 +1,51 @@
|
||||
"""ERP_5 URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include, re_path
|
||||
from django.views.static import serve
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.views import get_schema_view
|
||||
from rest_framework import permissions
|
||||
from rest_framework.documentation import include_docs_urls
|
||||
from ERP_5.utils.base_views import GenerateCode
|
||||
|
||||
schema_view = get_schema_view(
|
||||
openapi.Info(
|
||||
title="接口 API文档",
|
||||
default_version='v1',
|
||||
description="马士兵ERP系统项目接口文档",
|
||||
),
|
||||
public=True,
|
||||
permission_classes=(permissions.AllowAny,),
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', include('erp_system.urls')),
|
||||
path('api/', include('basic_info.urls')),
|
||||
path('api/', include('goods_info.urls')),
|
||||
path('api/', include('purchase_info.urls')),
|
||||
re_path(r'^api/generate_code/$', GenerateCode.as_view()),
|
||||
|
||||
# 媒体资源文件的访问路由
|
||||
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
|
||||
path('docs/', include_docs_urls(title='ERP系统的接口文档')),
|
||||
# swagger接口文档的路由
|
||||
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
|
||||
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
]
|
@ -0,0 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
"""所有模型的父类"""
|
||||
delete_flag = models.CharField('是否启用', max_length=1, default='0', help_text='是否启用')
|
||||
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
|
||||
update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间', help_text='更新时间')
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
@ -0,0 +1,17 @@
|
||||
from enum import Enum, unique
|
||||
|
||||
"""
|
||||
各个不同类型的前缀枚举类
|
||||
"""
|
||||
|
||||
|
||||
@unique
|
||||
class NumberPrefix(Enum): # 定义编号的前缀
|
||||
# 结算账户编号的前缀
|
||||
acc = 'ACC'
|
||||
# 销售订单编号的前缀
|
||||
ord = 'ORD'
|
||||
# 商品类别编号的前缀
|
||||
cat = 'CAT'
|
||||
# 商品信息编号的前缀
|
||||
goo = 'GOO'
|
@ -0,0 +1,22 @@
|
||||
import string
|
||||
import time
|
||||
import random
|
||||
|
||||
|
||||
def generate_code(prefix):
|
||||
"""
|
||||
生成28位流水编号: 3位前缀 + 14位的时间 + 7位的微秒 + 4位随机数
|
||||
"""
|
||||
seeds = string.digits
|
||||
random_str = random.choices(seeds, k=4)
|
||||
|
||||
random_str = "".join(random_str)
|
||||
code_no = "%s%s%s%s" % (prefix,
|
||||
time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())),
|
||||
str(time.time()).replace('.', '')[-7:],
|
||||
random_str)
|
||||
return code_no
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(generate_code('ORD'))
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue