From cdd3763a8b8df186c947a9dc41004f38df7c5b52 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Tue, 24 Dec 2024 16:38:51 +0530 Subject: [PATCH 1/3] fix: clear payment schedule in purchase invoice for is_paid (cherry picked from commit e1fc239f3d6e737d1acf022db274fedf4a396af0) # Conflicts: # erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js # erpnext/controllers/accounts_controller.py --- .../doctype/purchase_invoice/purchase_invoice.js | 7 +++++++ erpnext/controllers/accounts_controller.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index dc879cfc1b4..ff82055d19b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -366,8 +366,15 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying. hide_fields(this.frm.doc); if(cint(this.frm.doc.is_paid)) { this.frm.set_value("allocate_advances_automatically", 0); +<<<<<<< HEAD if(!this.frm.doc.company) { this.frm.set_value("is_paid", 0) +======= + this.frm.set_value("payment_terms_template", ""); + this.frm.set_value("payment_schedule", []); + if (!this.frm.doc.company) { + this.frm.set_value("is_paid", 0); +>>>>>>> e1fc239f3d (fix: clear payment schedule in purchase invoice for is_paid) frappe.msgprint(__("Please specify Company to proceed")); } } diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 6a5914ddbe0..58e9b86e24b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -415,10 +415,14 @@ class AccountsController(TransactionBase): ) def validate_invoice_documents_schedule(self): - if self.is_return: + if ( + self.is_return + or (self.doctype == "Purchase Invoice" and self.is_paid) + or (self.doctype == "Sales Invoice" and self.is_pos) + or self.get("is_opening") == "Yes" + ): self.payment_terms_template = "" self.payment_schedule = [] - return self.validate_payment_schedule_dates() self.set_due_date() @@ -2177,9 +2181,6 @@ class AccountsController(TransactionBase): dates = [] li = [] - if self.doctype == "Sales Invoice" and self.is_pos: - return - for d in self.get("payment_schedule"): if self.doctype == "Sales Order" and getdate(d.due_date) < getdate(self.transaction_date): frappe.throw( @@ -2196,9 +2197,12 @@ class AccountsController(TransactionBase): frappe.throw(_("Rows with duplicate due dates in other rows were found: {0}").format(duplicates)) def validate_payment_schedule_amount(self): +<<<<<<< HEAD if self.doctype == "Sales Invoice" and self.is_pos: return +======= +>>>>>>> e1fc239f3d (fix: clear payment schedule in purchase invoice for is_paid) party_account_currency = self.get("party_account_currency") if not party_account_currency: party_type, party = self.get_party() From d5f30202b431621177fb3e671220c513fe5c59b4 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 27 Dec 2024 12:48:25 +0530 Subject: [PATCH 2/3] refactor: early return is always better validate_advance_entries() has a heavy IO bound operation. Early return on unwanted cases is always better. (cherry picked from commit 0589fa7f3efcc826d856be71c20c7ad684f1c822) # Conflicts: # erpnext/controllers/accounts_controller.py --- erpnext/controllers/accounts_controller.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 58e9b86e24b..27b656ef51e 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -424,6 +424,9 @@ class AccountsController(TransactionBase): self.payment_terms_template = "" self.payment_schedule = [] + if self.is_return: + return + self.validate_payment_schedule_dates() self.set_due_date() self.set_payment_schedule() @@ -2181,6 +2184,9 @@ class AccountsController(TransactionBase): dates = [] li = [] + if self.doctype == "Sales Invoice" and self.is_pos: + return + for d in self.get("payment_schedule"): if self.doctype == "Sales Order" and getdate(d.due_date) < getdate(self.transaction_date): frappe.throw( @@ -2197,12 +2203,18 @@ class AccountsController(TransactionBase): frappe.throw(_("Rows with duplicate due dates in other rows were found: {0}").format(duplicates)) def validate_payment_schedule_amount(self): +<<<<<<< HEAD <<<<<<< HEAD if self.doctype == "Sales Invoice" and self.is_pos: return ======= >>>>>>> e1fc239f3d (fix: clear payment schedule in purchase invoice for is_paid) +======= + if (self.doctype == "Sales Invoice" and self.is_pos) or self.get("is_opening") == "Yes": + return + +>>>>>>> 0589fa7f3e (refactor: early return is always better) party_account_currency = self.get("party_account_currency") if not party_account_currency: party_type, party = self.get_party() From ce7dc5ecb32f41c1d60716b96cba3b7ccd96dfa9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 27 Dec 2024 13:49:09 +0530 Subject: [PATCH 3/3] chore: resolve conflicts --- .../doctype/purchase_invoice/purchase_invoice.js | 9 ++------- erpnext/controllers/accounts_controller.py | 9 --------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index ff82055d19b..4a8c8ad82a7 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -366,15 +366,10 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying. hide_fields(this.frm.doc); if(cint(this.frm.doc.is_paid)) { this.frm.set_value("allocate_advances_automatically", 0); -<<<<<<< HEAD - if(!this.frm.doc.company) { - this.frm.set_value("is_paid", 0) -======= this.frm.set_value("payment_terms_template", ""); this.frm.set_value("payment_schedule", []); - if (!this.frm.doc.company) { - this.frm.set_value("is_paid", 0); ->>>>>>> e1fc239f3d (fix: clear payment schedule in purchase invoice for is_paid) + if(!this.frm.doc.company) { + this.frm.set_value("is_paid", 0) frappe.msgprint(__("Please specify Company to proceed")); } } diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 27b656ef51e..15748868510 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2203,18 +2203,9 @@ class AccountsController(TransactionBase): frappe.throw(_("Rows with duplicate due dates in other rows were found: {0}").format(duplicates)) def validate_payment_schedule_amount(self): -<<<<<<< HEAD -<<<<<<< HEAD - if self.doctype == "Sales Invoice" and self.is_pos: - return - -======= ->>>>>>> e1fc239f3d (fix: clear payment schedule in purchase invoice for is_paid) -======= if (self.doctype == "Sales Invoice" and self.is_pos) or self.get("is_opening") == "Yes": return ->>>>>>> 0589fa7f3e (refactor: early return is always better) party_account_currency = self.get("party_account_currency") if not party_account_currency: party_type, party = self.get_party()