Stack · Django

Why didn't the customer get the discount? Get the answer with the rule in the code.

Prices, discounts and rules often sit in a views.py or a service that only developers can read. Adea reads it and explains step by step what happened on a specific order.

Free, no sign-up. Prefer a guided tour? Book 20 minutes with us →

What an answer looks like

Why didn't order 10432 get the volume discount?

Adea
  • Finding order 10432
  • Reading shop/pricing.py
  • Matching the rule against the order lines

The order had 9 items, and the volume discount starts at 10. The discount also only applies to items in the Tools category, and 2 of the items were in Accessories.

Sourcesshop/pricing.py:112

The code Adea read · shop/pricing.py:112

def volume_discount(lines):
    eligible = [l for l in lines
                if l.product.category == 'tools']
    if sum(l.qty for l in eligible) >= 10:
        return Decimal('0.08')

The query Adea ran (read-only)

SELECT l.qty, c.name FROM shop_orderline l
JOIN shop_product p ON p.id = l.product_id
JOIN shop_category c ON c.id = p.category_id
WHERE l.order_id = 10432

Explains, not just counts

Adea shows the sequence: which lines counted, which rule was hit and why the threshold was not reached. Support can answer the customer right away.

Understands your ORM

Adea follows relations and managers in the Django models and finds the right tables, even when the names do not look like what you call things.

The rule can be corrected

If Adea has understood a rule wrongly, a developer corrects it. The fix applies to all future answers.

How to connect a Django app

Give read access to the repo and to a Postgres read-only user. Adea finds the models itself.

Read more about security →

CREATE ROLE adea_readonly LOGIN PASSWORD '…';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO adea_readonly;

Frequently asked questions

Does it work with Django REST framework and Celery?

Adea reads the code that decides the rules, whether it lives in views, serializers, services or tasks.

Can support see the customer's data?

Only the tables and columns you open for their role.

What about Django admin?

It is not required, but you can have Adea link to the record in admin in the answer.