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:
|
||||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue