get lead details in quotation

This commit is contained in:
Nabin Hait 2014-02-19 17:43:24 +05:30
parent 05b28eb161
commit 9d1f077922
10 changed files with 88 additions and 90 deletions

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.defaults import get_restrictions
from frappe.utils import add_days
from erpnext.utilities.doctype.address.address import get_address_display
from erpnext.utilities.doctype.contact.contact import get_contact_details
@ -22,7 +23,8 @@ def get_party_details(party=None, account=None, party_type="Customer", company=N
party_bean = frappe.bean(party_type, party)
party = party_bean.doc
set_address_and_contact(out, party, party_type)
set_address_details(out, party, party_type)
set_contact_details(out, party, party_type)
set_other_values(out, party, party_type)
set_price_list(out, party, price_list)
@ -38,20 +40,26 @@ def get_party_details(party=None, account=None, party_type="Customer", company=N
return out
def set_address_and_contact(out, party, party_type):
out.update({
party_type.lower() + "_address": frappe.conn.get_value("Address",
{party_type.lower(): party.name, "is_primary_address":1}, "name"),
"contact_person": frappe.conn.get_value("Contact",
{party_type.lower(): party.name, "is_primary_contact":1}, "name")
})
def set_address_details(out, party, party_type):
billing_address_field = "customer_address" if party_type == "Lead" \
else party_type.lower() + "_address"
out[billing_address_field] = frappe.conn.get_value("Address",
{party_type.lower(): party.name, "is_primary_address":1}, "name")
# address display
out.address_display = get_address_display(out[party_type.lower() + "_address"])
out.address_display = get_address_display(out[billing_address_field])
# shipping address
if party_type in ["Customer", "Lead"]:
out.shipping_address_name = frappe.conn.get_value("Address",
{party_type.lower(): party.name, "is_shipping_address":1}, "name")
out.shipping_address = get_address_display(out["shipping_address_name"])
def set_contact_details(out, party, party_type):
out.contact_person = frappe.conn.get_value("Contact",
{party_type.lower(): party.name, "is_primary_contact":1}, "name")
# primary contact details
out.update(get_contact_details(out.contact_person))
def set_other_values(out, party, party_type):
# copy

View File

@ -32,12 +32,13 @@ class SellingController(StockController):
self.set_taxes("other_charges", "taxes_and_charges")
def set_missing_lead_customer_details(self):
from erpnext.accounts.party import get_party_details
if self.doc.customer:
from erpnext.accounts.party import get_party_details
self.doc.update_if_missing(get_party_details(self.doc.customer))
elif self.doc.lead:
self.doc.update_if_missing(self.get_lead_defaults())
from erpnext.selling.doctype.lead.lead import get_lead_details
self.doc.update_if_missing(get_lead_details(self.doc.lead))
def set_price_list_and_item_details(self):
self.set_price_list_currency("Selling")

View File

@ -2,7 +2,7 @@
{
"creation": "2013-08-02 13:45:23",
"docstatus": 0,
"modified": "2013-12-20 19:23:14",
"modified": "2014-02-19 17:40:18",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -47,6 +47,7 @@
"label": "Employee Settings"
},
{
"default": "Naming Series",
"description": "Employee record is created using selected field. ",
"doctype": "DocField",
"fieldname": "emp_created_by",

View File

@ -36,22 +36,23 @@ erpnext.utils.get_party_details = function(frm, method, args) {
});
}
erpnext.utils.get_address_display = function(frm, address_field) {
erpnext.utils.get_address_display = function(frm, address_field, display_field) {
if(frm.updating_party_details) return;
if(!address_field) {
if(frm.doc.customer) {
address_field = "customer_address";
} else {
} else if(frm.doc.supplier) {
address_field = "supplier_address";
}
} else return;
}
if(!display_field) display_field = "address_display";
if(frm.doc[address_field]) {
frappe.call({
method: "erpnext.utilities.doctype.address.address.get_address_display",
args: {address: frm.doc[address_field] },
args: {"address_dict": frm.doc[address_field] },
callback: function(r) {
if(r.message)
frm.set_value("address_display", r.message)
frm.set_value(display_field, r.message)
}
})
}
@ -60,7 +61,7 @@ erpnext.utils.get_address_display = function(frm, address_field) {
erpnext.utils.get_contact_details = function(frm) {
if(frm.updating_party_details) return;
if(frm.doc[address_field]) {
if(frm.doc["contact_person"]) {
frappe.call({
method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
args: {contact: frm.doc.contact_person },

View File

@ -4,8 +4,8 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cstr, validate_email_add, cint, extract_email_id
from frappe import session, msgprint
from frappe.utils import cstr, validate_email_add, cint
from frappe import session
from erpnext.controllers.selling_controller import SellingController
@ -121,4 +121,27 @@ def make_opportunity(source_name, target_doclist=None):
}
}}, target_doclist)
return [d if isinstance(d, dict) else d.fields for d in doclist]
return [d if isinstance(d, dict) else d.fields for d in doclist]
@frappe.whitelist()
def get_lead_details(lead):
if not lead: return {}
from erpnext.accounts.party import set_address_details
out = frappe._dict()
lead_bean = frappe.bean("Lead", lead)
lead = lead_bean.doc
out.update({
"territory": lead.territory,
"customer_name": lead.company_name or lead.lead_name,
"contact_display": lead.lead_name,
"contact_email": lead.email_id,
"contact_mobile": lead.mobile_no,
"contact_phone": lead.phone,
})
set_address_details(out, lead, "Lead")
return out

View File

@ -21,15 +21,6 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
doc.quotation_to = "Customer";
else if(doc.lead && !doc.quotation_to)
doc.quotation_to = "Lead";
// to overwrite the customer_filter trigger from queries.js
if (doc.lead) {
$.each(["customer_address", "shipping_address_name"],
function(i, opts) {
me.frm.set_query(opts, erpnext.queries["lead_filter"]);
}
);
}
},
refresh: function(doc, dt, dn) {
this._super(doc, dt, dn);
@ -75,11 +66,19 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
},
quotation_to: function() {
var me = this;
this.frm.toggle_reqd("lead", this.frm.doc.quotation_to == "Lead");
this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
if (this.frm.doc.quotation_to == "Lead") {
this.frm.set_value("customer", null);
this.frm.set_value("contact_person", null);
// to overwrite the customer_filter trigger from queries.js
$.each(["customer_address", "shipping_address_name"],
function(i, opts) {
me.frm.set_query(opts, erpnext.queries["lead_filter"]);
}
);
}
else if (this.frm.doc.quotation_to == "Customer")
this.frm.set_value("lead", null);
@ -100,6 +99,23 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
return this._super(party_field);
}
},
lead: function() {
var me = this;
frappe.call({
method: "erpnext.selling.doctype.lead.lead.get_lead_details",
args: { "lead": this.frm.doc.lead },
callback: function(r) {
if(r.message) {
me.frm.updating_party_details = true;
me.frm.set_value(r.message);
me.frm.refresh();
me.frm.updating_party_details = false;
}
}
})
}
});
cur_frm.script_manager.make(erpnext.selling.QuotationController);
@ -108,24 +124,6 @@ cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) {
return{ query: "erpnext.controllers.queries.lead_query" }
}
cur_frm.cscript.lead = function(doc, cdt, cdn) {
if(doc.lead) {
unhide_field('territory');
return cur_frm.call({
doc: cur_frm.doc,
method: "set_lead_defaults",
callback: function(r) {
if(!r.exc) {
cur_frm.refresh_fields();
}
}
});
}
}
// Make Sales Order
// =====================================================================================
cur_frm.cscript['Make Sales Order'] = function() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.quotation.quotation.make_sales_order",
@ -133,8 +131,6 @@ cur_frm.cscript['Make Sales Order'] = function() {
})
}
// declare order lost
//-------------------------
cur_frm.cscript['Declare Order Lost'] = function(){
var dialog = new frappe.ui.Dialog({
title: "Set as Lost",

View File

@ -158,7 +158,7 @@ def _make_customer(source_name, ignore_permissions=False):
try:
customer.insert()
return customer
except NameError, e:
except NameError:
if frappe.defaults.get_global_default('cust_master_name') == "Customer Name":
customer.run_method("autoname")
customer.doc.name += "-" + lead_name

View File

@ -111,6 +111,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
erpnext.utils.get_address_display(this.frm, "customer_address");
},
shipping_address_name: function() {
erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address");
},
contact_person: function() {
erpnext.utils.get_contact_details(this.frm);
},
@ -552,28 +556,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
if(df) df.label = label;
});
},
shipping_address_name: function () {
var me = this;
if(this.frm.doc.shipping_address_name) {
frappe.model.with_doc("Address", this.frm.doc.shipping_address_name, function(name) {
var address = frappe.model.get_doc("Address", name);
var out = $.map(["address_line1", "address_line2", "city"],
function(f) { return address[f]; });
var state_pincode = $.map(["state", "pincode"], function(f) { return address[f]; }).join(" ");
if(state_pincode) out.push(state_pincode);
if(address["country"]) out.push(address["country"]);
out.concat($.map([["Phone:", address["phone"]], ["Fax:", address["fax"]]],
function(val) { return val[1] ? val.join(" ") : null; }));
me.frm.set_value("shipping_address", out.join("\n"));
});
}
}
});
// Help for Sales BOM items

View File

@ -34,7 +34,7 @@ def get_item_details(args):
args = frappe._dict(args)
if not args.get("transaction_type"):
args.transaction_type = "selling" if args.get("customer") else "buying"
args.transaction_type = "buying" if args.get("supplier") else "selling"
if not args.get("price_list"):
args.price_list = args.get("selling_price_list") or args.get("buying_price_list")

View File

@ -31,20 +31,6 @@ class TransactionBase(StatusUpdater):
break
return self._party_type_and_name
def get_lead_defaults(self):
out = self.get_default_address_and_contact("lead")
lead = frappe.conn.get_value("Lead", self.doc.lead,
["territory", "company_name", "lead_name"], as_dict=True) or {}
out["territory"] = lead.get("territory")
out["customer_name"] = lead.get("company_name") or lead.get("lead_name")
return out
def set_lead_defaults(self):
self.doc.fields.update(self.get_lead_defaults())
def load_notification_message(self):
dt = self.doc.doctype.lower().replace(" ", "_")