Open lost opportunity again if quotation made against it (#8854)

This commit is contained in:
Nabin Hait 2017-05-17 19:41:39 +05:30 committed by GitHub
parent f69ffeb0b4
commit e4f80a6eaa
3 changed files with 20 additions and 7 deletions

View File

@ -19,7 +19,7 @@ status_map = {
["Converted", "has_customer"],
],
"Opportunity": [
["Quotation", "has_quotation"],
["Quotation", "has_active_quotation"],
["Converted", "has_ordered_quotation"],
["Lost", "eval:self.status=='Lost'"],
["Lost", "has_lost_quotation"],

View File

@ -84,20 +84,31 @@ class Opportunity(TransactionBase):
def on_trash(self):
self.delete_events()
def has_quotation(self):
return frappe.db.get_value("Quotation Item", {"prevdoc_docname": self.name, "docstatus": 1})
def has_active_quotation(self):
return frappe.db.sql("""
select q.name
from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s
and q.status not in ('Lost', 'Closed')""", self.name)
def has_ordered_quotation(self):
return frappe.db.sql("""select q.name from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s and q.status = 'Ordered'""", self.name)
return frappe.db.sql("""
select q.name
from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s
and q.status = 'Ordered'""", self.name)
def has_lost_quotation(self):
return frappe.db.sql("""
lost_quotation = frappe.db.sql("""
select q.name
from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1
and qi.prevdoc_docname =%s and q.status = 'Lost'
""", self.name)
if lost_quotation:
if self.has_active_quotation():
return False
return True
def validate_cust_name(self):
if self.customer:

View File

@ -44,7 +44,9 @@ class Quotation(SellingController):
def update_opportunity(self):
for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])):
if opportunity:
frappe.get_doc("Opportunity", opportunity).set_status(update=True)
opp = frappe.get_doc("Opportunity", opportunity)
opp.status = None
opp.set_status(update=True)
def declare_order_lost(self, arg):
if not self.has_sales_order():