Пример #1
0
 def renew_discard(self, request, pk=None):
     from apps.order.serializers import OrderBaseSr
     from apps.order.models import Status
     order = get_object_or_404(Order, pk=pk)
     if hasattr(request.user,
                'customer') and order.customer != request.user.customer:
         raise ValidationError(
             "Bạn không thể khởi tạo lại đơn hàng của người khác.")
     order = MoveStatusUtils.move(order, Status.NEW)
     return res(OrderBaseSr(order).data)
Пример #2
0
 def change_cust_care(self, request, pk=None):
     obj = get_object_or_404(Order, pk=pk)
     blank, staff = Tools.obj_from_pk(Staff,
                                      request.data.get('value', None))
     if not blank and not staff:
         # Staff not exist -> do nothing
         serializer = OrderBaseSr(obj)
     else:
         serializer = OrderUtils.partial_update(obj, 'cust_care', staff.pk)
     return res(serializer.data)
Пример #3
0
 def change_address(self, request, pk=None):
     obj = get_object_or_404(Order, pk=pk)
     blank, address = Tools.obj_from_pk(Address,
                                        request.data.get('value', None))
     if not blank and not address:
         # Address not exist -> do nothing
         serializer = OrderBaseSr(obj)
     else:
         serializer = OrderUtils.partial_update(obj, 'address', address.pk)
     return res(serializer.data)
Пример #4
0
 def retrieve(self, request, pk=None):
     order = get_object_or_404(Order, pk=pk)
     serializer = OrderBaseSr(order)
     data = serializer.data
     data['options'] = {
         'addresses':
         AddressBaseSr(
             Address.objects.filter(customer_id=order.customer_id),
             many=True).data
     }
     return res(data)
Пример #5
0
 def early_discard(self, request, pk=None):
     from apps.order.serializers import OrderBaseSr
     from apps.order.models import Status
     order = get_object_or_404(Order, pk=pk)
     staff = None
     if hasattr(request.user,
                'customer') and order.customer != request.user.customer:
         raise ValidationError("Bạn không thể huỷ đơn hàng của người khác.")
     if hasattr(request.user, 'staff'):
         staff = request.user.staff
     order = MoveStatusUtils.move(order, Status.DISCARD, staff=staff)
     return res(OrderBaseSr(order).data)
Пример #6
0
    def get_order_items_for_checking(self, request, uid=''):
        from apps.bol.models import Bol
        from apps.order_item.serializers import OrderItemBaseSr
        from apps.bol.serializers import BolBaseSr
        order_items = OrderUtils.get_items_for_checking(uid)
        order = order_items[0].order
        bols = Bol.objects.filter(order_id=order.pk)

        result = {
            'items': OrderItemBaseSr(order_items, many=True).data,
            'extra': {
                'order': OrderBaseSr(order).data,
                'bols': BolBaseSr(bols, many=True).data
            }
        }

        return NoPaginationStatic.get_paginated_response(result)
Пример #7
0
 def add(self, request):
     data, order_items = OrderUtils.prepare_data(request.data)
     order = OrderUtils.validate_create(data)
     OrderItemUtils.validate_bulk_create(order_items, order.id)
     return res(OrderBaseSr(order).data)