Add command to fix ibans
This commit is contained in:
parent
fbc441d1ea
commit
e74f224de4
|
|
@ -24,7 +24,7 @@ class Command(BaseCommand):
|
||||||
today = now().date()
|
today = now().date()
|
||||||
|
|
||||||
for license in License.objects.filter(expire_date__gte=today):
|
for license in License.objects.filter(expire_date__gte=today):
|
||||||
isbn = license.get_isbn()
|
isbn = license.get_hep_isbn()
|
||||||
if isbn not in YEARLY_ISBNS:
|
if isbn not in YEARLY_ISBNS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from users.models import License
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = """
|
||||||
|
Overwrites the License model's IBAN with the IBAN from the hep-JSON
|
||||||
|
"""
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument('--dry-run', action='store_true', dest='dry_run', default=False, help='Make dry-run')
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
|
||||||
|
for license in License.objects.all():
|
||||||
|
isbn = license.get_hep_isbn()
|
||||||
|
|
||||||
|
if isbn == license.isbn:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f'Setting ISBN for licenseID {license.id} from {license.isbn} to {isbn}')
|
||||||
|
|
||||||
|
if not options['dry_run']:
|
||||||
|
license.isbn = isbn
|
||||||
|
license.save()
|
||||||
|
|
@ -330,7 +330,7 @@ class License(models.Model):
|
||||||
|
|
||||||
return License.NO_DATE
|
return License.NO_DATE
|
||||||
|
|
||||||
def get_isbn(self) -> str:
|
def get_hep_isbn(self) -> str:
|
||||||
hep_data = self._read_as_json(self.raw)
|
hep_data = self._read_as_json(self.raw)
|
||||||
if 'sku' in hep_data: # Magento key
|
if 'sku' in hep_data: # Magento key
|
||||||
return hep_data['sku']
|
return hep_data['sku']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue