Exemple #1
0
    def deposit(order: models.QuerySet, staff: models.QuerySet):
        from .models import Type, MoneyType
        from .models import Transaction
        from apps.order.utils import OrderUtils

        TransactionUtils.undeposit(order)

        amount = OrderUtils.get_deposit_amount(order)
        can_deposit = OrderUtils.can_deposit(order)
        if not can_deposit:
            raise ValidationError("Đơn hàng {} không đủ tiền đặt cọc.".format(
                order.uid))

        transaction = Transaction(order=order,
                                  customer=order.customer,
                                  staff=staff,
                                  amount=amount,
                                  type=Type.DEPOSIT,
                                  money_type=MoneyType.INDIRECT,
                                  note="Đặt cọc đơn {}".format(order.uid))
        order.deposit = amount
        order.save()
        transaction.save()
Exemple #2
0
 def undeposit(order: models.QuerySet):
     from .models import Type
     for transaction in order.order_transactions.filter(type=Type.DEPOSIT):
         transaction.delete()
     order.deposit = 0
     order.save()