Skip to content

RTO and insurance changes move extra discount, not the customer price - #299

Merged
writerish07-pixel merged 2 commits into
mainfrom
cursor/rto-insurance-extra-discount-996c
Nov 21, 2026
Merged

writerish07-pixel merged 2 commits into
mainfrom
cursor/rto-insurance-extra-discount-996c

Conversation

@writerish07-pixel

@writerish07-pixel writerish07-pixel commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

The confirmed rule is unchanged. When extra discount is ₹4,500 against list RTO ₹5,500 and insurance ₹19,000, changing those to ₹2,200 and ₹18,000 cuts extra discount by the same ₹4,300, to ₹200. Customer payable stays.

A full pass of the price, scheme, and pack paths found three places that did not follow that rule:

  • On a multi-unit file, an agreed unit price that sat above the new on-road cost was treated as the pack total and thrown away. The old extra discount stayed and the customer price fell. A real pack total (another vehicle) is still rejected, including an order total copied onto the expensive unit when it also covers the cheaper vehicle.
  • Editing RTO or insurance on a named pack unit did not write that unit, so its extra discount never moved.
  • After a price save, the scheme form could keep the old extra discount and, on the next scheme save, put that discount back and move the customer price.

When the charge cut is larger than the extra discount, the gap stays extra income from the customer. On a pack that amount is summed once into dealer margin, so Dealer Earnings includes it.

Live check

Logged into the CRM as owner and edited a Turbo Max file that started at extra discount ₹4,500, RTO ₹5,500, insurance ₹19,000, payable ₹8,05,000.

  • After RTO ₹2,200 and insurance ₹18,000, Additional (Dealer) showed ₹200 and Customer Payable stayed ₹8,05,000. Saving wrote those figures.
  • The scheme tab then showed Additional (Dealer) 200, with payable still ₹8,05,000.
  • On a two-unit file, the same change on unit 2 set that unit's additional to ₹200 and left unit 1 at ₹4,500. Pack payable stayed ₹16,10,000.

Tests

tests/test_deal_pass_meet_cx.py covers the ₹4,500 → ₹200 case on one vehicle and on pack unit 2, including the owner-field edit, and the case where the charge cut is larger than the discount (additional becomes ₹0, payable stays, and the ₹10,000 gap is in dealer margin). The scheme form test checks that Additional follows the saved price. A pack refresh test keeps a copied order total of ₹17,70,000 from being treated as the expensive unit's price.

Open in Web Open in Cursor 

Devin Review

A lower RTO or insurance reduces Additional (Dealer) by the same rupees. An agreed pack-unit price above the new on-road cost stays the deal, a named pack unit accepts the real charges, and the scheme form follows the reduced discount.

Co-authored-by: writerish07-pixel <writerish07-pixel@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9fa98787-b24d-4834-b365-e02b6978de05
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T07:38:42.071647Z f191963 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
euler-crm c976735 Nov 21 2026, 07:42 AM

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread backend/commercial.py
Comment on lines +172 to +174
ex = round2(num(snap.get("exShowroom") or unit.get("exShowroom")))
if ex > 0:
return cx > ex * 1.5 + DEAL_AMOUNT_EQUAL_RUPEES

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Legacy pack totals double-count cheaper vehicles

On older packs with the order total copied to unit 1, pack_unit_cx_is_pack_rollup accepts totals below the new cutoff. Recompute then adds the sibling prices again, inflating the customer’s balance.

Learn more

Older pack price hydration could copy the lead’s commercial fields onto the first unit. The existing legacy data regression test covers a copied order total, but its total is far above the new cutoff. Price Structure runs recompute after an edit. Unit payable refresh keeps the copied Cx Demand as the first unit’s price when the cutoff misses it. Pack recompute then persists the inflated sum as payable and uses it for outstanding.

Example: A Storm with ₹12,00,000 ex-showroom has an agreed price of ₹11,80,000. A sibling costs ₹5,90,000. If unit 1 still carries the copied ₹17,70,000 pack total, the new ₹18,00,001 cutoff accepts it, and a price save writes ₹23,60,000 instead of ₹17,70,000.

Recommended fix: Distinguish explicit per-unit agreements from legacy copied totals using their source, with pack context available during reconciliation. Cover both a mixed-price pack with a copied total below the cutoff and a genuine unit agreement that exceeds GVC after a charge cut.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread backend/commercial.py
Comment on lines +172 to +174
ex = round2(num(snap.get("exShowroom") or unit.get("exShowroom")))
if ex > 0:
return cx > ex * 1.5 + DEAL_AMOUNT_EQUAL_RUPEES

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Missing extra income on pack sales

When an RTO or insurance cut exhausts the discount, pack_unit_cx_is_pack_rollup now preserves the higher agreed price. Recompute adds the difference to dealer margin only for single vehicles. Dealer Earnings omits the pack’s extra income.

Learn more

An owner can lower RTO and insurance through Price Structure. When the agreed price remains above the revised charges, unit payable refresh keeps the agreed price and records the positive gap as extra customer income. Lead recompute only derives that income directly for single vehicles, and its lead-level margin and earnings use that single-vehicle result. The Dealer Earnings register uses the persisted lead margin, so saving or reloading the report does not recover the omitted amount.

Example: A pack unit stays at ₹8,05,000 after its gross cost falls to ₹7,95,000 and the discount reaches zero. The unit records ₹10,000 in extra customer income, but none of that ₹10,000 reaches Dealer Earnings.

Recommended fix: Roll up extra customer income from the freshly computed pack units and include it exactly once in persisted margin and total earnings. Extend the large-cut regression to assert the lead-level margin and the earnings register contribution.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f191963b4d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/commercial.py
unit = unit or {}
ex = round2(num(snap.get("exShowroom") or unit.get("exShowroom")))
if ex > 0:
return cx > ex * 1.5 + DEAL_AMOUNT_EQUAL_RUPEES

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep low-ratio pack totals from locking as unit prices

For a mixed-SKU pack whose first unit costs much more than another vehicle, the pack total can be below 1.5× the first unit’s ex-showroom (for example, a Storm LR200 plus a HiRange SR). This returns false for a legacy pack roll-up copied onto unit 1, so _refresh_unit_payables treats the whole pack total as unit 1’s deal and then adds unit 2’s payable, overstating the customer balance and potentially blocking delivery.

Useful? React with 👍 / 👎.

A charge cut that exhausts Additional leaves the gap on each pack unit and in dealer margin. An order total copied onto the expensive unit is still dropped when it also covers the cheaper vehicle.

Co-authored-by: writerish07-pixel <writerish07-pixel@users.noreply.github.com>
@writerish07-pixel
writerish07-pixel merged commit 429cb50 into main Nov 21, 2026
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants