Exemple #1
0
    def calculate_order_remain(orders: models.QuerySet) -> dict:
        from apps.order.utils import OrderUtils

        result = {}
        for order in orders:
            result[str(order.pk)] = {
                'uid': order.uid,
                'remain': OrderUtils.get_vnd_total_obj(order) - OrderUtils.get_deposit_amount(order),
            }
        return result
Exemple #2
0
    def test_normal_case(self):
        order = OrderUtils.seeding(1, True)
        OrderItemUtils.seeding(2, order=order)

        staff = StaffUtils.seeding(1, True)
        TransactionUtils.recharge(100000000, MoneyType.CASH, order.customer, staff)
        self.assertEqual(Transaction.objects.count(), 1)

        TransactionUtils.deposit(order, staff)
        transaction = Transaction.objects.first()

        self.assertEqual(Transaction.objects.count(), 2)
        self.assertEqual(transaction.order, order)
        self.assertEqual(transaction.staff, staff)
        self.assertEqual(transaction.customer, order.customer)
        self.assertEqual(transaction.amount, OrderUtils.get_deposit_amount(order))
        self.assertEqual(transaction.type, Type.DEPOSIT)
Exemple #3
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()