最后提交

master
laoxiao 2 years ago
parent 7d1e03cbe0
commit fe8a9a7c2b

File diff suppressed because it is too large Load Diff

@ -33,12 +33,12 @@ class PaymentModel(BaseModel):
account = models.ForeignKey('basic_info.SettlementAccountModel', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='结算账户,审核之后不能改')
operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator_pay_list', null=True,
operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator14_pay_list', null=True,
blank=True, on_delete=models.SET_NULL,
verbose_name='财务操作人员,不能修改')
# 增加一个冗余字段
operator_user_name = models.CharField('财务人员的真实姓名', max_length=20, null=True, blank=True)
check_user = models.ForeignKey('erp_system.UserModel', related_name='operator3_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
check_user = models.ForeignKey('erp_system.UserModel', related_name='check13_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='审核人员,不能修改')
# 增加一个冗余字段
check_user_name = models.CharField('审核人员的真实姓名', max_length=20, null=True, blank=True)
@ -102,12 +102,12 @@ class ReceiptModel(BaseModel):
account = models.ForeignKey('basic_info.SettlementAccountModel', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='结算账户,审核之后不能改')
operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator2_pay_list', null=True,
operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator12_pay_list', null=True,
blank=True, on_delete=models.SET_NULL,
verbose_name='财务操作人员,不能修改')
# 增加一个冗余字段
operator_user_name = models.CharField('财务人员的真实姓名', max_length=20, null=True, blank=True)
check_user = models.ForeignKey('erp_system.UserModel', related_name='operator4_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
check_user = models.ForeignKey('erp_system.UserModel', related_name='operator11_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='审核人员,不能修改')
# 增加一个冗余字段
check_user_name = models.CharField('审核人员的真实姓名', max_length=20, null=True, blank=True)
@ -149,61 +149,61 @@ class ReceiptItemModel(BaseModel):
# 收款单的模型类
class ReceiptModel(BaseModel):
pay_date = models.DateTimeField('收款日期')
number_code = models.CharField('单据编号,不让用户填写', max_length=28)
discount_money = models.DecimalField('优惠金额(收款优惠),最多精确到小数点后两位', max_digits=10, default=0, decimal_places=2,
blank=True, null=True)
receipt_money = models.DecimalField('合计 收款金额最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
this_money = models.DecimalField('实际 收款金额最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
remark = models.CharField('备注', max_length=512, blank=True, null=True)
currency = models.CharField('货币种类', max_length=20, null=True, choices=currency_choices, default='CNY')
pay_category = models.CharField('收款类型', max_length=2, null=True, choices=pay_choices, default='1')
status = models.CharField('状态,0:未审核,1:已审核', max_length=1, default='0')
account = models.ForeignKey('basic_info.SettlementAccountModel', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='结算账户,审核之后不能改')
operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator_pay_list', null=True,
blank=True, on_delete=models.SET_NULL,
verbose_name='财务操作人员,不能修改')
# 增加一个冗余字段
operator_user_name = models.CharField('财务人员的真实姓名', max_length=20, null=True, blank=True)
check_user = models.ForeignKey('erp_system.UserModel', related_name='operator3_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='审核人员,不能修改')
# 增加一个冗余字段
check_user_name = models.CharField('审核人员的真实姓名', max_length=20, null=True, blank=True)
customer = models.ForeignKey('basic_info.CustomerModel', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='客户,审核之后不能改')
# 增加一个冗余字段
customer_name = models.CharField('客户名称', max_length=30, null=True, blank=True)
sale = models.ForeignKey('purchase_info.SaleModel', null=True, blank=True, on_delete=models.SET_NULL,
verbose_name='销售订单,审核之后不能改')
attachment_list = models.CharField('附件的id列表字段的值为: 1,2,3,4', max_length=20, null=True, blank=True)
class Meta:
db_table = 't_receipt'
verbose_name = '收款单表'
verbose_name_plural = verbose_name
ordering = ['id']
# 收款单中 收款项目的模型类
class ReceiptItemModel(BaseModel):
# 冗余字段
storage_code = models.CharField('销售出库单编号,不让用户填写', max_length=28)
deliver_storage = models.ForeignKey('warehouse_info.SaleDeliverModel', related_name='pay_item_list', null=True, blank=True,
on_delete=models.SET_NULL, verbose_name='采购入库单')
receipt = models.ForeignKey('ReceiptModel', null=True, blank=True, related_name='item_list', on_delete=models.SET_NULL,
verbose_name='收款单,不能改')
should_money = models.DecimalField('应该 收款金额(就是采购入库单中需要支收的金额),最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
this_money = models.DecimalField('本次 收款金额,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
remark = models.CharField('备注', max_length=512, blank=True, null=True)
class Meta:
db_table = 't_receipt_item'
verbose_name = '收款单中的 收款项目表'
verbose_name_plural = verbose_name
ordering = ['id']
# class ReceiptModel(BaseModel):
# pay_date = models.DateTimeField('收款日期')
# number_code = models.CharField('单据编号,不让用户填写', max_length=28)
# discount_money = models.DecimalField('优惠金额(收款优惠),最多精确到小数点后两位', max_digits=10, default=0, decimal_places=2,
# blank=True, null=True)
# receipt_money = models.DecimalField('合计 收款金额最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
# this_money = models.DecimalField('实际 收款金额最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
# remark = models.CharField('备注', max_length=512, blank=True, null=True)
# currency = models.CharField('货币种类', max_length=20, null=True, choices=currency_choices, default='CNY')
# pay_category = models.CharField('收款类型', max_length=2, null=True, choices=pay_choices, default='1')
# status = models.CharField('状态,0:未审核,1:已审核', max_length=1, default='0')
#
# account = models.ForeignKey('basic_info.SettlementAccountModel', null=True, blank=True, on_delete=models.SET_NULL,
# verbose_name='结算账户,审核之后不能改')
# operator_user = models.ForeignKey('erp_system.UserModel', related_name='operator_pay_list', null=True,
# blank=True, on_delete=models.SET_NULL,
# verbose_name='财务操作人员,不能修改')
# # 增加一个冗余字段
# operator_user_name = models.CharField('财务人员的真实姓名', max_length=20, null=True, blank=True)
# check_user = models.ForeignKey('erp_system.UserModel', related_name='operator3_pay_list', null=True, blank=True, on_delete=models.SET_NULL,
# verbose_name='审核人员,不能修改')
# # 增加一个冗余字段
# check_user_name = models.CharField('审核人员的真实姓名', max_length=20, null=True, blank=True)
#
# customer = models.ForeignKey('basic_info.CustomerModel', null=True, blank=True, on_delete=models.SET_NULL,
# verbose_name='客户,审核之后不能改')
# # 增加一个冗余字段
# customer_name = models.CharField('客户名称', max_length=30, null=True, blank=True)
# sale = models.ForeignKey('purchase_info.SaleModel', null=True, blank=True, on_delete=models.SET_NULL,
# verbose_name='销售订单,审核之后不能改')
# attachment_list = models.CharField('附件的id列表字段的值为: 1,2,3,4', max_length=20, null=True, blank=True)
#
# class Meta:
# db_table = 't_receipt'
# verbose_name = '收款单表'
# verbose_name_plural = verbose_name
# ordering = ['id']
#
#
# # 收款单中 收款项目的模型类
# class ReceiptItemModel(BaseModel):
# # 冗余字段
# storage_code = models.CharField('销售出库单编号,不让用户填写', max_length=28)
# deliver_storage = models.ForeignKey('warehouse_info.SaleDeliverModel', related_name='pay_item_list', null=True, blank=True,
# on_delete=models.SET_NULL, verbose_name='采购入库单')
#
# receipt = models.ForeignKey('ReceiptModel', null=True, blank=True, related_name='item_list', on_delete=models.SET_NULL,
# verbose_name='收款单,不能改')
# should_money = models.DecimalField('应该 收款金额(就是采购入库单中需要支收的金额),最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
# this_money = models.DecimalField('本次 收款金额,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
#
# remark = models.CharField('备注', max_length=512, blank=True, null=True)
#
# class Meta:
# db_table = 't_receipt_item'
# verbose_name = '收款单中的 收款项目表'
# verbose_name_plural = verbose_name
# ordering = ['id']

@ -142,3 +142,24 @@ class ProductProcessModel(BaseModel):
db_table = 't_product_process'
verbose_name = '生产工序表'
verbose_name_plural = verbose_name
# 生产过程中的验收记录
class InspectionRecordModel(BaseModel):
inspection_date = models.DateField('验收日期')
inspection_username = models.CharField('验收人员的名字', max_length=20)
inspection_user = models.ForeignKey('erp_system.UserModel', related_name='inspection_in_list', null=True, blank=True,
on_delete=models.SET_NULL, verbose_name='验收人员')
qualified_count = models.DecimalField('合格数量,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
unqualified_count = models.DecimalField('不合格的数量,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
scrap_count = models.DecimalField('报废的数量', max_digits=10, decimal_places=2, default=0)
remark = models.CharField('备注', max_length=512, blank=True, null=True)
product_task = models.ForeignKey('ProductTaskModel', on_delete=models.SET_NULL, null=True, blank=True,
verbose_name='生产任务', related_name='inspection_list')
class Meta:
db_table = 't_inspection_record'
verbose_name = '验收记录表'
verbose_name_plural = verbose_name

@ -0,0 +1,30 @@
from django.db import transaction
from django.db.models import F
from rest_framework import serializers
from production_info.models import InspectionRecordModel, ProductTaskModel
class InspectionRecordSerializer(serializers.ModelSerializer):
"""
验收记录的序列化器
"""
class Meta:
model = InspectionRecordModel
fields = '__all__'
def create(self, validated_data):
"""
1插入一条验收记录数据
2修改生产任务中的 验收合格数量
:param validated_data:
:return:
"""
with transaction.atomic():
# 第一件事情搞定
irm: InspectionRecordModel = super(InspectionRecordSerializer, self).create(validated_data)
# 修改生产任务中的: 验收合格数量
ProductTaskModel.objects.filter(id=irm.product_task_id) \
.update(check_number=F('check_number') + irm.qualified_count)
return irm

@ -10,7 +10,7 @@ from ERP_5.utils.get_inventory import get_inventory_by_goods
from basic_info.models import WarehouseModel
from goods_info.models import GoodsModel, GoodsInventoryModel
from production_info.models import ProductProcessModel, ProductMaterialModel, ProductTaskModel
from warehouse_info.models import SaleDeliverModel, SaleDeliverItemModel
from warehouse_info.models import SaleDeliverModel, SaleDeliverItemModel, PurchaseStorageModel, PurchaseStorageItemModel
class ProductProcessSerializer(serializers.ModelSerializer):
@ -65,17 +65,21 @@ class ProductTaskSerializer(serializers.ModelSerializer):
return pt
def update(self, instance, validated_data):
if instance.status != '0':
raise ValidationError("生产任务已经生效,不能修改!")
process_list = validated_data.pop('process_list')
material_list = validated_data.pop('material_list')
process_list = []
material_list = []
if instance.status == '2':
raise ValidationError("生产任务已经完成,不能修改!")
if 'process_list' in validated_data:
process_list = validated_data.pop('process_list')
if 'material_list' in validated_data:
material_list = validated_data.pop('material_list')
old_list1 = instance.process_list
old_list2 = instance.material_list
with transaction.atomic():
if old_list1.exists():
if process_list and old_list1.exists():
# 然后把旧数据删除因为在validated_data拿不到货品库存数据的ID
instance.process_list.all().delete()
if old_list2.exists():
if material_list and old_list2.exists():
# 然后把旧数据删除因为在validated_data拿不到货品库存数据的ID
instance.material_list.all().delete()
for item in process_list:
@ -151,3 +155,133 @@ class GetMaterialSerializer(serializers.Serializer):
material_id = serializers.IntegerField(help_text='所属生产物料的主键')
pt_id = serializers.IntegerField(help_text='所属生产任务的主键')
class BackMaterialSerializer(serializers.Serializer):
"""
退料的序列化器
"""
def update(self, instance, validated_data):
pass
def create(self, validated_data):
# 需要完成4件事情
with transaction.atomic():
# 1、插入 入库单
storage = PurchaseStorageModel.objects.create(invoices_date=timezone.now(),
number_code=generate_code(NumberPrefix['storage'].value),
last_amount=validated_data['money'],
number_count=validated_data['count'],
product_task_id=validated_data['pt_id'],
status='1',
is_other='1')
# 2、插入 入库单中的项目
goods = GoodsModel.objects.get(pk=validated_data['good_id'])
wh = WarehouseModel.objects.get(pk=validated_data['warehouse_id'])
psi = PurchaseStorageItemModel()
psi.goods_id = goods.id
psi.specification = goods.specification
psi.model_number = goods.model_number
psi.number_code = goods.number_code
psi.color = goods.color
psi.category = goods.category
psi.category_name = goods.category.name
psi.units = goods.units
psi.units_name = goods.units.basic_name
psi.name = goods.name
psi.purchase_count = validated_data['count']
psi.purchase_price = validated_data['price']
psi.purchase_money = validated_data['money']
psi.warehouse_name = wh.name
psi.warehouse_id = wh.id
psi.purchase_storage_id = storage.id
psi.save()
# 3、 修改库存数量
GoodsInventoryModel.objects \
.filter(goods_id=goods.id, warehouse_id=wh.id) \
.update(cur_inventory=F('cur_inventory') + psi.purchase_count)
# 4、 修改生产物料中退料数量
ProductMaterialModel.objects.filter(id=validated_data['material_id']) \
.update(back_count=F('back_count') + psi.purchase_count)
return storage
goods_number_code = serializers.CharField(help_text='物料的条码或者编号', required=False)
warehouse_name = serializers.CharField(help_text='退还仓库的名字', required=False)
warehouse_id = serializers.IntegerField(help_text='退还仓库的主键')
good_id = serializers.IntegerField(help_text='退还的货品主键')
count = serializers.DecimalField(help_text='退还数量,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
price = serializers.DecimalField(help_text='退还的成本单价,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
money = serializers.DecimalField(help_text='退还的成本总价,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
material_id = serializers.IntegerField(help_text='所属生产物料的主键')
pt_id = serializers.IntegerField(help_text='所属生产任务的主键')
class ProductStorageSerializer(serializers.Serializer):
"""
生产入库的序列化器
"""
def update(self, instance, validated_data):
pass
def create(self, validated_data):
# 需要完成4件事情
with transaction.atomic():
# 1、插入 入库单
storage = PurchaseStorageModel.objects.create(invoices_date=timezone.now(),
number_code=generate_code(NumberPrefix['storage'].value),
last_amount=validated_data['money'],
number_count=validated_data['count'],
product_task_id=validated_data['pt_id'],
status='1',
is_other='1')
# 2、插入 入库单中的项目
goods = GoodsModel.objects.get(pk=validated_data['good_id'])
wh = WarehouseModel.objects.get(pk=validated_data['warehouse_id'])
psi = PurchaseStorageItemModel()
psi.goods_id = goods.id
psi.specification = goods.specification
psi.model_number = goods.model_number
psi.number_code = goods.number_code
psi.color = goods.color
psi.category = goods.category
psi.category_name = goods.category.name
psi.units = goods.units
psi.units_name = goods.units.basic_name
psi.name = goods.name
psi.purchase_count = validated_data['count']
psi.purchase_price = validated_data['price']
psi.purchase_money = validated_data['money']
psi.warehouse_name = wh.name
psi.warehouse_id = wh.id
psi.purchase_storage_id = storage.id
psi.save()
# 3、 修改库存数量
GoodsInventoryModel.objects \
.filter(goods_id=goods.id, warehouse_id=wh.id) \
.update(cur_inventory=F('cur_inventory') + psi.purchase_count)
# 4、 修改生产任务的:已入库数量
ProductTaskModel.objects.filter(id=validated_data['pt_id']) \
.update(storage_number=F('storage_number') + psi.purchase_count)
return storage
goods_number_code = serializers.CharField(help_text='入库商品的条码或者编号', required=False)
good_id = serializers.IntegerField(help_text='入库的货品主键')
warehouse_name = serializers.CharField(help_text='入库仓库的名字', required=False)
warehouse_id = serializers.IntegerField(help_text='入库仓库的主键')
count = serializers.DecimalField(help_text='入库数量,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
price = serializers.DecimalField(help_text='成本单价,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
money = serializers.DecimalField(help_text='入库成本总价,最多精确到小数点后两位', max_digits=10, decimal_places=2, default=0)
pt_id = serializers.IntegerField(help_text='所属生产任务的主键')

@ -16,7 +16,7 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, re_path
from rest_framework.routers import DefaultRouter
from .views import bom_views, product_task_views
from .views import bom_views, product_task_views, inspection_views
from rest_framework_jwt.views import obtain_jwt_token
@ -31,5 +31,6 @@ router.register('bom_material', bom_views.MaterialViewSets)
router.register('bom_process', bom_views.ProcessViewSets)
router.register('bom', bom_views.GoodsBomViewSet)
router.register('products', product_task_views.ProductTaskViewSets)
router.register('inspection', inspection_views.InspectionViewSets)
urlpatterns += router.urls

@ -0,0 +1,41 @@
from rest_framework.viewsets import ModelViewSet
from production_info.models import InspectionRecordModel
from production_info.serializer.inspection_serializer import InspectionRecordSerializer
class InspectionViewSets(ModelViewSet):
"""
create:
验收记录--新增
验收记录新增, status: 201(成功), return: 新增验收记录信息
destroy:
验收记录--删除
验收记录删除, status: 204(成功), return: None
update:
验收记录--修改,注意其中images_list="1,2,3,4";里面是附件的ID
验收记录修改, status: 200(成功), return: 修改后的验收记录信息
partial_update:
验收记录--局部修改,可以传参任意属性的值服务器会修改指定的属性值
验收记录局部修改, status: 200(成功), return: 修改后的验收记录信息
list:
验收记录--的列表查询
验收记录列表信息, status: 200(成功), return: 验收记录信息列表
retrieve:
查询某一个验收记录
查询指定ID的验收记录, status: 200(成功), return: 用户验收记录
"""
queryset = InspectionRecordModel.objects.all()
serializer_class = InspectionRecordSerializer

@ -8,7 +8,8 @@ from rest_framework.response import Response
from ERP_5.utils.base_views import MultipleDestroyMixin, MultipleAuditMixin
from ERP_5.utils.paginations import GlobalPagination
from production_info.models import ProductTaskModel
from production_info.serializer.product_task_serializer import ProductTaskSerializer, GetMaterialSerializer
from production_info.serializer.product_task_serializer import ProductTaskSerializer, GetMaterialSerializer, \
BackMaterialSerializer, ProductStorageSerializer
class ProductTaskViewSets(viewsets.ModelViewSet, MultipleDestroyMixin, MultipleAuditMixin):
@ -106,5 +107,27 @@ class ProductTaskViewSets(viewsets.ModelViewSet, MultipleDestroyMixin, MultipleA
def get_serializer_class(self):
if self.action == 'get_material':
return GetMaterialSerializer
elif self.action == 'back_material':
return BackMaterialSerializer
elif self.action == 'product_storage':
return ProductStorageSerializer
else:
return ProductTaskSerializer
@swagger_auto_schema(method='POST', request_body=BackMaterialSerializer,
operation_description="生产任务中退还物料")
@action(methods=['POST'], detail=False)
def back_material(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
result = serializer.save()
return Response({'msg': 'ok'})
@swagger_auto_schema(method='POST', request_body=ProductStorageSerializer,
operation_description="生产任务中的生产入库")
@action(methods=['POST'], detail=False)
def product_storage(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
result = serializer.save()
return Response({'msg': 'ok'})

@ -50,6 +50,9 @@ class PurchaseStorageModel(BaseModel):
is_other = models.CharField('是否是其他入库,0:采购入库,1:其他入库', max_length=1, default='0')
product_task = models.ForeignKey('production_info.ProductTaskModel', null=True, blank=True,
on_delete=models.SET_NULL,
verbose_name='所属的生产任务')
class Meta:
db_table = 't_purchase_storage'
verbose_name = '入库单表'

@ -152,7 +152,7 @@ USE_TZ = False
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

@ -9,12 +9,15 @@ 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/
"""
import sys
import os
import datetime
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
@ -23,10 +26,9 @@ BASE_DIR = Path(__file__).resolve().parent.parent
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 = []
# DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
@ -37,9 +39,23 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'erp_system',
'basic_info',
'goods_info',
'purchase_info',
'warehouse_info',
'financial_info',
'sale_info',
'production_info',
# 'django.contrib.staticfiles', # required for serving swagger ui's css/js files
'drf_yasg',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@ -48,6 +64,12 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_WHITELIST = (
'http://127.0.0.1:8080',
'http://localhost:8080',
)
CORS_ALLOW_CREDENTIALS = True
ROOT_URLCONF = 'ERP_5.urls'
@ -70,17 +92,30 @@ TEMPLATES = [
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',
'ENGINE': 'django.db.backends.mysql',
'NAME': 'erp_5',
'USER': 'laoxiao',
'PASSWORD': '123456',
'HOST': '192.168.23.1',
'PORT': '3306',
}
}
# 配置Redis数据库
CACHES = {
"default": { # 默认
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.23.1:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
@ -100,27 +135,151 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# 配置抽取静态文件之后,存放的目录
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), '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'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': { #
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(filename)s: %(lineno)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
},
},
'filters': { #
'require_debug_true': { #
'()': 'django.utils.log.RequireDebugTrue',
},
},
'handlers': { #
'console': { #
'level': 'INFO',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'my_con': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'file': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'logs/mangguo.log'),
'maxBytes': 300 * 1024 * 1024,
'backupCount': 10,
'formatter': 'verbose'
},
},
'loggers': {
'my': {
# 'handlers': ['console', 'file'],
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'django.db.backends': {
# 'handlers': ['console', 'file'],
'handlers': ['my_con'],
'propagate': True,
'level': 'DEBUG',
},
}
}
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
'DEFAULT_PERMISSION_CLASSES':
(
# 'rest_framework.permissions.IsAuthenticated',
# 'ERP_5.utils.rbac_permissions.RbacPermission', # 自定义的权限验证
)
}
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
'JWT_RESPONSE_PAYLOAD_HANDLER': 'ERP_5.utils.jwt_handler.my_jwt_response_msg',
}
# 添加自定义用户模型类(应用名.模型类名)
AUTH_USER_MODEL = 'erp_system.UserModel'
# 指定自定义认证类路径
AUTHENTICATION_BACKENDS = ['erp_system.erp_auth.UserLoginAuth']
# SWAGGER 接口文档支持JWT的自动认证自动在请求头中加入token
SWAGGER_SETTINGS = {
# 'PERSIST_AUTH': True,
'REFETCH_SCHEMA_WITH_AUTH': True,
'REFETCH_SCHEMA_ON_LOGOUT': True,
'SECURITY_DEFINITIONS': {
'JWT': {
'type': 'apiKey',
'name': 'Authorization',
'in': 'header'
},
}
}
# celery
# Broker配置使用Redis作为消息中间件
CELERY_BROKER_URL = 'redis://127.0.0.1:6379/4'
# BACKEND配置这里使用redis
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/5'
# 结果序列化方案
CELERY_RESULT_SERIALIZER = 'json'
# 任务结果过期时间,秒
CELERY_TASK_RESULT_EXPIRES = 60 * 60 * 24
# 时区配置
CELERY_TIMEZONE = 'Asia/Shanghai'
BASE_API = 'api/' # 项目BASE API, 如设置时必须以/结尾
# 权限认证白名单
WHITE_LIST = [f'/{BASE_API}users/login/', f'/{BASE_API}users/register/', f'/docs/.*', f'/swagger/.*']
REGEX_URL = '^{url}$' # 权限匹配时,严格正则url
# 设置媒体路由地址信息
MEDIA_URL = '/media/'
# # 配置上传件存放的目录获取media文件夹的完整路径信息
MEDIA_ROOT = BASE_DIR / 'media'

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ERP_5.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ERP_5.settings.prod')
application = get_wsgi_application()

Loading…
Cancel
Save