mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
[minor] [fix] opportunity form, queries, stock uom replace utility
This commit is contained in:
@@ -19,6 +19,70 @@ wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||
wn.provide("erpnext.selling");
|
||||
// TODO commonify this code
|
||||
erpnext.selling.Opportunity = wn.ui.form.Controller.extend({
|
||||
onload: function() {
|
||||
if(!this.frm.doc.enquiry_from && this.frm.doc.customer)
|
||||
this.frm.doc.enquiry_from = "Customer";
|
||||
if(!this.frm.doc.enquiry_from && this.frm.doc.lead)
|
||||
this.frm.doc.enquiry_from = "Lead";
|
||||
|
||||
if(!this.frm.doc.enquiry_from)
|
||||
hide_field(['customer', 'customer_address', 'contact_person', 'customer_name','lead', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
|
||||
if(!this.frm.doc.status)
|
||||
set_multiple(cdt,cdn,{status:'Draft'});
|
||||
if(!this.frm.doc.date)
|
||||
this.frm.doc.transaction_date = date.obj_to_str(new Date());
|
||||
if(!this.frm.doc.company && sys_defaults.company)
|
||||
set_multiple(cdt,cdn,{company:sys_defaults.company});
|
||||
if(!this.frm.doc.fiscal_year && sys_defaults.fiscal_year)
|
||||
set_multiple(cdt,cdn,{fiscal_year:sys_defaults.fiscal_year});
|
||||
|
||||
if(this.frm.doc.enquiry_from) {
|
||||
if(this.frm.doc.enquiry_from == 'Customer') {
|
||||
hide_field('lead');
|
||||
}
|
||||
else if (this.frm.doc.enquiry_from == 'Lead') {
|
||||
hide_field(['customer', 'customer_address', 'contact_person', 'customer_group']);
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.frm.doc.__islocal) {
|
||||
cur_frm.communication_view = new wn.views.CommunicationList({
|
||||
list: wn.model.get("Communication", {"opportunity": this.frm.doc.name}),
|
||||
parent: cur_frm.fields_dict.communication_html.wrapper,
|
||||
doc: this.frm.doc,
|
||||
recipients: this.frm.doc.contact_email
|
||||
});
|
||||
}
|
||||
|
||||
if(this.frm.doc.customer && !this.frm.doc.customer_name) cur_frm.cscript.customer(doc);
|
||||
|
||||
this.setup_queries();
|
||||
},
|
||||
|
||||
setup_queries: function() {
|
||||
var me = this;
|
||||
|
||||
if(this.frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
|
||||
this.frm.set_query("contact_by", erpnext.queries.profile);
|
||||
}
|
||||
|
||||
this.frm.set_query("item_code", "enquiry_details", function() {
|
||||
var key = (me.frm.doc.enquiry_type === "Maintenance" ? "is_service_item" : "is_sales_item");
|
||||
return {
|
||||
query: "controllers.queries.item_query",
|
||||
filters: { key: "Yes" }
|
||||
};
|
||||
});
|
||||
|
||||
$.each([["lead", "lead"],
|
||||
["customer", "customer"],
|
||||
["customer_address", "customer_filter"],
|
||||
["contact_person", "customer_filter"],
|
||||
["territory", "not_a_group_filter"]], function(i, opts) {
|
||||
me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
|
||||
});
|
||||
},
|
||||
|
||||
customer: function() {
|
||||
var me = this;
|
||||
if(this.frm.doc.customer) {
|
||||
@@ -70,52 +134,6 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn){
|
||||
|
||||
}
|
||||
|
||||
// ONLOAD
|
||||
// ===============================================================
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
|
||||
if(!doc.enquiry_from && doc.customer)
|
||||
doc.enquiry_from = "Customer";
|
||||
if(!doc.enquiry_from && doc.lead)
|
||||
doc.enquiry_from = "Lead";
|
||||
|
||||
if(!doc.enquiry_from)
|
||||
hide_field(['customer', 'customer_address', 'contact_person', 'customer_name','lead', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
|
||||
if(!doc.status)
|
||||
set_multiple(cdt,cdn,{status:'Draft'});
|
||||
if(!doc.date)
|
||||
doc.transaction_date = date.obj_to_str(new Date());
|
||||
if(!doc.company && sys_defaults.company)
|
||||
set_multiple(cdt,cdn,{company:sys_defaults.company});
|
||||
if(!doc.fiscal_year && sys_defaults.fiscal_year)
|
||||
set_multiple(cdt,cdn,{fiscal_year:sys_defaults.fiscal_year});
|
||||
|
||||
if(doc.enquiry_from) {
|
||||
if(doc.enquiry_from == 'Customer') {
|
||||
hide_field('lead');
|
||||
}
|
||||
else if (doc.enquiry_from == 'Lead') {
|
||||
hide_field(['customer', 'customer_address', 'contact_person', 'customer_group']);
|
||||
}
|
||||
}
|
||||
|
||||
if(!doc.__islocal) {
|
||||
cur_frm.communication_view = new wn.views.CommunicationList({
|
||||
list: wn.model.get("Communication", {"opportunity": doc.name}),
|
||||
parent: cur_frm.fields_dict.communication_html.wrapper,
|
||||
doc: doc,
|
||||
recipients: doc.contact_email
|
||||
});
|
||||
}
|
||||
|
||||
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
|
||||
cur_frm.fields_dict.contact_by.get_query = function(doc,cdt,cdn) {
|
||||
return { query:"controllers.queries.profile_query" } }
|
||||
}
|
||||
|
||||
if(doc.customer && !doc.customer_name) cur_frm.cscript.customer(doc);
|
||||
}
|
||||
|
||||
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
|
||||
if(doc.enquiry_from == 'Lead' && doc.lead) {
|
||||
cur_frm.cscript.lead(doc,cdt,cdn);
|
||||
@@ -153,26 +171,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
|
||||
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
|
||||
return {
|
||||
filters:{'customer':doc.customer}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
|
||||
if (!doc.customer) msgprint("Please select customer first");
|
||||
else {
|
||||
filters:{'customer':doc.customer}
|
||||
}
|
||||
}
|
||||
|
||||
// lead
|
||||
cur_frm.fields_dict['lead'].get_query = function(doc,cdt,cdn){
|
||||
return {
|
||||
query: "selling.doctype.opportunity.opportunity.get_lead"
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.lead = function(doc, cdt, cdn) {
|
||||
cur_frm.toggle_display("contact_info", doc.customer || doc.lead);
|
||||
|
||||
@@ -185,19 +183,7 @@ cur_frm.cscript.lead = function(doc, cdt, cdn) {
|
||||
'contact_email', 'territory']);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['enquiry_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
|
||||
if (doc.enquiry_type == 'Maintenance') {
|
||||
return {
|
||||
query:"controllers.queries.item_query",
|
||||
filters:{ 'is_service_item': 'Yes' }
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
query:"controllers.queries.item_query",
|
||||
filters:{ 'is_sales_item': 'Yes' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript['Declare Opportunity Lost'] = function(){
|
||||
var dialog = new wn.ui.Dialog({
|
||||
@@ -229,16 +215,4 @@ cur_frm.cscript['Declare Opportunity Lost'] = function(){
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
//get query select Territory
|
||||
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
|
||||
return{
|
||||
filters:{'is_group': 'No'}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) {
|
||||
return { query:"controllers.queries.lead_query" } }
|
||||
|
||||
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
|
||||
return { query:"controllers.queries.customer_query" } }
|
||||
}
|
||||
@@ -197,14 +197,4 @@ def make_quotation(source_name, target_doclist=None):
|
||||
}
|
||||
}, target_doclist)
|
||||
|
||||
return [d.fields for d in doclist]
|
||||
|
||||
def get_lead(doctype, txt, searchfield, start, page_len, filters):
|
||||
from controllers.queries import get_match_cond
|
||||
return webnotes.conn.sql ("""select `tabLead`.name, `tabLead`.lead_name FROM `tabLead`
|
||||
where `tabLead`.%(key)s like "%(txt)s"
|
||||
%(mcond)s
|
||||
order by `tabLead`.`name` asc
|
||||
limit %(start)s, %(page_len)s """ % {'key': searchfield,
|
||||
'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
|
||||
'start': start, 'page_len': page_len})
|
||||
return [d.fields for d in doclist]
|
||||
Reference in New Issue
Block a user