From 65bef026075252d2f404574d19915396a196dc19 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sat, 13 Sep 2014 11:55:45 +0530 Subject: [PATCH 1/2] Fixes in address template --- .../doctype/address_template/address_template.py | 14 +++++++------- .../address_template/test_address_template.py | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/erpnext/utilities/doctype/address_template/address_template.py b/erpnext/utilities/doctype/address_template/address_template.py index 4ac80540dd..c8d34709fe 100644 --- a/erpnext/utilities/doctype/address_template/address_template.py +++ b/erpnext/utilities/doctype/address_template/address_template.py @@ -8,16 +8,16 @@ from frappe import _ class AddressTemplate(Document): def validate(self): - defaults = frappe.db.get_values("Address Template", - {"is_default":1, "name":("!=", self.name)}) + self.defaults = frappe.db.get_values("Address Template", {"is_default":1, "name":("!=", self.name)}) if not self.is_default: - if not defaults: + if not self.defaults: self.is_default = 1 frappe.msgprint(_("Setting this Address Template as default as there is no other default")) - else: - if defaults: - for d in defaults: - frappe.db.set_value("Address Template", d[0], "is_default", 0) + + def on_update(self): + if self.is_default and self.defaults: + for d in self.defaults: + frappe.db.set_value("Address Template", d[0], "is_default", 0) def on_trash(self): if self.is_default: diff --git a/erpnext/utilities/doctype/address_template/test_address_template.py b/erpnext/utilities/doctype/address_template/test_address_template.py index 953c852d85..d4e3de0623 100644 --- a/erpnext/utilities/doctype/address_template/test_address_template.py +++ b/erpnext/utilities/doctype/address_template/test_address_template.py @@ -20,3 +20,8 @@ class TestAddressTemplate(unittest.TestCase): b.save() self.assertEqual(frappe.db.get_value("Address Template", "India", "is_default"), 0) + + def tearDown(self): + a = frappe.get_doc("Address Template", "India") + a.is_default = 1 + a.save() From 01d171756be8463bfb54189d8ce2cc772839a7ea Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 15 Sep 2014 12:50:37 +0530 Subject: [PATCH 2/2] [fix] before_recurring, set due_date, ageing_date as None, fixed account due date validation --- erpnext/accounts/doctype/account/account.py | 6 ++---- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 ++++++ erpnext/controllers/recurring_document.py | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index e067c70bf0..7195db8a94 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -169,15 +169,13 @@ class Account(Document): def validate_due_date(self, posting_date, due_date): credit_days = (self.credit_days or frappe.db.get_value("Company", self.company, "credit_days")) - if credit_days is None: - return - posting_date, due_date = getdate(posting_date), getdate(due_date) diff = (due_date - posting_date).days if diff < 0: frappe.throw(_("Due Date cannot be before Posting Date")) - elif diff > credit_days: + + elif credit_days is not None and diff > credit_days: is_credit_controller = frappe.db.get_value("Accounts Settings", None, "credit_controller") in frappe.user.get_roles() diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index a20d906b8c..d4e09ecae7 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -71,7 +71,9 @@ class SalesInvoice(SellingController): self.is_opening = 'No' self.set_aging_date() + frappe.get_doc("Account", self.debit_to).validate_due_date(self.posting_date, self.due_date) + self.set_against_income_account() self.validate_c_form() self.validate_time_logs_are_submitted() @@ -147,6 +149,10 @@ class SalesInvoice(SellingController): validate_recurring_document(self) convert_to_recurring(self, "RECINV.#####", self.posting_date) + def before_recurring(self): + self.aging_date = None + self.due_date = None + def get_portal_page(self): return "invoice" if self.docstatus==1 else None diff --git a/erpnext/controllers/recurring_document.py b/erpnext/controllers/recurring_document.py index c7163ae3f8..bdf8b2918a 100644 --- a/erpnext/controllers/recurring_document.py +++ b/erpnext/controllers/recurring_document.py @@ -36,6 +36,9 @@ def manage_recurring_documents(doctype, next_date=None, commit=True): % (doctype, date_field, '%s', '%s'), (next_date, recurring_id)): try: ref_wrapper = frappe.get_doc(doctype, ref_document) + if hasattr(ref_wrapper, "before_recurring"): + ref_wrapper.before_recurring() + new_document_wrapper = make_new_document(ref_wrapper, date_field, next_date) send_notification(new_document_wrapper) if commit: