From 43870aa8dbf8e92c45a9269ddc9906210d4213eb Mon Sep 17 00:00:00 2001 From: tunde Date: Fri, 18 Aug 2017 11:59:30 +0100 Subject: [PATCH] moves `set_payment_schedule` and `validate_payment_schedule` to accounts_controller --- .../doctype/sales_invoice/sales_invoice.py | 27 ----------------- erpnext/controllers/accounts_controller.py | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 4fbfc95d0fd..bc3531778d1 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -99,8 +99,6 @@ class SalesInvoice(SellingController): self.set_billing_hours_and_amount() self.update_timesheet_billing_for_project() self.set_status() - self.set_payment_schedule() - self.validate_payment_schedule() def before_save(self): set_account_for_mode_of_payment(self) @@ -532,31 +530,6 @@ class SalesInvoice(SellingController): self.total_billing_amount = total_billing_amount - def set_payment_schedule(self): - if not self.get("payment_schedule"): - if self.due_date: - self.append("payment_schedule", { - "due_date": self.due_date, - "invoice_portion": 100, - "payment_amount": self.grand_total - }) - else: - self.due_date = max([d.due_date for d in self.get("payment_schedule")]) - - def validate_payment_schedule(self): - if self.due_date and getdate(self.due_date) < getdate(self.posting_date): - frappe.throw(_("Due Date cannot be before posting date")) - - total = 0 - for d in self.get("payment_schedule"): - if getdate(d.due_date) < getdate(self.posting_date): - frappe.throw(_("Row {0}: Due Date cannot be before posting date").format(d.idx)) - - total += flt(d.payment_amount) - - if total != self.grand_total: - frappe.throw(_("Total Payment Amount in Payment Schdule must be equal to Grand Total")) - def get_warehouse(self): user_pos_profile = frappe.db.sql("""select name, warehouse from `tabPOS Profile` where ifnull(user,'') = %s and company = %s""", (frappe.session['user'], self.company)) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 41f8dc5335d..bb634d1e0e1 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -44,6 +44,8 @@ class AccountsController(TransactionBase): self.set_total_in_words() if self.doctype in ("Sales Invoice", "Purchase Invoice") and not self.is_return: + self.set_payment_schedule() + self.validate_payment_schedule() self.validate_due_date() self.validate_advance_entries() @@ -614,6 +616,33 @@ class AccountsController(TransactionBase): for item in duplicate_list: self.remove(item) + def set_payment_schedule(self): + if not self.get("payment_schedule"): + if self.due_date: + self.append("payment_schedule", { + "due_date": self.due_date, + "invoice_portion": 100, + "payment_amount": self.grand_total + }) + else: + self.due_date = max([d.due_date for d in self.get("payment_schedule")]) + + def validate_payment_schedule(self): + if self.due_date and getdate(self.due_date) < getdate(self.posting_date): + frappe.throw(_("Due Date cannot be before posting date")) + + total = 0 + for d in self.get("payment_schedule"): + if getdate(d.due_date) < getdate(self.posting_date): + frappe.throw(_("Row {0}: Due Date cannot be before posting date").format(d.idx)) + + total += flt(d.payment_amount) + + if total != self.grand_total: + frappe.throw(_("Total Payment Amount in Payment Schdule must be equal to Grand Total")) + + + @frappe.whitelist() def get_tax_rate(account_head): return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)