Fix license sync
This commit is contained in:
parent
a481989348
commit
f62d2ad5ef
|
|
@ -164,11 +164,12 @@ class HepClient:
|
|||
if 'status' in order_item:
|
||||
status = order_item['status']
|
||||
|
||||
order_id = -1
|
||||
if 'order_id' in order_item:
|
||||
status = order_item['order_id']
|
||||
|
||||
for item in order_item['items']:
|
||||
|
||||
order_id = -1
|
||||
if 'order_id' in item:
|
||||
order_id = item['order_id']
|
||||
|
||||
if item['sku'] == settings.MYSKILLBOX_TEACHER_EDITION_ISBN or \
|
||||
item['sku'] == settings.MYSKILLBOX_STUDENT_EDITION_ISBN:
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,9 @@ import os
|
|||
import shutil
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
from django.core.management import BaseCommand
|
||||
from django.db import connection
|
||||
|
||||
from core import hep_client
|
||||
from core.hep_client import HepClient
|
||||
from core.models import AdminData
|
||||
from users.models import User, License
|
||||
|
||||
|
|
@ -32,11 +30,14 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
"Update licenses via cronjob"
|
||||
|
||||
hep_client = HepClient()
|
||||
|
||||
admin_token = AdminData.objects.get_admin_token()
|
||||
hep_users = User.objects.filter(hep_id__isnull=False)
|
||||
|
||||
for hep_user in hep_users:
|
||||
product = hep_client.myskillbox_product_for_customer(admin_token, hep_user.hep_id)
|
||||
if License.objects.filter(licensee=hep_users, order_id=product['order_id']).count() == 0:
|
||||
|
||||
if product and License.objects.filter(licensee=hep_user, order_id=product['order_id']).count() == 0:
|
||||
License.objects.create_license_for_role(hep_user, product['activated'], product['raw'],
|
||||
product['edition'], product['order_id'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue