From 77e82f4a809c35957681cec8b27205a7b3caeb43 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Thu, 19 Jun 2025 13:15:36 +0530 Subject: [PATCH] fix: disallow posting date of purchase receipt and invoice before PO transaction date --- .../doctype/purchase_invoice/purchase_invoice.py | 1 + erpnext/controllers/buying_controller.py | 15 +++++++++++++++ .../doctype/purchase_receipt/purchase_receipt.py | 1 + 3 files changed, 17 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 76a124df3aa..9336279cfe0 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -259,6 +259,7 @@ class PurchaseInvoice(BuyingController): self.is_opening = "No" self.validate_posting_time() + self.validate_posting_date_with_po() super().validate() diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index e17e9678812..e4bd2536ec3 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -80,6 +80,21 @@ class BuyingController(SubcontractingController): ), ) + def validate_posting_date_with_po(self): + po_list = [] + for item in self.items: + if item.purchase_order and item.purchase_order not in po_list: + po_list.append(item.purchase_order) + + for po in po_list: + po_posting_date = frappe.get_value("Purchase Order", po, "transaction_date") + if getdate(po_posting_date) > getdate(self.posting_date): + frappe.throw( + _("Posting Date {0} cannot be before Purchase Order Posting Date {1}").format( + frappe.bold(self.posting_date), frappe.bold(po_posting_date) + ) + ) + def create_package_for_transfer(self) -> None: """Create serial and batch package for Sourece Warehouse in case of inter transfer.""" diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 99739867530..badb2beefb0 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -235,6 +235,7 @@ class PurchaseReceipt(BuyingController): def validate(self): self.validate_posting_time() + self.validate_posting_date_with_po() super().validate() if self._action != "submit":