-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Admin): Besoins : répare le filtre par montant exact (#1112)
- Loading branch information
Showing
4 changed files
with
55 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from lemarche.tenders import constants as tender_constants | ||
|
||
|
||
def find_amount_ranges(amount, operation): | ||
""" | ||
Returns the keys from AMOUNT_RANGE that match a given operation on a specified amount. | ||
:param amount: The amount to compare against. | ||
:param operation: The operation to perform ('lt', 'lte', 'gt', 'gte'). | ||
:return: A list of matching keys. | ||
""" | ||
amount = int(amount) | ||
if operation == "lt": | ||
if amount < tender_constants.AMOUNT_RANGE_CHOICE_EXACT.get(tender_constants.AMOUNT_RANGE_0_1): | ||
return [tender_constants.AMOUNT_RANGE_0_1] | ||
return [key for key, value in tender_constants.AMOUNT_RANGE_CHOICE_EXACT.items() if value < amount] | ||
elif operation == "lte": | ||
if amount <= tender_constants.AMOUNT_RANGE_CHOICE_EXACT.get(tender_constants.AMOUNT_RANGE_0_1): | ||
return [tender_constants.AMOUNT_RANGE_0_1] | ||
return [key for key, value in tender_constants.AMOUNT_RANGE_CHOICE_EXACT.items() if value <= amount] | ||
elif operation == "gt": | ||
if amount >= tender_constants.AMOUNT_RANGE_CHOICE_EXACT.get(tender_constants.AMOUNT_RANGE_1000_MORE): | ||
return [tender_constants.AMOUNT_RANGE_1000_MORE] | ||
return [key for key, value in tender_constants.AMOUNT_RANGE_CHOICE_EXACT.items() if value > amount] | ||
elif operation == "gte": | ||
if amount >= tender_constants.AMOUNT_RANGE_CHOICE_EXACT.get(tender_constants.AMOUNT_RANGE_1000_MORE): | ||
return [tender_constants.AMOUNT_RANGE_1000_MORE] | ||
return [key for key, value in tender_constants.AMOUNT_RANGE_CHOICE_EXACT.items() if value >= amount] | ||
else: | ||
raise ValueError("Unrecognized operation. Use 'lt', 'lte', 'gt', or 'gte'.") |