Make dumpstuff more efficient
This commit is contained in:
parent
8baaa1d339
commit
23c1de0fc6
1 changed files with 18 additions and 9 deletions
|
@ -33,19 +33,28 @@ def dump_articles(filename: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def dump_operations(filename: str, accounts_hashes: Dict[int, str]) -> None:
|
def dump_operations(filename: str, accounts_hashes: Dict[int, str]) -> None:
|
||||||
not_canceled_purchases = Operation.objects.filter(type=Operation.PURCHASE).filter(
|
not_canceled_purchases = (
|
||||||
canceled_at__isnull=True
|
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 = [
|
operations = [
|
||||||
{
|
{
|
||||||
"amount": str(operation.amount),
|
"amount": str(amount),
|
||||||
"article": operation.article.id,
|
"article": article_id,
|
||||||
"number": operation.article_nb,
|
"number": nb,
|
||||||
"date": str(operation.group.at),
|
"date": str(at),
|
||||||
"is_cof": operation.group.is_cof,
|
"is_cof": is_cof,
|
||||||
"on_account": accounts_hashes[operation.group.on_acc.id],
|
"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:
|
with open(filename, "w") as file:
|
||||||
json.dump(operations, file, indent=4)
|
json.dump(operations, file, indent=4)
|
||||||
|
|
Loading…
Reference in a new issue