Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto-update due date for invoices via data import (backport #40198) #40470

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,23 +603,31 @@ def disable_tax_included_prices_for_internal_transfer(self):
)

def validate_due_date(self):
if self.get("is_pos"):
if self.get("is_pos") or self.doctype not in ["Sales Invoice", "Purchase Invoice"]:
return

from erpnext.accounts.party import validate_due_date

if self.doctype == "Sales Invoice":
posting_date = (
self.posting_date if self.doctype == "Sales Invoice" else (self.bill_date or self.posting_date)
)

# skip due date validation for records via Data Import
if frappe.flags.in_import and getdate(self.due_date) < getdate(posting_date):
self.due_date = posting_date

elif self.doctype == "Sales Invoice":
if not self.due_date:
frappe.throw(_("Due Date is mandatory"))

validate_due_date(
self.posting_date,
posting_date,
self.due_date,
self.payment_terms_template,
)
elif self.doctype == "Purchase Invoice":
validate_due_date(
self.bill_date or self.posting_date,
posting_date,
self.due_date,
self.bill_date,
self.payment_terms_template,
Expand Down
Loading