[buying] started cleanup, [mapper] started rewrite

This commit is contained in:
Rushabh Mehta
2013-07-04 12:50:52 +05:30
parent bcff7dce8e
commit 8aded138c7
17 changed files with 218 additions and 97 deletions

View File

@@ -99,38 +99,10 @@ erpnext.LeadController = wn.ui.form.Controller.extend({
$.extend(cur_frm.cscript, new erpnext.LeadController({frm: cur_frm}));
cur_frm.cscript['Create Customer'] = function(){
var doc = cur_frm.doc;
$c('runserverobj',args={ 'method':'check_status', 'docs':wn.model.compress(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message == 'Converted'){
msgprint("This lead is already converted to customer");
}
else{
n = wn.model.make_new_doc_and_get_name("Customer");
$c('dt_map', args={
'docs':wn.model.compress([locals["Customer"][n]]),
'from_doctype':'Lead',
'to_doctype':'Customer',
'from_docname':doc.name,
'from_to_list':"[['Lead', 'Customer']]"
},
function(r,rt) {
wn.model.with_doctype("Customer", function() {
var customer = wn.model.get_doc("Customer", n);
var customer_copy = $.extend({}, customer);
var updated = wn.model.set_default_values(customer_copy);
$.each(updated, function(i, f) {
if(!customer[f]) customer[f] = customer_copy[f];
});
loaddoc("Customer", n);
});
}
);
}
}
);
wn.model.open_mapped_doc({
method: "selling.doctype.lead.lead.make_customer",
source_name: cur_frm.doc.name
})
}
// Create New Opportunity

View File

@@ -95,4 +95,24 @@ class DocType(SellingController):
webnotes.conn.sql("""update `tabSupport Ticket` set lead='' where lead=%s""",
self.doc.name)
self.delete_events()
self.delete_events()
@webnotes.whitelist()
def make_customer(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
if target_doclist:
target_doclist = json.loads(target_doclist)
doclist = get_mapped_doclist("Lead", source_name,
{"Lead": {
"doctype": "Customer",
"field_map": {
"name": "lead_name",
"company_name": "customer_name",
"contact_no": "phone_1",
"fax": "fax_1"
}
}})
return [d.fields for d in doclist]

View File

@@ -1,3 +1,5 @@
from __future__ import unicode_literals
test_records = [
[{"doctype":"Lead", "lead_name": "_Test Lead", "status":"Open",
"email_id":"test_lead@example.com"}],
@@ -8,3 +10,17 @@ test_records = [
[{"doctype":"Lead", "lead_name": "_Test Lead 3", "status":"Converted",
"email_id":"test_lead3@example.com"}],
]
import webnotes
import unittest
class TestLead(unittest.TestCase):
def test_make_customer(self):
from selling.doctype.lead.lead import make_customer
customer = make_customer("_T-Lead-00001")
self.assertEquals(customer[0]["doctype"], "Customer")
self.assertEquals(customer[0]["lead_name"], "_T-Lead-00001")
webnotes.bean(customer).insert()