From acc876e0d7b444a857b6618f8759394fb7d0e5b1 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 4 Oct 2013 13:33:24 +0530 Subject: [PATCH] [minor] [fix] status updater, only change communication status when called explicitly --- controllers/status_updater.py | 16 ++++++++++------ patches/october_2013/p03_crm_update_status.py | 18 +++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/controllers/status_updater.py b/controllers/status_updater.py index e457fa957ef..b2a0e17a258 100644 --- a/controllers/status_updater.py +++ b/controllers/status_updater.py @@ -88,17 +88,21 @@ class StatusUpdater(DocListController): webnotes.conn.set_value(self.doc.doctype, self.doc.name, "status", self.doc.status) def on_communication(self): + self.communication_set = True self.set_status(update=True) + del self.communication_set def communication_received(self): - last_comm = self.doclist.get({"doctype":"Communication"}) - if last_comm: - return last_comm[-1].sent_or_received == "Received" + if getattr(self, "communication_set", False): + last_comm = self.doclist.get({"doctype":"Communication"}) + if last_comm: + return last_comm[-1].sent_or_received == "Received" def communication_sent(self): - last_comm = self.doclist.get({"doctype":"Communication"}) - if last_comm: - return last_comm[-1].sent_or_received == "Sent" + if getattr(self, "communication_set", False): + last_comm = self.doclist.get({"doctype":"Communication"}) + if last_comm: + return last_comm[-1].sent_or_received == "Sent" def validate_qty(self): """ diff --git a/patches/october_2013/p03_crm_update_status.py b/patches/october_2013/p03_crm_update_status.py index 73ed1b1c78c..07a70c642a9 100644 --- a/patches/october_2013/p03_crm_update_status.py +++ b/patches/october_2013/p03_crm_update_status.py @@ -36,12 +36,12 @@ def execute(): webnotes.conn.sql("""update `tab%s` set status=%s where status=%s""" % \ (dt, "%s", "%s"), (status[1], status[0])) - # for dt in ["Lead", "Opportunity"]: - # for name in webnotes.conn.sql_list("""select name from `tab%s`""" % dt): - # bean = webnotes.bean(dt, name) - # before_status = bean.doc.status - # bean.get_controller().set_status() - # - # if bean.doc.status != before_status: - # webnotes.conn.sql("""update `tab%s` set status=%s where name=%s""" % (dt, "%s", "%s"), - # (bean.doc.status, name)) + for dt in ["Lead", "Opportunity"]: + for name in webnotes.conn.sql_list("""select name from `tab%s`""" % dt): + bean = webnotes.bean(dt, name) + before_status = bean.doc.status + bean.get_controller().set_status() + + if bean.doc.status != before_status: + webnotes.conn.sql("""update `tab%s` set status=%s where name=%s""" % (dt, "%s", "%s"), + (bean.doc.status, name))