Status updater for quotation/lost to lead, quotation lost to oppt, and to set conversion as priority in lead
cleanup squashed
This commit is contained in:
parent
d395c7d54e
commit
fcaaa29a58
@ -13,15 +13,17 @@ def validate_status(status, options):
|
|||||||
|
|
||||||
status_map = {
|
status_map = {
|
||||||
"Lead": [
|
"Lead": [
|
||||||
["Converted", "has_customer"],
|
["Lost Quotation", "lost_quotation"],
|
||||||
["Opportunity", "has_opportunity"],
|
["Opportunity", "has_opportunity"],
|
||||||
|
["Quotation", "has_quotation"],
|
||||||
|
["Converted", "has_customer"],
|
||||||
],
|
],
|
||||||
"Opportunity": [
|
"Opportunity": [
|
||||||
["Quotation", "has_quotation"],
|
["Quotation", "has_quotation"],
|
||||||
["Converted", "has_ordered_quotation"],
|
["Converted", "has_ordered_quotation"],
|
||||||
["Lost", "eval:self.status=='Lost'"],
|
["Lost", "eval:self.status=='Lost'"],
|
||||||
|
["Lost", "has_lost_quotation"],
|
||||||
["Closed", "eval:self.status=='Closed'"]
|
["Closed", "eval:self.status=='Closed'"]
|
||||||
|
|
||||||
],
|
],
|
||||||
"Quotation": [
|
"Quotation": [
|
||||||
["Draft", None],
|
["Draft", None],
|
||||||
|
@ -181,7 +181,7 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "status",
|
"oldfieldname": "status",
|
||||||
"oldfieldtype": "Select",
|
"oldfieldtype": "Select",
|
||||||
"options": "Lead\nOpen\nReplied\nOpportunity\nInterested\nConverted\nDo Not Contact",
|
"options": "Lead\nOpen\nReplied\nOpportunity\nQuotation\nLost Quotation\nInterested\nConverted\nDo Not Contact",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"print_hide_if_no_value": 0,
|
"print_hide_if_no_value": 0,
|
||||||
|
@ -80,6 +80,22 @@ class Lead(SellingController):
|
|||||||
def has_opportunity(self):
|
def has_opportunity(self):
|
||||||
return frappe.db.get_value("Opportunity", {"lead": self.name, "status": ["!=", "Lost"]})
|
return frappe.db.get_value("Opportunity", {"lead": self.name, "status": ["!=", "Lost"]})
|
||||||
|
|
||||||
|
def has_quotation(self):
|
||||||
|
return frappe.db.get_value(
|
||||||
|
"Quotation", {
|
||||||
|
"lead": self.name,
|
||||||
|
"status": ["!=", "Lost"],
|
||||||
|
"status": ["!=", "Cancelled"]
|
||||||
|
})
|
||||||
|
|
||||||
|
def lost_quotation(self):
|
||||||
|
return frappe.db.get_value(
|
||||||
|
"Quotation", {
|
||||||
|
"lead": self.name,
|
||||||
|
"status": ["=", "Lost"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_customer(source_name, target_doc=None):
|
def make_customer(source_name, target_doc=None):
|
||||||
return _make_customer(source_name, target_doc)
|
return _make_customer(source_name, target_doc)
|
||||||
|
@ -84,6 +84,10 @@ class Opportunity(TransactionBase):
|
|||||||
return frappe.db.sql("""select q.name from `tabQuotation` q, `tabQuotation Item` qi
|
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)
|
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("""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)
|
||||||
|
|
||||||
def validate_cust_name(self):
|
def validate_cust_name(self):
|
||||||
if self.customer:
|
if self.customer:
|
||||||
self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name")
|
self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name")
|
||||||
|
@ -13,9 +13,14 @@ form_grid_templates = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Quotation(SellingController):
|
class Quotation(SellingController):
|
||||||
|
def after_insert(self):
|
||||||
|
self.update_lead()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(Quotation, self).validate()
|
super(Quotation, self).validate()
|
||||||
self.set_status()
|
self.set_status()
|
||||||
|
self.update_opportunity()
|
||||||
|
self.update_lead()
|
||||||
self.validate_order_type()
|
self.validate_order_type()
|
||||||
self.validate_uom_is_integer("stock_uom", "qty")
|
self.validate_uom_is_integer("stock_uom", "qty")
|
||||||
self.validate_quotation_to()
|
self.validate_quotation_to()
|
||||||
@ -35,6 +40,10 @@ class Quotation(SellingController):
|
|||||||
elif self.lead:
|
elif self.lead:
|
||||||
self.quotation_to = "Lead"
|
self.quotation_to = "Lead"
|
||||||
|
|
||||||
|
def update_lead(self):
|
||||||
|
if self.lead:
|
||||||
|
frappe.get_doc("Lead", self.lead).set_status(update=True)
|
||||||
|
|
||||||
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:
|
||||||
@ -45,6 +54,8 @@ class Quotation(SellingController):
|
|||||||
frappe.db.set(self, 'status', 'Lost')
|
frappe.db.set(self, 'status', 'Lost')
|
||||||
frappe.db.set(self, 'order_lost_reason', arg)
|
frappe.db.set(self, 'order_lost_reason', arg)
|
||||||
self.update_opportunity()
|
self.update_opportunity()
|
||||||
|
self.update_lead()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Cannot set as Lost as Sales Order is made."))
|
frappe.throw(_("Cannot set as Lost as Sales Order is made."))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user