models.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from django.db import models
  2. from decimal import Decimal
  3. class flowModel(models.Model):
  4. document_date = models.DateField(verbose_name='Document Date', null=True, blank=True)
  5. document_number = models.CharField(max_length=20, verbose_name='Document Number', null=True, blank=True)
  6. document_type = models.CharField(max_length=20, verbose_name='Document Type', null=True, blank=True)
  7. business_type = models.CharField(max_length=20, verbose_name='Business Type', null=True, blank=True)
  8. iout_type = models.CharField(max_length=255, verbose_name='IOUT Type', null=True, blank=True)
  9. department = models.CharField(max_length=255, verbose_name='Department', null=True, blank=True)
  10. warehouse_code = models.CharField(max_length=20, verbose_name='Warehouse Code', null=True, blank=True)
  11. warehouse_name = models.CharField(max_length=255, verbose_name='Warehouse Name', null=True, blank=True)
  12. goods_code = models.CharField(max_length=255, verbose_name='Goods Code', null=True, blank=True)
  13. goods_desc = models.CharField(max_length=255, verbose_name='Goods Description', null=True, blank=True)
  14. goods_std = models.CharField(max_length=255, verbose_name='Goods Standard', null=True, blank=True)
  15. goods_batch = models.CharField(max_length=255, verbose_name='Goods Batch', null=True, blank=True)
  16. in_batch = models.CharField(max_length=255, verbose_name='In Batch', null=True, blank=True)
  17. out_batch = models.CharField(max_length=255, verbose_name='Out Batch', null=True, blank=True)
  18. goods_unit = models.CharField(max_length=255,default = '件', verbose_name="Goods Unit", null=True, blank=True)
  19. goods_in = models.DecimalField(max_digits=10, decimal_places=3, default=Decimal('0'), verbose_name="Goods In",null=True, blank=True)
  20. goods_out = models.DecimalField(max_digits=10, decimal_places=3, default=Decimal('0'), verbose_name="Goods Out",null=True, blank=True)
  21. goods_notes = models.CharField(max_length=255,default = '待填写', verbose_name="Goods Notes",null=True, blank=True)
  22. creator = models.CharField(max_length=255, verbose_name='Creator', null=True, blank=True)
  23. class Meta:
  24. db_table = 'flowlist'
  25. verbose_name = 'Flow List'
  26. verbose_name_plural = "Flow List"
  27. ordering = ['id']
  28. constraints = [
  29. models.UniqueConstraint(
  30. fields=[
  31. 'document_date', 'document_number', 'document_type',
  32. 'business_type', 'iout_type', 'department', 'warehouse_code',
  33. 'warehouse_name', 'goods_code', 'goods_desc', 'goods_std',
  34. 'goods_batch', 'in_batch', 'out_batch', 'goods_in', 'goods_out',
  35. 'goods_notes', 'creator'
  36. ],
  37. name='unique_all_fields'
  38. )
  39. ]
  40. class GoodsSummaryModel(models.Model):
  41. """货品变动汇总模型(按goods_code聚合)"""
  42. goods_code = models.CharField(max_length=50, verbose_name='货品编码', primary_key=True)
  43. goods_desc = models.CharField(max_length=100, verbose_name='货品描述')
  44. total_in = models.DecimalField(
  45. max_digits=15,
  46. decimal_places=3,
  47. default=Decimal('0'),
  48. verbose_name='总入库量'
  49. )
  50. total_out = models.DecimalField(
  51. max_digits=15,
  52. decimal_places=3,
  53. default=Decimal('0'),
  54. verbose_name='总出库量'
  55. )
  56. net_change = models.DecimalField(
  57. max_digits=15,
  58. decimal_places=3,
  59. default=Decimal('0'),
  60. verbose_name='净变化量'
  61. )
  62. last_updated = models.DateTimeField(auto_now=True, verbose_name='最后更新时间')
  63. class Meta:
  64. db_table = 'goods_summary'
  65. verbose_name = '货品汇总'
  66. verbose_name_plural = "货品汇总"
  67. def __str__(self):
  68. return f"{self.goods_code} | 入库:{self.total_in} 出库:{self.total_out}"