Back to Feed
article 2m read

Credit report claimed the shopper's whole discount whenever it got stuck

When my vendor-credit report couldn't compute what a supplier owed on a promotion, it fell back to the shopper's full shelf discount. Now it derives the rate from the register's own amounts, applies it to cost, and writes zero with a needs-review label when it has no basis.

Article DepthPractice

Flow

What each kind of row should produce

  1. 1Discount and pre-discount amount, both valid

    Divide them for the rate, then claim rate times cost times quantity.

  2. 2Only a stated percent

    Use it on cost the same way.

  3. 3Bare number in the promotion name

    Not a rate. Claim zero and send the row to review.

  4. 4No rate, no mapping or no cost

    Claim zero, mark for review, keep the shopper's discount beside it.

  5. 5Blocked product, credit report opted in

    Counted only with a real cost and a positive credit.

The vendor-credit report had a bad fallback. When it couldn't work out what a supplier owed after a promotion, it used what the shopper saved as the claim.

Keep the two amounts apart

The shopper's discount comes off the shelf price. The supplier's share should come off your cost. With a made-up line of ten dollars, two off and five of cost, the claim is one dollar, not two. Store both in separate fields, and keep money in whole cents.

My fallback fired when there was no rate, no mapped product, no cost, or a promotion named with a bare number. A test even expected the inflated number for that last case. The row was labeled as a fallback, but it sat in the same field as real claims, so the totals couldn't tell.

Find the rate, then stop guessing

If the source sends the discount and the line amount before it, divide them. Accept the result only when both are positive and the discount isn't bigger than the line. Don't read bare numbers out of promotion names.

When there's no rate or no cost, set the claim to zero, mark the row for review, and keep the shopper's discount next to it. Check every place that has its own default for the label. My single-event view had one that needed changing.

Watch the order of your checks

My first version put the new math below an early return, so the records that needed it never got there. A follow-up moved it to the top. Then the test needed a tolerance, because 1.2 over 6, divided as plain dollar floats, comes out a hair under one fifth.

The rate is the ratio of the two amounts, falling back to the stated rate only if the ratio isn't available.

That order means a computed rate beats a stated one on the same record. I have no test for when the two disagree, and that's the next one to write.

Blocked products need their own door

A product blocked from ordering can still have sales that earned a credit. Leave the shared ordering check alone. Give the credit report an explicit opt-in, and count a blocked product only with a real cost and a positive credit. In my report, only the two credit screens pass that option.

Keep reading

Pick up a connected idea or branch into a nearby one.

5 paths forward