fix: auto-update due date for invoices via data import
This commit is contained in:
@@ -600,23 +600,32 @@ class AccountsController(TransactionBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def validate_due_date(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
|
return
|
||||||
|
|
||||||
from erpnext.accounts.party import validate_due_date
|
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)
|
||||||
|
)
|
||||||
|
via_data_import = (
|
||||||
|
self.flags.updater_reference and self.flags.updater_reference.get("doctype") == "Data Import"
|
||||||
|
)
|
||||||
|
if via_data_import and getdate(self.due_date) < getdate(posting_date):
|
||||||
|
self.due_date = posting_date
|
||||||
|
|
||||||
|
elif self.doctype == "Sales Invoice":
|
||||||
if not self.due_date:
|
if not self.due_date:
|
||||||
frappe.throw(_("Due Date is mandatory"))
|
frappe.throw(_("Due Date is mandatory"))
|
||||||
|
|
||||||
validate_due_date(
|
validate_due_date(
|
||||||
self.posting_date,
|
posting_date,
|
||||||
self.due_date,
|
self.due_date,
|
||||||
self.payment_terms_template,
|
self.payment_terms_template,
|
||||||
)
|
)
|
||||||
elif self.doctype == "Purchase Invoice":
|
elif self.doctype == "Purchase Invoice":
|
||||||
validate_due_date(
|
validate_due_date(
|
||||||
self.bill_date or self.posting_date,
|
posting_date,
|
||||||
self.due_date,
|
self.due_date,
|
||||||
self.bill_date,
|
self.bill_date,
|
||||||
self.payment_terms_template,
|
self.payment_terms_template,
|
||||||
|
|||||||
Reference in New Issue
Block a user