Fix "margin threshold" bug in pricing batch logic
also make sure to flush session once every 200 new rows when populating
This commit is contained in:
parent
2773663d70
commit
af340c79f7
|
@ -41,17 +41,23 @@ class PricingBatchHandler(BatchHandler):
|
|||
"""
|
||||
batch_model_class = model.PricingBatch
|
||||
|
||||
# cached decimal object used for rounding percentages, below
|
||||
percent_decimal = decimal.Decimal('.001')
|
||||
|
||||
def populate(self, batch, progress=None):
|
||||
"""
|
||||
Batch row data comes from product query.
|
||||
"""
|
||||
assert batch.products
|
||||
session = orm.object_session(batch)
|
||||
|
||||
def append(item, i):
|
||||
row = model.PricingBatchRow()
|
||||
row.product = item
|
||||
row.upc = row.product.upc
|
||||
self.add_row(batch, row)
|
||||
if i % 200 == 0:
|
||||
session.flush()
|
||||
|
||||
self.progress_loop(append, batch.products, progress,
|
||||
message="Adding initial rows to batch")
|
||||
|
@ -81,9 +87,6 @@ class PricingBatchHandler(BatchHandler):
|
|||
regprice = product.regular_price
|
||||
row.old_price = regprice.price if regprice else None
|
||||
|
||||
# cached decimal object used for rounding percentages, below
|
||||
percent_decimal = decimal.Decimal('.001')
|
||||
|
||||
def set_status_per_diff(self, row):
|
||||
"""
|
||||
Set the row's status code according to its price diff
|
||||
|
@ -94,7 +97,8 @@ class PricingBatchHandler(BatchHandler):
|
|||
# force rounding of row's % diff, for comparison to threshold
|
||||
# (this is just to avoid unexpected surprises for the user)
|
||||
# (ideally we'd just flush() the session but this seems safer)
|
||||
row.price_diff_percent = row.price_diff_percent.quantize(percent_decimal)
|
||||
if isinstance(row.price_diff_percent, decimal.Decimal):
|
||||
row.price_diff_percent = row.price_diff_percent.quantize(self.percent_decimal)
|
||||
# TODO: why don't we use price_diff_percent here again?
|
||||
minor = abs(row.margin_diff) < threshold
|
||||
|
||||
|
|
Loading…
Reference in a new issue