Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions openprocurement/auction/worker/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import datetime
from pytz import timezone
import wtforms_json

import decimal
from openprocurement.auction.utils import prepare_extra_journal_fields

wtforms_json.init()
Expand All @@ -34,8 +34,11 @@ def validate_bid_change_on_bidding(form, field):
raise ValidationError(u'Too high value')
else:
minimal_bid = form.document['stages'][stage_id]['amount']
if field.data > (minimal_bid - form.document['minimalStep']['amount']):
raise ValidationError(u'Too high value')
with decimal.localcontext() as ctx:
ctx.prec = 2
max_allowed_bid = decimal.Decimal(minimal_bid) - decimal.Decimal(form.document['minimalStep']['amount'])
if field.data is not None and decimal.Decimal(field.data).normalize() > max_allowed_bid:
raise ValidationError(u'Too high value')


def validate_bidder_id_on_bidding(form, field):
Expand Down
25 changes: 24 additions & 1 deletion openprocurement/auction/worker/tests/unit/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
test_auction_document
)
from openprocurement.auction.worker.forms import (
validate_bid_value, BidsForm, form_handler
validate_bid_value, BidsForm, form_handler, validate_bid_change_on_bidding
)
from copy import deepcopy


def test_validate_bid_value():
Expand All @@ -32,6 +33,28 @@ def test_validate_bid_value():
validate_bid_value(None, field)


def test_bid_change_float_precision_issue(auction):
"""
checks the fix of the issue CBD-1723
"""
form = BidsForm()
form.auction = auction
form.document = deepcopy(test_auction_document)
form.document['minimalStep']['amount'] = 72.03
form.document['stages'][-1]['amount'] = 14395.71

field = form.bid
field.data = 14323.68

try:
validate_bid_change_on_bidding(form, form.bid)
except ValidationError:
pytest.fail("Unexpected ValidationError: {} - {} = {}".format(
form.document['stages'][-1]['amount'],
form.document['minimalStep']['amount'],
field.data))


def test_bids_form(auction, features_auction):
form_errors = {
'bid': [u'Bid amount is required'],
Expand Down