diff --git a/kfet/management/commands/dumpstuff.py b/kfet/management/commands/dumpstuff.py index d13810e5..cee92a58 100644 --- a/kfet/management/commands/dumpstuff.py +++ b/kfet/management/commands/dumpstuff.py @@ -33,19 +33,28 @@ def dump_articles(filename: str) -> None: def dump_operations(filename: str, accounts_hashes: Dict[int, str]) -> None: - not_canceled_purchases = Operation.objects.filter(type=Operation.PURCHASE).filter( - canceled_at__isnull=True + not_canceled_purchases = ( + Operation.objects.filter(type=Operation.PURCHASE) + .filter(canceled_at__isnull=True) + .values_list( + "amount", + "article__id", + "article_nb", + "group__at", + "group__is_cof", + "group__on_acc__id", + ) ) operations = [ { - "amount": str(operation.amount), - "article": operation.article.id, - "number": operation.article_nb, - "date": str(operation.group.at), - "is_cof": operation.group.is_cof, - "on_account": accounts_hashes[operation.group.on_acc.id], + "amount": str(amount), + "article": article_id, + "number": nb, + "date": str(at), + "is_cof": is_cof, + "on_account": accounts_hashes[on_acc], } - for operation in not_canceled_purchases + for amount, article_id, nb, at, is_cof, on_acc in not_canceled_purchases ] with open(filename, "w") as file: json.dump(operations, file, indent=4)