-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Information about bug
Summary
Pricing rules with expired validity dates continue to be applied to new sales invoices, even when the invoice posting date is after the
pricing rule's valid_upto date.
Steps to Reproduce
- Create a Pricing Rule (e.g., PRLE-0001 "All Customers this week 5%")
- Set valid_from: 2025-10-06
- Set valid_upto: 2025-10-13
- Apply to Item Group: "Demo Item Group"
- Discount: 5%
- Status: Active (disable = 0) - Create a Sales Invoice via POS on 2025-10-15 (after expiry date)
- Add items from "Demo Item Group" (e.g., Camera, Backpack)
- Complete the sale - Check the invoice items
Expected Behavior
The expired pricing rule (PRLE-0001) should NOT be applied to invoices created after 2025-10-13. Items should be priced without the 5%
discount.
Actual Behavior
The expired pricing rule IS applied to the invoice:
- Camera: ج.م 900.00 → ج.م 855.00 (5% discount applied)
- Backpack: ج.م 500.00 → ج.م 475.00 (5% discount applied)
- Invoice shows: discount_percentage = 5%, discount_amount = 45.00/25.00
Database Evidence
-- Pricing Rule Status
SELECT name, title, valid_from, valid_upto, disable
FROM tabPricing Rule
WHERE name = 'PRLE-0001';
-- Result:
-- PRLE-0001 | All Customers this week 5% | 2025-10-06 | 2025-10-13 | 0
-- Invoice created AFTER expiry
SELECT name, posting_date, creation
FROM tabSales Invoice
WHERE name = 'ACC-SINV-2025-00040';
-- Result:
-- ACC-SINV-2025-00040 | 2025-10-15 | 2025-10-15 22:24:51
-- Discount still applied
SELECT item_code, rate, price_list_rate, discount_percentage, discount_amount
FROM tabSales Invoice Item
WHERE parent = 'ACC-SINV-2025-00040';
-- Result:
-- SKU008 | 475.00 | 500.00 | 5.0 | 25.00
Root Cause
ERPNext Core Behavior: The apply_pricing_rule function in ERPNext's core (erpnext.accounts.doctype.pricing_rule.pricing_rule) does NOT
enforce valid_upto date validation when applying pricing rules during invoice creation.
Code Flow:
- Calling ERPNext erpnext_apply_pricing_rule
pricing_results = erpnext_apply_pricing_rule(pricing_args) or [] - The pricing_args includes the correct posting date:
"posting_date": invoice.get("posting_date") or nowdate(), # 2025-10-15 - ERPNext's pricing engine matches rules based on:
- Item/Item Group/Brand ✓
- Customer/Customer Group ✓
- Company ✓
- BUT ignores valid_upto validation ✗
Impact
- User Confusion: Customers receive unexpected discounts on expired promotions
- Revenue Loss: Business loses revenue from unintended discounts
- Inventory Issues: Expired promotional pricing affects profit margins
- UI Inconsistency: Expired rules don't appear in POS Next offers dialog (after my fixes), but are still applied by ERPNext core
Module
accounts, selling
Version
frappe 15.75.0 version-15
erpnext 15.72.2 version-15
Installation method
None