Open lost opportunity again if quotation made against it (#8854)
This commit is contained in:
parent
f69ffeb0b4
commit
e4f80a6eaa
@ -19,7 +19,7 @@ status_map = {
|
|||||||
["Converted", "has_customer"],
|
["Converted", "has_customer"],
|
||||||
],
|
],
|
||||||
"Opportunity": [
|
"Opportunity": [
|
||||||
["Quotation", "has_quotation"],
|
["Quotation", "has_active_quotation"],
|
||||||
["Converted", "has_ordered_quotation"],
|
["Converted", "has_ordered_quotation"],
|
||||||
["Lost", "eval:self.status=='Lost'"],
|
["Lost", "eval:self.status=='Lost'"],
|
||||||
["Lost", "has_lost_quotation"],
|
["Lost", "has_lost_quotation"],
|
||||||
|
@ -84,20 +84,31 @@ class Opportunity(TransactionBase):
|
|||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_events()
|
self.delete_events()
|
||||||
|
|
||||||
def has_quotation(self):
|
def has_active_quotation(self):
|
||||||
return frappe.db.get_value("Quotation Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
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):
|
def has_ordered_quotation(self):
|
||||||
return frappe.db.sql("""select q.name from `tabQuotation` q, `tabQuotation Item` qi
|
return frappe.db.sql("""
|
||||||
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s and q.status = 'Ordered'""", self.name)
|
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):
|
def has_lost_quotation(self):
|
||||||
return frappe.db.sql("""
|
lost_quotation = frappe.db.sql("""
|
||||||
select q.name
|
select q.name
|
||||||
from `tabQuotation` q, `tabQuotation Item` qi
|
from `tabQuotation` q, `tabQuotation Item` qi
|
||||||
where q.name = qi.parent and q.docstatus=1
|
where q.name = qi.parent and q.docstatus=1
|
||||||
and qi.prevdoc_docname =%s and q.status = 'Lost'
|
and qi.prevdoc_docname =%s and q.status = 'Lost'
|
||||||
""", self.name)
|
""", self.name)
|
||||||
|
if lost_quotation:
|
||||||
|
if self.has_active_quotation():
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def validate_cust_name(self):
|
def validate_cust_name(self):
|
||||||
if self.customer:
|
if self.customer:
|
||||||
|
@ -44,7 +44,9 @@ class Quotation(SellingController):
|
|||||||
def update_opportunity(self):
|
def update_opportunity(self):
|
||||||
for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])):
|
for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])):
|
||||||
if opportunity:
|
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):
|
def declare_order_lost(self, arg):
|
||||||
if not self.has_sales_order():
|
if not self.has_sales_order():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user