2021-12-17 17:14:23 +08:00
|
|
|
from extensions.common.base import *
|
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-05 18:49:51 +08:00
|
|
|
class PurchaseOrder(Model):
|
|
|
|
"""采购单据"""
|
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
number = CharField(max_length=32, verbose_name='编号')
|
|
|
|
warehouse = ForeignKey('data.Warehouse', on_delete=PROTECT, related_name='purchase_orders', verbose_name='仓库')
|
|
|
|
supplier = ForeignKey('data.Supplier', on_delete=PROTECT, related_name='purchase_orders', verbose_name='供应商')
|
|
|
|
handler = ForeignKey('system.User', on_delete=PROTECT, related_name='purchase_orders', verbose_name='经手人')
|
|
|
|
handle_time = DateTimeField(verbose_name='处理时间')
|
|
|
|
remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
|
2021-11-12 01:03:17 +08:00
|
|
|
total_quantity = FloatField(null=True, verbose_name='采购总数量')
|
2021-11-11 23:58:18 +08:00
|
|
|
other_amount = AmountField(default=0, verbose_name='其他费用')
|
2021-11-12 01:03:17 +08:00
|
|
|
total_amount = AmountField(null=True, verbose_name='采购总金额')
|
2021-11-12 22:07:49 +08:00
|
|
|
payment_amount = AmountField(null=True, verbose_name='付款金额')
|
|
|
|
arrears_amount = AmountField(null=True, verbose_name='欠款金额')
|
2021-11-06 01:30:13 +08:00
|
|
|
is_void = BooleanField(default=False, verbose_name='作废状态')
|
2021-11-08 02:05:10 +08:00
|
|
|
enable_auto_stock_in = BooleanField(default=False, verbose_name='启用自动入库')
|
2021-11-06 01:30:13 +08:00
|
|
|
creator = ForeignKey('system.User', on_delete=PROTECT,
|
|
|
|
related_name='created_purchase_orders', verbose_name='创建人')
|
|
|
|
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_orders')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('number', 'team')]
|
|
|
|
|
2021-11-11 23:58:18 +08:00
|
|
|
@classmethod
|
|
|
|
def get_number(cls, team):
|
2021-12-17 17:14:23 +08:00
|
|
|
start_date, end_date = pendulum.today(), pendulum.tomorrow()
|
2021-11-12 01:03:17 +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-12-17 17:14:23 +08:00
|
|
|
number = 'CG' + pendulum.today().format('YYYYMMDD') + '0001'
|
2021-11-12 01:03:17 +08:00
|
|
|
|
|
|
|
return number
|
2021-11-11 23:58:18 +08:00
|
|
|
|
2021-11-05 18:49:51 +08:00
|
|
|
|
|
|
|
class PurchaseGoods(Model):
|
|
|
|
"""采购商品"""
|
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
purchase_order = ForeignKey('purchase.PurchaseOrder', on_delete=CASCADE,
|
|
|
|
related_name='purchase_goods_set', verbose_name='采购单据')
|
|
|
|
goods = ForeignKey('goods.Goods', on_delete=PROTECT, related_name='purchase_goods_set', verbose_name='商品')
|
|
|
|
purchase_quantity = FloatField(verbose_name='采购数量')
|
2021-12-17 17:14:23 +08:00
|
|
|
purchase_price = FloatField(verbose_name='采购单价')
|
2021-11-06 01:30:13 +08:00
|
|
|
total_amount = AmountField(verbose_name='总金额')
|
|
|
|
return_quantity = FloatField(default=0, verbose_name='退货数量')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_goods_set')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('purchase_order', 'goods')]
|
|
|
|
|
2021-11-05 18:49:51 +08:00
|
|
|
|
2021-11-14 15:23:15 +08:00
|
|
|
class PurchaseAccount(Model):
|
|
|
|
"""采购结算账户"""
|
|
|
|
|
|
|
|
purchase_order = ForeignKey('purchase.PurchaseOrder', on_delete=CASCADE,
|
|
|
|
related_name='purchase_accounts', verbose_name='采购单据')
|
|
|
|
account = ForeignKey('data.Account', on_delete=PROTECT, related_name='purchase_accounts', verbose_name='结算账户')
|
|
|
|
payment_amount = AmountField(verbose_name='付款金额')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_accounts')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('purchase_order', 'account')]
|
|
|
|
|
|
|
|
|
2021-11-05 18:49:51 +08:00
|
|
|
class PurchaseReturnOrder(Model):
|
|
|
|
"""采购退货单据"""
|
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
number = CharField(max_length=32, verbose_name='编号')
|
|
|
|
purchase_order = ForeignKey('purchase.PurchaseOrder', on_delete=CASCADE, null=True,
|
|
|
|
related_name='purchase_return_orders', verbose_name='采购单据')
|
|
|
|
warehouse = ForeignKey('data.Warehouse', on_delete=PROTECT, related_name='purchase_return_orders', verbose_name='仓库')
|
|
|
|
supplier = ForeignKey('data.Supplier', on_delete=PROTECT, related_name='purchase_return_orders', verbose_name='供应商')
|
|
|
|
handler = ForeignKey('system.User', on_delete=PROTECT, related_name='purchase_return_orders', verbose_name='经手人')
|
|
|
|
handle_time = DateTimeField(verbose_name='处理时间')
|
|
|
|
remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
|
2021-11-14 22:26:05 +08:00
|
|
|
total_quantity = FloatField(null=True, verbose_name='退货总数量')
|
2021-11-14 15:23:15 +08:00
|
|
|
other_amount = AmountField(default=0, verbose_name='其他费用')
|
2021-11-14 22:26:05 +08:00
|
|
|
total_amount = AmountField(null=True, verbose_name='退货总金额')
|
2021-11-14 15:23:15 +08:00
|
|
|
collection_amount = AmountField(null=True, verbose_name='收款金额')
|
|
|
|
arrears_amount = AmountField(null=True, verbose_name='欠款金额')
|
2021-11-06 01:30:13 +08:00
|
|
|
is_void = BooleanField(default=False, verbose_name='作废状态')
|
2021-11-14 15:23:15 +08:00
|
|
|
enable_auto_stock_out = BooleanField(default=False, verbose_name='启用自动出库')
|
2021-11-06 01:30:13 +08:00
|
|
|
creator = ForeignKey('system.User', on_delete=PROTECT,
|
|
|
|
related_name='created_purchase_return_orders', verbose_name='创建人')
|
|
|
|
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_return_orders')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('number', 'team')]
|
|
|
|
|
2021-11-12 15:37:43 +08:00
|
|
|
@classmethod
|
|
|
|
def get_number(cls, team):
|
2021-12-17 17:14:23 +08:00
|
|
|
start_date, end_date = pendulum.today(), pendulum.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-12-17 17:14:23 +08:00
|
|
|
number = 'CR' + pendulum.today().format('YYYYMMDD') + '0001'
|
2021-11-12 15:37:43 +08:00
|
|
|
|
|
|
|
return number
|
|
|
|
|
2021-11-05 18:49:51 +08:00
|
|
|
|
2021-11-13 02:34:05 +08:00
|
|
|
class PurchaseReturnGoods(Model):
|
2021-11-05 18:49:51 +08:00
|
|
|
"""采购退货商品"""
|
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
purchase_return_order = ForeignKey('purchase.PurchaseReturnOrder', on_delete=CASCADE,
|
2021-11-07 14:16:47 +08:00
|
|
|
related_name='purchase_return_goods_set', verbose_name='采购退货单据')
|
2021-11-14 15:23:15 +08:00
|
|
|
purchase_goods = ForeignKey('purchase.PurchaseGoods', on_delete=CASCADE, null=True,
|
|
|
|
related_name='purchase_return_goods_set', verbose_name='采购商品')
|
|
|
|
goods = ForeignKey('goods.Goods', on_delete=PROTECT,
|
|
|
|
related_name='purchase_return_goods_set', verbose_name='商品')
|
2021-11-06 01:30:13 +08:00
|
|
|
return_quantity = FloatField(verbose_name='退货数量')
|
2021-12-17 17:14:23 +08:00
|
|
|
return_price = FloatField(verbose_name='退货单价')
|
2021-11-06 01:30:13 +08:00
|
|
|
total_amount = AmountField(verbose_name='总金额')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_return_goods_set')
|
2021-11-05 18:49:51 +08:00
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
class Meta:
|
|
|
|
unique_together = [('purchase_return_order', 'goods')]
|
2021-11-04 23:49:56 +08:00
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
|
2021-11-14 15:23:15 +08:00
|
|
|
class PurchaseReturnAccount(Model):
|
|
|
|
"""采购退货结算账户"""
|
|
|
|
|
|
|
|
purchase_return_order = ForeignKey('purchase.PurchaseReturnOrder', on_delete=CASCADE,
|
|
|
|
related_name='purchase_return_accounts', verbose_name='采购退货单据')
|
|
|
|
account = ForeignKey('data.Account', on_delete=PROTECT, related_name='purchase_return_accounts', verbose_name='结算账户')
|
|
|
|
collection_amount = AmountField(verbose_name='收款金额')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='purchase_return_accounts')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('purchase_return_order', 'account')]
|
|
|
|
|
|
|
|
|
2021-11-06 01:30:13 +08:00
|
|
|
__all__ = [
|
2021-11-14 15:23:15 +08:00
|
|
|
'PurchaseOrder', 'PurchaseGoods', 'PurchaseAccount',
|
|
|
|
'PurchaseReturnOrder', 'PurchaseReturnGoods', 'PurchaseReturnAccount',
|
2021-11-04 23:49:56 +08:00
|
|
|
]
|