models.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from django.db import models
  2. from bound.models import BoundBatchModel
  3. # Create your models here.
  4. # 主表:托盘数据
  5. class ContainerListModel(models.Model):
  6. CONTAINER_STATUS = (
  7. (0, '空置'),
  8. (1, '入库中'),
  9. (2, '在库'),
  10. (3, '出库中'),
  11. (4, '已出库')
  12. )
  13. container_code = models.IntegerField( verbose_name='托盘编号')
  14. current_location = models.CharField(max_length=50, verbose_name='当前库位', default='N/A')
  15. target_location = models.CharField(max_length=50, verbose_name='目标库位', default='N/A')
  16. status = models.IntegerField(choices=CONTAINER_STATUS, default=0, verbose_name='托盘状态')
  17. last_operation = models.DateTimeField(auto_now=True, verbose_name='最后操作时间')
  18. class Meta:
  19. db_table = 'container_list'
  20. verbose_name = 'ContainerList'
  21. verbose_name_plural = "ContainerList"
  22. ordering = ['-container_code']
  23. # 明细表:托盘详细数据记录当前组盘的 批次 数量 使用托盘码和状态来获取、托盘上的物料信息,
  24. class ContainerDetailModel(models.Model):
  25. month = models.IntegerField(verbose_name='月份')
  26. container = models.ForeignKey(ContainerListModel, on_delete=models.CASCADE, related_name='details')
  27. batch = models.ForeignKey(BoundBatchModel, on_delete=models.CASCADE, verbose_name='批次')
  28. goods_code = models.CharField(max_length=50, verbose_name='货品编码')
  29. goods_desc = models.CharField(max_length=100, verbose_name='货品描述')
  30. goods_qty = models.IntegerField(verbose_name='数量')
  31. goods_weight = models.DecimalField(max_digits=10, decimal_places=3, verbose_name='重量')
  32. status = models.IntegerField(default=1, verbose_name='状态') # 0: 未使用 1: 使用中 2: 已出库
  33. creater = models.CharField(max_length=50, verbose_name='创建人')
  34. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  35. update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
  36. class Meta:
  37. db_table = 'container_detail'
  38. verbose_name = 'ContainerDetail'
  39. verbose_name_plural = "ContainerDetail"
  40. ordering = ['-id']
  41. # 明细表:操作记录 记录每次出入库的记录,使用goods来进行盘点,使用托盘码来进行托盘的操作记录
  42. class ContainerOperationModel(models.Model):
  43. OPERATION_TYPES = (
  44. ('inbound', '入库'),
  45. ('outbound', '出库'),
  46. )
  47. month = models.IntegerField(verbose_name='月份')
  48. container = models.ForeignKey(ContainerListModel, on_delete=models.CASCADE, related_name='operations')
  49. operation_type = models.CharField(max_length=20, choices=OPERATION_TYPES, verbose_name='操作类型')
  50. batch = models.ForeignKey(BoundBatchModel, on_delete=models.CASCADE, verbose_name='批次')
  51. goods_code = models.CharField(max_length=50, verbose_name='货品编码')
  52. goods_desc = models.CharField(max_length=100, verbose_name='货品描述')
  53. goods_qty = models.IntegerField(verbose_name='数量')
  54. goods_weight = models.DecimalField(max_digits=10, decimal_places=3, verbose_name='重量')
  55. operator = models.CharField(max_length=50, verbose_name='操作人')
  56. timestamp = models.DateTimeField(auto_now_add=True, verbose_name='操作时间')
  57. from_location = models.CharField(max_length=50, null=True, verbose_name='原库位')
  58. to_location = models.CharField(max_length=50, null=True, verbose_name='目标库位')
  59. memo = models.TextField(null=True, verbose_name='备注')
  60. class Meta:
  61. db_table = 'container_operation'
  62. verbose_name = 'ContainerOperation'
  63. verbose_name_plural = "ContainerOperation"
  64. ordering = ['-timestamp']
  65. class ContainerWCSModel(models.Model):
  66. taskid = models.CharField(max_length=50, verbose_name='任务ID')
  67. month = models.IntegerField(verbose_name='月份')
  68. tasktype = models.CharField(max_length=50, verbose_name='任务类型')
  69. container = models.CharField(max_length=50, verbose_name='托盘号')
  70. current_location = models.CharField(max_length=50, verbose_name='当前库位')
  71. target_location = models.CharField(max_length=50, verbose_name='目标库位')
  72. message = models.TextField(verbose_name='消息')
  73. status = models.IntegerField(verbose_name='状态')
  74. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  75. is_delete = models.BooleanField(default=False, verbose_name='是否删除')
  76. class Meta:
  77. db_table = 'container_wcs'
  78. verbose_name = 'ContainerWCS'
  79. verbose_name_plural = "ContainerWCS"
  80. ordering = ['-create_time']
  81. def to_dict(self):
  82. return {
  83. 'container': self.container,
  84. 'current_location': self.current_location,
  85. 'month' : self.month,
  86. 'target_location': self.target_location,
  87. 'tasktype': self.tasktype,
  88. 'taskid': self.taskid,
  89. 'message': self.message,
  90. 'container': self.container,
  91. 'status': self.status
  92. }