Last active
June 7, 2022 12:11
-
-
Save winzard/299f77d171d443c4c9c201b94060c42a to your computer and use it in GitHub Desktop.
Revisions
-
winzard revised this gist
Jun 7, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ @classmethod def get_quantity_by_catalog_item(cls, catalog_item_id: str) -> dict: event_repo = cls.event_repo() query = {'catalog_item': catalog_item_id} -
winzard renamed this gist
Jun 7, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
winzard created this gist
Jun 7, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ @classmethod def get_quantity_by_catalog_item(cls, catalog_item_id: str) -> dict: event_repo = cls.event_repo() query = {'catalog_item': catalog_item_id} events = event_repo.find(query) pivot = {} for event in events: company = event.internal_agent storage = event.location delta = event.quantity*event.direction if company not in pivot: pivot[company] = {} if storage not in pivot[company]: pivot[company][storage] = {'balance': Decimal(0), 'reserved': Decimal(0)} pivot[company][storage]['balance'] += delta reserved_commitments = CommitmentRepository().find( { 'reservation': True, 'catalog_item_id': catalog_item_id } ) for commitment in reserved_commitments: company = commitment.internal_agent storage = commitment.location delta = commitment.get_unfulfilled_quantity() if company not in pivot: pivot[company] = {} if storage not in pivot[company]: pivot[company][storage] = {'balance': Decimal(0), 'reserved': Decimal(0)} pivot[company][storage]['reserved'] += delta return pivot