Skip to content

feat: show applied Promotional Scheme as a Link on Sales Invoice item#322

Open
engahmed1190 wants to merge 11 commits into
uatfrom
feat/applied-pricing-rule-name-on-invoice-item
Open

feat: show applied Promotional Scheme as a Link on Sales Invoice item#322
engahmed1190 wants to merge 11 commits into
uatfrom
feat/applied-pricing-rule-name-on-invoice-item

Conversation

@engahmed1190

Copy link
Copy Markdown
Contributor

What & why

POS Next computes promotional offers itself and, in update_invoice, clears item.pricing_rules before save (to stop ERPNext zeroing the discount on the 2nd save). As a result a saved POS Sales Invoice keeps no record of which Pricing Rule / Promotional Scheme produced a line's discount — staff can't tell from the invoice which promotion applied.

This adds a read-only, clickable Link on each Sales Invoice item line pointing to the Promotional Scheme that discounted it.

How

  • New custom field pos_applied_promotional_scheme (Link → Promotional Scheme, read-only, visible, printable when populated) on Sales Invoice Item, via custom/sales_invoice_item.json (synced by bench migrate).
  • In update_invoice: capture each line's applied Pricing Rule names before item.pricing_rules is cleared, then after the loop resolve each rule to its parent promotional_scheme and stamp the Link. The resolution is folded into the existing one-time-offer block under a single if doctype == "Sales Invoice": guard, using one Pricing Rule query that feeds both the scheme Link and the pos_applied_one_time_rules stamp.
  • Standalone Pricing Rules (no scheme) and undiscounted lines leave the field blank. Stamping is guarded so it can never fail the sale.

Notes / constraints

  • New invoices only — historical invoices can't be backfilled (the rule name was discarded at save time).
  • Sales Invoice only — the clearing logic that motivates this lives in the SI save path; Sales Order is unaffected.
  • No frontend (Vue) change, no discount-math change; the existing one-time-offer logic is preserved.
  • Promotional Scheme has no title column in this ERPNext version (its name is the title), so the Link renders the scheme name directly.

Testing

  • Added test_applied_promotional_scheme_stamped to pos_next/test_promotions.py: drives a real scheme through the full apply_offers → update_invoice → submit_invoice pipeline and asserts the discounted line links to the scheme, the undiscounted line is blank, and pricing_rules stays cleared.
  • Full suite green on nexus.local: 19/19 (bench --site nexus.local run-tests --module pos_next.test_promotions).

Design docs

  • docs/superpowers/specs/2026-06-17-applied-pricing-rule-name-on-invoice-item-design.md
  • docs/superpowers/plans/2026-06-17-applied-pricing-rule-name-on-invoice-item.md

🤖 Generated with Claude Code

engahmed1190 and others added 11 commits June 17, 2026 12:06
Show the Promotional Scheme / Pricing Rule name on each Sales Invoice item
line (POS Next clears item.pricing_rules at save, so no rule name survives
today). Per-item read-only field, formatted as '<Scheme Title> (<RULE-ID>)'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Field becomes a read-only Link (Promotional Scheme) instead of Small Text;
drop the text-label helper (Link renders the scheme natively). Resolve each
applied Pricing Rule to its parent promotional_scheme in one query. Promotional
Scheme has no title column in this ERPNext version (name is the title).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…Item

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Avoid two consecutive identical 'if doctype == "Sales Invoice":' blocks by
nesting the scheme-stamp logic with the existing one-time-offer block under a
single guard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merge the two Pricing Rule lookups (scheme resolution + one-time flag) into one
get_all over applied_rule_names_seen; derive both the per-line scheme Link and
the invoice-level one-time stamp from it. Drop the now-redundant getattr guard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant