Skip to content

Incorrect Due Date validation due to type mismatch in workflow submission (version-15) #54502

@Dev1-digitalistech

Description

@Dev1-digitalistech

Information about bug

In ERPNext version-15, there is a bug in due date validation inside:

erpnext/accounts/party.py

Function:
validate_due_date_with_template()

The issue occurs due to inconsistent data types between posting_date and default_due_date, especially when a document is submitted via Workflow.

Steps to Reproduce

  1. Enable a Workflow on Purchase Invoice
  2. Create a Purchase Invoice from UI
  3. Set:
    • Posting Date = 2026-04-23
    • Bill Date = 2026-04-22
    • Due Date = 2026-04-23 (same as expected default)
  4. Submit using Workflow action (e.g., Approve)

Actual Behavior

Validation incorrectly triggers:

"default_due_date != posting_date"

Even when both dates are logically the same.

Expected Behavior

Validation should not trigger when posting_date and default_due_date are equal.

Module

accounts

Version

Frappe Framework: v15.102.1 (HEAD)
ERPNext: v15.101.0 (HEAD)

Installation method

FrappeCloud

Relevant log output / Stack trace / Full Error Message.

🔍 Root Cause
Type mismatch during comparison:

default_due_date = '2026-04-23'  (string)
posting_date = datetime.date(2026, 4, 23)  (date object)

Comparison:
'2026-04-23' != datetime.date(2026, 4, 23) → True (incorrect logically)

This happens specifically in workflow submission because:
- frappe.get_doc + load_from_db() converts fields into Python date objects
- while get_due_date_from_template() returns string
💡 Suggested Fix
Normalize all date values using getdate() before comparison.

Example fix:

default_due_date = getdate(get_due_date_from_template(template_name, posting_date, bill_date))
posting_date = getdate(posting_date)
due_date = getdate(due_date)

if default_due_date != posting_date and due_date > default_due_date:
    ...




📌 Additional Context
This issue only appears in workflow-based submission.
Normal save/submit flow may not trigger this due to different data handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions