fixes for #2655
This commit is contained in:
parent
e241569303
commit
47a62c623c
@ -17,6 +17,7 @@ status_map = {
|
|||||||
["Submitted", "eval:self.docstatus==1"],
|
["Submitted", "eval:self.docstatus==1"],
|
||||||
["Lost", "eval:self.status=='Lost'"],
|
["Lost", "eval:self.status=='Lost'"],
|
||||||
["Quotation", "has_quotation"],
|
["Quotation", "has_quotation"],
|
||||||
|
["Converted", "has_ordered_quotation"],
|
||||||
["Cancelled", "eval:self.docstatus==2"],
|
["Cancelled", "eval:self.docstatus==2"],
|
||||||
],
|
],
|
||||||
"Quotation": [
|
"Quotation": [
|
||||||
|
@ -28,7 +28,6 @@ erpnext.selling.Opportunity = frappe.ui.form.Controller.extend({
|
|||||||
if(!this.frm.doc.fiscal_year && sys_defaults.fiscal_year)
|
if(!this.frm.doc.fiscal_year && sys_defaults.fiscal_year)
|
||||||
set_multiple(cdt, cdn, { fiscal_year:sys_defaults.fiscal_year });
|
set_multiple(cdt, cdn, { fiscal_year:sys_defaults.fiscal_year });
|
||||||
|
|
||||||
if(this.frm.doc.customer && !this.frm.doc.customer_name) cur_frm.cscript.customer(this.frm.doc);
|
|
||||||
|
|
||||||
this.setup_queries();
|
this.setup_queries();
|
||||||
},
|
},
|
||||||
|
@ -74,9 +74,10 @@
|
|||||||
"read_only": 0
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.customer || doc.lead",
|
"depends_on": "",
|
||||||
"fieldname": "customer_name",
|
"fieldname": "customer_name",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
|
"hidden": 1,
|
||||||
"label": "Customer / Lead Name",
|
"label": "Customer / Lead Name",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
|
@ -10,6 +10,56 @@ from frappe.model.mapper import get_mapped_doc
|
|||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
|
|
||||||
class Opportunity(TransactionBase):
|
class Opportunity(TransactionBase):
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
self._prev = frappe._dict({
|
||||||
|
"contact_date": frappe.db.get_value("Opportunity", self.name, "contact_date") if \
|
||||||
|
(not cint(self.get("__islocal"))) else None,
|
||||||
|
"contact_by": frappe.db.get_value("Opportunity", self.name, "contact_by") if \
|
||||||
|
(not cint(self.get("__islocal"))) else None,
|
||||||
|
})
|
||||||
|
|
||||||
|
if not self.enquiry_from:
|
||||||
|
frappe.throw(_("Opportunity From field is mandatory"))
|
||||||
|
|
||||||
|
self.set_status()
|
||||||
|
self.validate_item_details()
|
||||||
|
self.validate_uom_is_integer("uom", "qty")
|
||||||
|
self.validate_lead_cust()
|
||||||
|
self.validate_cust_name()
|
||||||
|
|
||||||
|
from erpnext.accounts.utils import validate_fiscal_year
|
||||||
|
validate_fiscal_year(self.transaction_date, self.fiscal_year, "Opportunity Date")
|
||||||
|
|
||||||
|
def on_submit(self):
|
||||||
|
if self.lead:
|
||||||
|
frappe.get_doc("Lead", self.lead).set_status(update=True)
|
||||||
|
|
||||||
|
def on_cancel(self):
|
||||||
|
if self.has_quotation():
|
||||||
|
frappe.throw(_("Cannot Cancel Opportunity as Quotation Exists"))
|
||||||
|
self.set_status(update=True)
|
||||||
|
|
||||||
|
def declare_enquiry_lost(self,arg):
|
||||||
|
if not self.has_quotation():
|
||||||
|
frappe.db.set(self, 'status', 'Lost')
|
||||||
|
frappe.db.set(self, 'order_lost_reason', arg)
|
||||||
|
else:
|
||||||
|
frappe.throw(_("Cannot declare as lost, because Quotation has been made."))
|
||||||
|
|
||||||
|
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_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)
|
||||||
|
|
||||||
|
def validate_cust_name(self):
|
||||||
|
self.customer_name = self.customer or self.lead
|
||||||
|
|
||||||
def get_item_details(self, item_code):
|
def get_item_details(self, item_code):
|
||||||
item = frappe.db.sql("""select item_name, stock_uom, description_html, description, item_group, brand
|
item = frappe.db.sql("""select item_name, stock_uom, description_html, description, item_group, brand
|
||||||
from `tabItem` where name = %s""", item_code, as_dict=1)
|
from `tabItem` where name = %s""", item_code, as_dict=1)
|
||||||
@ -80,51 +130,16 @@ class Opportunity(TransactionBase):
|
|||||||
frappe.throw(_("Items required"))
|
frappe.throw(_("Items required"))
|
||||||
|
|
||||||
def validate_lead_cust(self):
|
def validate_lead_cust(self):
|
||||||
if self.enquiry_from == 'Lead' and not self.lead:
|
if self.enquiry_from == 'Lead':
|
||||||
frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
|
if not self.lead:
|
||||||
elif self.enquiry_from == 'Customer' and not self.customer:
|
frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
|
||||||
msgprint("Customer is mandatory if 'Opportunity From' is selected as Customer", raise_exception=1)
|
else:
|
||||||
|
self.customer = None
|
||||||
def validate(self):
|
elif self.enquiry_from == 'Customer':
|
||||||
self._prev = frappe._dict({
|
if not self.customer:
|
||||||
"contact_date": frappe.db.get_value("Opportunity", self.name, "contact_date") if \
|
msgprint("Customer is mandatory if 'Opportunity From' is selected as Customer", raise_exception=1)
|
||||||
(not cint(self.get("__islocal"))) else None,
|
else:
|
||||||
"contact_by": frappe.db.get_value("Opportunity", self.name, "contact_by") if \
|
self.lead = None
|
||||||
(not cint(self.get("__islocal"))) else None,
|
|
||||||
})
|
|
||||||
|
|
||||||
if not self.enquiry_from:
|
|
||||||
frappe.throw(_("Opportunity From field is mandatory"))
|
|
||||||
|
|
||||||
self.set_status()
|
|
||||||
self.validate_item_details()
|
|
||||||
self.validate_uom_is_integer("uom", "qty")
|
|
||||||
self.validate_lead_cust()
|
|
||||||
|
|
||||||
from erpnext.accounts.utils import validate_fiscal_year
|
|
||||||
validate_fiscal_year(self.transaction_date, self.fiscal_year, "Opportunity Date")
|
|
||||||
|
|
||||||
def on_submit(self):
|
|
||||||
if self.lead:
|
|
||||||
frappe.get_doc("Lead", self.lead).set_status(update=True)
|
|
||||||
|
|
||||||
def on_cancel(self):
|
|
||||||
if self.has_quotation():
|
|
||||||
frappe.throw(_("Cannot Cancel Opportunity as Quotation Exists"))
|
|
||||||
self.set_status(update=True)
|
|
||||||
|
|
||||||
def declare_enquiry_lost(self,arg):
|
|
||||||
if not self.has_quotation():
|
|
||||||
frappe.db.set(self, 'status', 'Lost')
|
|
||||||
frappe.db.set(self, 'order_lost_reason', arg)
|
|
||||||
else:
|
|
||||||
frappe.throw(_("Cannot declare as lost, because Quotation has been made."))
|
|
||||||
|
|
||||||
def on_trash(self):
|
|
||||||
self.delete_events()
|
|
||||||
|
|
||||||
def has_quotation(self):
|
|
||||||
return frappe.db.get_value("Quotation Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_quotation(source_name, target_doc=None):
|
def make_quotation(source_name, target_doc=None):
|
||||||
|
@ -134,6 +134,7 @@ class SalesOrder(SellingController):
|
|||||||
frappe.throw(_("Quotation {0} is cancelled").format(quotation))
|
frappe.throw(_("Quotation {0} is cancelled").format(quotation))
|
||||||
|
|
||||||
doc.set_status(update=True)
|
doc.set_status(update=True)
|
||||||
|
doc.update_opportunity()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
super(SalesOrder, self).on_submit()
|
super(SalesOrder, self).on_submit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user