[mapper] added sales order > material request, added postprocess function

This commit is contained in:
Rushabh Mehta 2013-07-04 16:29:03 +05:30
parent 080fcc8fcd
commit 212de6a084
5 changed files with 66 additions and 44 deletions

View File

@ -105,29 +105,9 @@ cur_frm.cscript['Create Customer'] = function(){
})
}
// Create New Opportunity
// ===============================================================
cur_frm.cscript['Create Opportunity'] = 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 now converted to customer. Please create enquiry on behalf of customer");
}
else{
n = wn.model.make_new_doc_and_get_name("Opportunity");
$c('dt_map', args={
'docs':wn.model.compress([locals["Opportunity"][n]]),
'from_doctype':'Lead',
'to_doctype':'Opportunity',
'from_docname':doc.name,
'from_to_list':"[['Lead', 'Opportunity']]"
}
, function(r,rt) {
loaddoc("Opportunity", n);
}
);
}
}
);
wn.model.open_mapped_doc({
method: "selling.doctype.lead.lead.make_opportunity",
source_name: cur_frm.doc.name
})
}

View File

@ -101,9 +101,6 @@ class DocType(SellingController):
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",
@ -116,3 +113,19 @@ def make_customer(source_name, target_doclist=None):
}}, target_doclist)
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_opportunity(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
doclist = get_mapped_doclist("Lead", source_name,
{"Lead": {
"doctype": "Opportunity",
"field_map": {
"campaign_name": "campaign",
"doctype": "enquiry_from",
"name": "lead",
}
}}, target_doclist)
return [d.fields for d in doclist]

View File

@ -195,21 +195,10 @@ cur_frm.cscript.make_maintenance_visit = function() {
}
cur_frm.cscript['Make Material Request'] = function() {
var doc = cur_frm.doc;
if (doc.docstatus == 1) {
n = wn.model.make_new_doc_and_get_name("Material Request");
$c('dt_map', args={
'docs':wn.model.compress([locals["Material Request"][n]]),
'from_doctype':'Sales Order',
'to_doctype':'Material Request',
'from_docname':doc.name,
'from_to_list':"[['Sales Order', 'Material Request'], ['Sales Order Item', 'Material Request Item']]"
}
, function(r,rt) {
loaddoc("Material Request", n);
}
);
}
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_material_request",
source_name: cur_frm.doc.name
})
}

View File

@ -379,3 +379,30 @@ def get_currency_and_number_format():
"currency_symbols": json.dumps(dict(webnotes.conn.sql("""select name, symbol
from tabCurrency where ifnull(enabled,0)=1""")))
}
@webnotes.whitelist()
def make_material_request(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def postprocess(source, doclist):
doclist[0].material_request_type = "Purchase"
doclist = get_mapped_doclist("Sales Order", source_name, {
"Sales Order": {
"doctype": "Material Request",
"validation": {
"docstatus": ["=", 1]
}
},
"Sales Order Item": {
"doctype": "Material Request Item",
"field_map": {
"parent": "sales_order_no",
"reserved_warehouse": "warehouse",
"stock_uom": "uom"
}
}
}, target_doclist, postprocess)
return [d.fields for d in doclist]

View File

@ -3,6 +3,19 @@ from webnotes.utils import flt
import unittest
class TestSalesOrder(unittest.TestCase):
def test_make_material_request(self):
from selling.doctype.sales_order.sales_order import make_material_request
self.assertRaises(webnotes.ValidationError, make_material_request,
"_T-Sales Order-00001")
sales_order = webnotes.bean("Sales Order", "_T-Sales Order-00001")
sales_order.submit()
mr = make_material_request("_T-Sales Order-00001")
self.assertEquals(mr[0]["material_request_type"], "Purchase")
self.assertEquals(len(mr), len(sales_order.doclist))
def create_so(self, so_doclist = None):
if not so_doclist:
so_doclist =test_records[0]