Esempio n. 1
0
 def update_orders(self):
     from core.services.payutc import PayutcClient
     p = PayutcClient()
     p.login_admin()
     rep = p.get_sales(product_id__in=[self.article.id_payutc])
     for line in rep['transactions']:
         if line['status'] == 'V':
             orderline, created = OrderLine.objects.get_or_create(id_transaction_payutc=line['id'],
                                                                  defaults={"menu": self})
             if created:
                 for payments in line['rows']:
                     orderline.id_rows_payutc = payments['id']
                     for menu in payments['payments']:
                         orderline.id_buyer = menu['buyer']['id']
                         orderline.quantity = menu['quantity']
                         orderline.buyer_first_name = menu['buyer']['first_name']
                         orderline.buyer_name = menu['buyer']['last_name']
                         orderline.save()
         for line1 in line['rows']:
             if line1['cancels']:
                 o = OrderLine.objects.filter(id_rows_payutc=line1['cancels']).first()
                 if o:
                     o.is_canceled = True
                     o.save()
     buyers_list = list()
     orders = OrderLine.objects.filter(menu_id=self.id, quantity__gt=0, is_canceled=False).order_by('served',
                                                                                                    'is_staff',
                                                                                                    'id_transaction_payutc')
     for order in orders:
         buyers_list.append(
             {'last_name': order.buyer_name, 'first_name': order.buyer_first_name, 'quantity': order.quantity,
              'served': order.served, 'is_staff': order.is_staff, 'id_transaction': order.id_transaction_payutc})
     return buyers_list
Esempio n. 2
0
def get_beers_sells(request):
    """
	Obtention des ventes dans la journée courante des ids mis en paramètres
	Méthode utilisée publique, utilisée pour le duel des brasseurs en A19 
	"""
    beers = request.data['beers']
    response = dict()

    current_date = (datetime.now()).strftime('%Y-%m-%d')
    start_date = current_date + "T00:00:01.000Z"
    end_date = current_date + "T23:59:59.000Z"

    p = PayutcClient()
    p.login_admin()

    duels = beers.keys()
    for duel in duels:
        response[duel] = dict()
        duel_beers = beers[duel].keys()
        for beer in duel_beers:
            beer_id = beers[duel][beer]['id']
            nb_sells = p.get_nb_sell(obj_id=beer_id,
                                     start=start_date,
                                     end=end_date)
            response[duel][beer] = dict()
            response[duel][beer]['id'] = beers[duel][beer]['id']
            response[duel][beer]['quantity'] = nb_sells

    return JsonResponse({'beers': response}, status=200)
Esempio n. 3
0
def user_autocomplete(request, query, format=None):
    """Authenticate with badge_id"""

    data = {'queryString': query}
    sessionid = request.session['payutc_session']
    p = PayutcClient()
    p.login_admin()
    return JsonResponse({'users': p.auto_complete(data)})
Esempio n. 4
0
 def set_article_disabled(self):
     from core.services.payutc import PayutcClient
     p = PayutcClient()
     p.login_admin()
     rep = p.patch_api_rest('resources',
                            'products',
                            self.id_payutc,
                            active=False)
     return rep
Esempio n. 5
0
 def update_sales(self):
     from core.services.payutc import PayutcClient
     p = PayutcClient()
     p.login_admin()
     rep = p.get_nb_sell(obj_id=self.id_payutc)
     self.ventes = rep
     self.ventes_last_update = timezone.now()
     self.save()
     return self.ventes
Esempio n. 6
0
def user_autocomplete(request, query, format=None):
    """
	Récupération à parti d'une query string des utilisateurs
	sur Payutc pouvant être susceptible de ressembler à la query
	"""

    data = {'queryString': query}
    sessionid = request.session['payutc_session']
    p = PayutcClient()
    p.login_admin()
    return JsonResponse({'users': p.auto_complete(data)})
Esempio n. 7
0
    def create(self, request):
        """Méthode pour générer 20 vainqueurs des goodies parmis les non-membres du Pic"""

        # Récupération des ventes entre une date de début et une date de fin
        # START doit être au format "AAAA-MM-JJ"
        # END doit être au format "AAAA-MM-JJ"
        # ROW_COUNT représente le nombre maximum de ventes récupérées
        sessionid = request.session['payutc_session']
        p = PayutcClient()
        p.login_admin()
        start = request.data['start_date'] + "T00:00:01.000Z"
        end = request.data['end_date'] + "T23:00:00.000Z"
        ROW_COUNT = 20000
        sales = p.get_sales(start=start, end=end,
                            row_count=ROW_COUNT)['transactions']

        # Recherche des membres dans le Pic actuel
        pic_members = []
        queryset = core_models.UserRight.objects.filter(
            Q(right='A') | Q(right='M'))
        serializer = core_serializers.UserRightSerializer(queryset, many=True)
        # Récupération des logins des membres du Pic pour les supprimer par la suite de la génération
        for i, user in enumerate(serializer.data):
            login = serializer.data[i]['login']
            pic_members.append(login)

        # Récupération aléatoire d'utilisateurs
        goodies_winners = []
        nb_sales = len(sales)
        while (len(goodies_winners) < 20):
            # Tant qqu'on a pas 20 vainqueurs on itère
            random_value = random.randint(1, nb_sales)
            user = sales[int(random_value) -
                         1]['rows'][0]['payments'][0]['buyer']
            user_description = user["first_name"] + " " + user["last_name"]
            # Si l'utilisateur n'est pas un membre du Pic ou un login déjà dans la liste des vainqueurs, ajout
            if (user["username"] not in pic_members
                    and user_description not in goodies_winners):
                goodies_winners.append(user_description)
                payutc_models.GoodiesWinner.objects.create(
                    winner=user_description, picked_up=False)

        # Renvoi des données
        queryset = payutc_models.GoodiesWinner.objects.all()
        serializer = payutc_serializers.GoodiesWinnerSerializer(queryset,
                                                                many=True)
        return JsonResponse({'winners': serializer.data})
Esempio n. 8
0
 def create_payutc_article(self):
     if self.id_payutc:
         return self.id_payutc
     from core.services.payutc import PayutcClient
     p = PayutcClient()
     p.login_admin()
     data = {
         'active': True,
         'alcool': False,
         'cotisant': True,
         'name': self.nom + ' - ' + self.creneau.perm.nom,
         'parent': PAYUTC_ARTICLES_CATEGORY,
         'prix': int(self.prix * 100),
         'stock': self.stock,
         'tva': self.tva,
         'variable_price': False
     }
     res = p.set_product(data)
     self.id_payutc = int(res['success'])
     self.ventes_last_update = timezone.now()
     self.save()
     Menu.objects.create(article=self)
     return self.id_payutc
Esempio n. 9
0
 def make_shotgun(self, request, max):
     p = PayutcClient()
     p.login_admin()
     data_temp = request.data.copy()
     liste = p.auto_complete({'queryString': request.data['login']})
     if len(liste) == 1:
         data_temp['email'] = liste[0]['email']
         nbListe = shotgun_models.Creneau.objects.select_related(
             'user').filter(userinshotgun__id_creneau=request.
                            data['id_creneau']).count()
         if nbListe < max:
             serializer = self.get_serializer(data=data_temp)
             serializer.is_valid(raise_exception=True)
             self.perform_create(serializer)
             headers = self.get_success_headers(serializer.data)
             return Response({"Success": "shotgun réalisé"},
                             status=200,
                             headers=headers)
         else:
             return Response({"Fail": "maximim de personnes déjà atteint"},
                             status=429)
     else:
         return Response({"Fail": "votre login est invalide"}, status=422)