[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()

View File

@@ -154,8 +154,11 @@ class DocType(SellingController):
super(DocType, self).validate()
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted",
"Order Confirmed", "Order Lost", "Cancelled"])
if not self.doc.status:
self.doc.status = "Draft"
else:
utilities.validate_status(self.doc.status, ["Draft", "Submitted",
"Order Confirmed", "Order Lost", "Cancelled"])
self.validate_fiscal_year()
self.set_last_contact_date()

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:08",
"docstatus": 0,
"modified": "2013-07-03 16:12:44",
"modified": "2013-07-04 10:56:10",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -114,7 +114,6 @@
"read_only": 0
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "customer_name",
"fieldtype": "Data",

View File

@@ -0,0 +1,49 @@
import webnotes
from webnotes.utils import flt
import unittest
test_dependencies = ["Sales BOM"]
class TestLead(unittest.TestCase):
def test_make_sales_order(self):
lead = webnotes.bean("Lead", "_T-Lead-00001")
lead.make_controller()
customer = lead.controller.make_customer()
self.assertEquals(customer[0].doctype, "Customer")
self.assertEquals(customer[0].lead_name, lead.doc.name)
webnotes.bean(customer).insert()
test_records = [
[
{
"company": "_Test Company",
"conversion_rate": 1.0,
"currency": "INR",
"customer": "_Test Customer",
"customer_name": "_Test Customer",
"customer_group": "_Test Customer Group",
"doctype": "Quotation",
"fiscal_year": "_Test Fiscal Year 2013",
"order_type": "Sales",
"plc_conversion_rate": 1.0,
"price_list_currency": "INR",
"price_list_name": "_Test Price List",
"territory": "_Test Territory",
"transaction_date": "2013-02-21",
"grand_total": 1000.0,
"grand_total_export": 1000.0,
},
{
"description": "CPU",
"doctype": "Quotation Item",
"item_code": "_Test Item Home Desktop 100",
"item_name": "CPU",
"parentfield": "quotation_details",
"qty": 10.0,
"basic_rate": 100.0,
"export_rate": 100.0,
"amount": 1000.0,
}
],
]

View File

@@ -37,6 +37,12 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
this.toggle_rounded_total();
},
refresh: function(doc) {
this.frm.toggle_display("customer_name",
(this.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
this._super();
},
customer: function() {
var me = this;
if(this.frm.doc.customer || this.frm.doc.debit_to) {

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-06-18 12:39:59",
"docstatus": 0,
"modified": "2013-07-03 16:12:26",
"modified": "2013-07-04 10:56:35",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -84,7 +84,6 @@
"search_index": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "customer_name",
"fieldtype": "Data",