HimoolERP/apps/stock_transfer/models.py

57 lines
2.7 KiB
Python
Raw Normal View History

2021-11-04 23:49:56 +08:00
from extensions.models import *
2021-11-04 17:35:34 +08:00
2021-11-04 23:49:56 +08:00
2021-11-07 23:26:17 +08:00
class StockTransferOrder(Model):
2021-11-05 18:49:51 +08:00
"""调拨单据"""
2021-11-07 23:26:17 +08:00
number = CharField(max_length=32, verbose_name='编号')
2021-11-08 00:25:38 +08:00
transfer_out_warehouse = ForeignKey('data.Warehouse', on_delete=PROTECT,
related_name='out_stock_transfer_orders', verbose_name='出库仓库')
transfer_in_warehouse = ForeignKey('data.Warehouse', on_delete=PROTECT,
related_name='in_stock_transfer_orders', verbose_name='入库仓库')
2021-11-07 23:26:17 +08:00
handler = ForeignKey('system.User', on_delete=PROTECT, related_name='stock_transfer_orders', verbose_name='经手人')
handle_time = DateTimeField(verbose_name='处理时间')
remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
total_quantity = FloatField(verbose_name='调拨总数量')
is_void = BooleanField(default=False, verbose_name='作废状态')
creator = ForeignKey('system.User', on_delete=PROTECT,
related_name='created_stock_transfer_orders', verbose_name='创建人')
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='stock_transfer_orders')
2021-11-05 18:49:51 +08:00
2021-11-07 23:26:17 +08:00
class Meta:
unique_together = [('number', 'team')]
2021-11-12 15:37:43 +08:00
@classmethod
def get_number(cls, team):
2021-11-12 18:28:54 +08:00
start_date, end_date = get_today(), get_tomorrow()
2021-11-12 15:37:43 +08:00
instance = cls.objects.filter(team=team, create_time__gte=start_date, create_time__lt=end_date).last()
try:
result = re.match('^(.*?)([1-9]+)$', instance.number)
number = result.group(1) + str(int(result.group(2)) + 1)
except AttributeError:
2021-11-12 22:07:49 +08:00
number = 'DB' + pendulum.today(settings.TIME_ZONE).format('YYYYMMDD') + '0001'
2021-11-12 15:37:43 +08:00
return number
2021-11-07 23:26:17 +08:00
class StockTransferGoods(Model):
2021-11-05 18:49:51 +08:00
"""调拨商品"""
2021-11-07 23:26:17 +08:00
stock_transfer_order = ForeignKey('stock_transfer.StockTransferOrder', on_delete=CASCADE,
related_name='stock_transfer_goods_set', verbose_name='采购单据')
goods = ForeignKey('goods.Goods', on_delete=PROTECT, related_name='stock_transfer_goods_set', verbose_name='商品')
batch = ForeignKey('goods.Batch', on_delete=SET_NULL, null=True,
related_name='stock_transfer_goods_set', verbose_name='批次')
stock_transfer_quantity = FloatField(verbose_name='调拨数量')
is_void = BooleanField(default=False, verbose_name='作废状态')
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='stock_transfer_goods_set')
2021-11-05 18:49:51 +08:00
2021-11-07 23:26:17 +08:00
class Meta:
unique_together = [('stock_transfer_order', 'goods', 'batch')]
2021-11-04 23:49:56 +08:00
2021-11-07 23:26:17 +08:00
__all__ = [
'StockTransferOrder', 'StockTransferGoods',
2021-11-04 23:49:56 +08:00
]