Skip to content

Commit

Permalink
Additional sanity checking on prices
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 6, 2014
1 parent 12d4658 commit e74bc8c
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions commands/update_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def validateRow(self, row):


def validate(self, widget):
""" For checking the contents of a widget. TBD """
""" For checking the contents of a widget. """
item, row, pos = widget.item, widget.row, widget.pos

value = widget.val.get()
Expand Down Expand Up @@ -248,13 +248,47 @@ def validate(self, widget):
asking = int(row[1][1].get())

if asking < paying:
widget.bell()
mbox.showerror(
"I DOUBT THAT!",
"Stations never pay more for an item than "
"they sell it for."
"they sell it for.",
)
return False

# https://forums.frontier.co.uk/showthread.php?t=34986&p=1162429&viewfull=1#post1162429
# It seems that stations usually pay within 25% of the
# asking price as a buy-back price. If the user gives
# us something out of those bounds, check with them.
if paying < asking * 0.75 or \
paying < asking - 127:
widget.bell()
ok = mbox.askokcancel(
"Are you sure about that?",
"You've indicated that the station is:\n"
" PAYING: {:>10n}cr\n"
" ASKING: {:>10n}cr\n"
"for {}.\n"
"\n"
"This is outside of expected tolerances, "
"please check the numbers.\n"
"\n"
"If the numbers are correct, click OK and "
"please post a screenshot of the market UI "
"to the TD thread "
"(http://kfs.org/td/thread)."
.format(
paying, asking,
widget.item.name
),
default=mbox.CANCEL,
parent=widget,
)
if not ok:
widget.val.set("")
widget.focus_set()
return False

return True

if pos == 3:
Expand Down

0 comments on commit e74bc8c

Please sign in to comment.