公路基建物料供应链企业ERP采购管理平台代码设计
以下是一个公路基建物料供应链企业ERP系统中采购管理模块的代码框架示例。这个示例包含主要功能和结构,可根据实际需求进行扩展。
1. 数据库模型 (models.py)
from django.db import models from django.contrib.auth.models import User class Supplier(models.Model): name = models.CharField(max_length=100) contact_person = models.CharField(max_length=50) phone = models.CharField(max_length=20) email = models.EmailField() address = models.TextField() tax_id = models.CharField(max_length=30) rating = models.IntegerField(default=3) is_active = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)def __str__(self): return self.name class MaterialCategory(models.Model): name = models.CharField(max_length=50) description = models.TextField(blank=True) def __str__(self): return self.name class Material(models.Model): UNIT_CHOICES = [ ('ton', '吨'), ('m3', '立方米'), ('kg', '千克'), ('bag', '袋'), ] name = models.CharField(max_length=100) category = models.ForeignKey(MaterialCategory, on_delete=models.SET_NULL, null=True) specification = models.CharField(max_length=200) unit = models.CharField(max_length=10, choices=UNIT_CHOICES) standard_price = models.DecimalField(max_digits=10, decimal_places=2) min_stock = models.DecimalField(max_digits=10, decimal_places=2) current_stock = models.DecimalField(max_digits=10, decimal_places=2, default=0) supplier = models.ForeignKey(Supplier, on_delete=models.SET_NULL, null=True, blank=True) notes = models.TextField(blank=True) def __str__(self): return f"{self.name} ({self.specification})" class PurchaseRequisition(models.Model): STATUS_CHOICES = [ ('draft', '草稿'), ('pending', '待审批'), ('approved', '已批准'), ('rejected', '已拒绝'), ('ordered', '已下单'), ('completed', '已完成'), ('cancelled', '已取消'), ] requisition_number = models.CharField(max_length=20, unique=True) project = models.ForeignKey('project.Project', on_delete=models.CASCADE) requester = models.ForeignKey(User, on_delete=models.CASCADE, related_name='requisitions') status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='draft') total_amount = models.DecimalField(max_digits=12, decimal_places=2, default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) approved_at = models.DateTimeField(null=True, blank=True) approved_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name='approved_requisitions') notes = models.TextField(blank=True)