New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a407828329451172 calculation of client payments #61
Closed
Tuoris
wants to merge
11
commits into
openprocurement:npv_calculation
from
Tuoris:a407828329451172_calculate_payments
Closed
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b6ce3e
Add calculation of client payment
Tuoris 3fff14e
Add test for calculation of client payment
Tuoris d6e7dc4
Add calculation of client payments
Tuoris f1f716f
Add test for calculation of client payments
Tuoris 746f856
Fix PEP 8 minor error
Tuoris 2551fd7
Merge branch 'npv_calculation' into a407828329451172_calculate_payments
Tuoris d34b94d
Move test data to separate file
Tuoris 461669c
Replace lambda in calculate_payments
Tuoris b93c025
Change percent representation
Tuoris 6c1698f
Merge branch 'npv_calculation' into a407828329451172_calculate_payments
Tuoris 1eb261f
Simplify calculate_payments code
Tuoris File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
from datetime import date | ||
from openprocurement.tender.esco.tests.npv_test_data import DISCOUNT_COEF, DISCOUNT_RATE | ||
from openprocurement.tender.esco.tests.npv_test_data import ( | ||
DISCOUNT_COEF, | ||
DISCOUNT_RATE, | ||
CLIENT_PAYMENT_DATA, | ||
CLIENT_PAYMENTS_DATA, | ||
) | ||
from openprocurement.tender.esco.constants import DAYS_PER_YEAR, NPV_CALCULATION_DURATION | ||
from openprocurement.tender.esco.npv_calculation import ( | ||
calculate_contract_duration, | ||
calculate_discount_rate, | ||
calculate_discount_rates, | ||
calculate_payment, | ||
calculate_payments, | ||
calculate_discount_coef, | ||
calculate_days_with_cost_reduction, | ||
) | ||
|
@@ -120,6 +127,120 @@ def discount_rates(self): | |
self.assertEqual(calculated_rates[-1], predefined_rate2) | ||
|
||
|
||
def client_payment(self): | ||
|
||
# Predefined values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. винеси тестові дані в окремий файл |
||
yearly_payments_percentage = CLIENT_PAYMENT_DATA['yearly_percentage'] | ||
client_cost_reduction = CLIENT_PAYMENT_DATA['client_cost_reduction'] | ||
days_with_payments = CLIENT_PAYMENT_DATA['days_with_payments'] | ||
days_for_discount_rate = CLIENT_PAYMENT_DATA['days_for_discount_rate'] | ||
payment_predefined = CLIENT_PAYMENT_DATA['payment'] | ||
prec = 2 | ||
|
||
payment = calculate_payment( | ||
yearly_payments_percentage, | ||
client_cost_reduction, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
|
||
self.assertEqual(round(payment, prec), round(payment_predefined, prec)) | ||
self.assertEqual( | ||
round(yearly_payments_percentage * client_cost_reduction / 100, prec), | ||
round(payment_predefined, prec), | ||
) | ||
|
||
# No days for payments at all | ||
days_with_payments = 0 | ||
payment = calculate_payment( | ||
yearly_payments_percentage, | ||
client_cost_reduction, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertEqual(payment, 0) | ||
|
||
# If there is more days for payments than payment must be greater | ||
last_payment = payment | ||
days_with_payments += 1 | ||
payment = calculate_payment( | ||
yearly_payments_percentage, | ||
client_cost_reduction, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertGreater(payment, last_payment) | ||
|
||
# If there is less days for payments than payment must be smaller | ||
last_payment = payment | ||
days_with_payments -= 10 | ||
payment = calculate_payment( | ||
yearly_payments_percentage, | ||
client_cost_reduction, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertLess(payment, last_payment) | ||
|
||
|
||
def client_payments(self): | ||
|
||
periods = 21 | ||
|
||
# Predefined values | ||
yearly_payments_percentage = CLIENT_PAYMENTS_DATA['yearly_percentage'] | ||
client_cost_reductions = CLIENT_PAYMENTS_DATA['client_cost_reductions'] | ||
days_with_payments = CLIENT_PAYMENTS_DATA['days_with_payments'] | ||
days_for_discount_rate = CLIENT_PAYMENTS_DATA['days_for_discount_rate'] | ||
payments_predefined = CLIENT_PAYMENTS_DATA['payments'] | ||
payments_sum = CLIENT_PAYMENTS_DATA['payments_sum'] | ||
prec = 2 | ||
|
||
payments = calculate_payments( | ||
yearly_payments_percentage, | ||
client_cost_reductions, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertEqual(len(payments), len(client_cost_reductions)) | ||
for i, _ in enumerate(payments): | ||
self.assertEqual( | ||
round(payments[i], prec), | ||
round(payments_predefined[i], prec) | ||
) | ||
|
||
self.assertEqual(round(sum(payments), prec), round(payments_sum, prec)) | ||
|
||
# No days for payments at all | ||
days_with_payments = CLIENT_PAYMENTS_DATA['days_no_payments'] | ||
days_for_discount_rate = CLIENT_PAYMENTS_DATA['full_years_discount'] | ||
payments = calculate_payments( | ||
yearly_payments_percentage, | ||
client_cost_reductions, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertEqual(len(payments), len(client_cost_reductions)) | ||
for payment in payments: | ||
self.assertEqual(payment, 0) | ||
|
||
# If there is more days for payments than payment must be greater | ||
# days_with_payments = [10, 20, ...] | ||
days_with_payments = CLIENT_PAYMENTS_DATA['growing_days_with_payments'] | ||
payments = calculate_payments( | ||
yearly_payments_percentage, | ||
client_cost_reductions, | ||
days_with_payments, | ||
days_for_discount_rate, | ||
) | ||
self.assertEqual(len(payments), len(client_cost_reductions)) | ||
for i, _ in enumerate(payments[:-1]): | ||
self.assertLess( | ||
payments[i], | ||
payments[i + 1], | ||
) | ||
|
||
|
||
def days_with_cost_reduction(self): | ||
announcement_date = date(2017, 8, 18) | ||
self.assertEqual( | ||
|
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 |
---|---|---|
|
@@ -28,3 +28,24 @@ | |
'second_test': [Fraction(str(0))]*21, | ||
'third_test': [Fraction(str(0.12500))] * 21 | ||
} | ||
|
||
CLIENT_PAYMENT_DATA = { | ||
'yearly_percentage': 70, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. подавай відсоток у вигляді 0.7, потрібно переробити під це логіку |
||
'client_cost_reduction': 92.47, | ||
'days_with_payments': 135, | ||
'days_for_discount_rate': 135, | ||
'payment': 64.73, | ||
} | ||
|
||
CLIENT_PAYMENTS_DATA = { | ||
'yearly_percentage': 70.0, | ||
'client_cost_reductions': [92.47] + [250.00] * 20, | ||
'days_with_payments': [135, 365, 365, 230] + [0] * (21 - 4), | ||
'days_for_discount_rate': [135, 365, 365, 365] + [0] * (21 - 4), | ||
'payments': | ||
[64.73, 175.00, 175.00, 110.27] + [0] * (21 - 4), | ||
'payments_sum': 525.00, | ||
'days_no_payments': [0] * 21, | ||
'full_years_discount': [365] * 21, | ||
'growing_days_with_payments': [(i + 1) * 10 for i in range(21)], | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/openprocurement/openprocurement.tender.esco/pull/60/files#r133735992
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а може ще якось і без зіпу?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ні)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
та ні, зроби таки без використання зіпу.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/2/library/functions.html#zip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed