diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index 5b55c6da..862e75d2 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -549,15 +549,16 @@ class processor_restock_diff_form(processor_text_json_diff_form):
{{ render_checkbox_field(form.follow_price_changes) }} - Changes in price should trigger a notification. + Changes in price should trigger a notification + When OFF - only care about restock detection
{{ render_field(form.price_change_min) }} - Minimum amount, when the price is below this amount, then a change is triggered. + Minimum amount, only trigger a change when the price is less than this amount.
{{ render_field(form.price_change_max) }} - Maximum amount, when the price is above this amount, then a change is triggered. + Maximum amount, only trigger a change when the price is more than this amount.
""" diff --git a/changedetectionio/processors/restock_diff.py b/changedetectionio/processors/restock_diff.py index ef9449cc..c55b3d51 100644 --- a/changedetectionio/processors/restock_diff.py +++ b/changedetectionio/processors/restock_diff.py @@ -164,30 +164,26 @@ class perform_site_check(difference_detection_processor): if watch.get('follow_price_changes') and watch.get('restock'): price = float(update_obj['restock'].get('price')) previous_price = float(watch['restock'].get('price')) + + # It was different, but negate it further down if price != previous_price: changed_detected = True - # Minimum price limit + # Minimum/maximum price limit if update_obj.get('restock') and update_obj['restock'].get('price') and watch.get('price_change_min'): logger.debug( - f"{uuid} - Change was detected, Has minimum price limit - 'price_change_min' is '{watch.get('price_change_min')}', price from website is '{update_obj['restock'].get('price', '')}'.") + f"{uuid} - Change was detected, Has minimum price limit - 'price_change_max' is '{watch.get('price_change_max', '')}' 'price_change_min' is '{watch.get('price_change_min', '')}', price from website is '{update_obj['restock'].get('price', '')}'.") if update_obj['restock'].get('price'): - min_limit = float(watch.get('price_change_min')) - price = float(update_obj['restock'].get('price')) - logger.debug(f"{uuid} after float conversion - Min limit: '{min_limit}' Price: '{price}'") - if price > min_limit: - changed_detected = False + min_limit = float(watch.get('price_change_min', 0)) + max_limit = float(watch.get('price_change_max', float('inf'))) # Set to infinity if not provided - # Maximum price limit - if update_obj.get('restock') and update_obj['restock'].get('price') and watch.get('price_change_max'): - logger.debug( - f"{uuid} - Change was detected, Has maximum price limit - 'price_change_max' is '{watch.get('price_change_max')}', price from website is '{update_obj['restock'].get('price', '')}'.") - if update_obj['restock'].get('price'): - max_limit = float(watch.get('price_change_max')) price = float(update_obj['restock'].get('price')) - logger.debug(f"{uuid} after float conversion - Max limit: '{max_limit}' Price: '{price}'") - if price < max_limit: - changed_detected = False + logger.debug(f"{uuid} after float conversion - Min limit: '{min_limit}' Max limit: '{max_limit}' Price: '{price}'") + if changed_detected: + if price < max_limit and price > min_limit: + changed_detected = False + + # Always record the new checksum diff --git a/changedetectionio/tests/test_restock_itemprop.py b/changedetectionio/tests/test_restock_itemprop.py index 690801b5..163df902 100644 --- a/changedetectionio/tests/test_restock_itemprop.py +++ b/changedetectionio/tests/test_restock_itemprop.py @@ -122,3 +122,55 @@ def test_itemprop_price_change(client, live_server): res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True) assert b'Deleted' in res.data + + +def test_itemprop_price_minmax_limit(client, live_server): + #live_server_setup(live_server) + + test_url = url_for('test_endpoint', _external=True) + + set_original_response(props_markup=instock_props[0], price="950.95") + client.post( + url_for("form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) + + # A change in price, should trigger a change by default + wait_for_all_checks(client) + + + res = client.post( + url_for("edit_page", uuid="first"), + data={"follow_price_changes": "y", + "price_change_min": 900.0, + "price_change_max": 1100.10, + "url": test_url, + "tags": "", + "headers": "", + 'fetch_backend': "html_requests" + }, + follow_redirects=True + ) + assert b"Updated watch." in res.data + wait_for_all_checks(client) + + client.get(url_for("mark_all_viewed")) + + # price changed to something greater than min (900), and less than max (1100).. should be no change + set_original_response(props_markup=instock_props[0], price='1000.45') + client.get(url_for("form_watch_checknow")) + wait_for_all_checks(client) + res = client.get(url_for("index")) + assert b'1000.45' in res.data + assert b'unviewed' not in res.data + + + # price changed to something LESS than min (900), SHOULD be a change + set_original_response(props_markup=instock_props[0], price='890.45') + res = client.get(url_for("form_watch_checknow"), follow_redirects=True) + assert b'1 watches queued for rechecking.' in res.data + wait_for_all_checks(client) + res = client.get(url_for("index")) + assert b'890.45' in res.data + assert b'unviewed' in res.data \ No newline at end of file