Merge branch 'responsive' of github.com:webnotes/erpnext into responsive

Conflicts:
	selling/doctype/lead/lead.txt
This commit is contained in:
Anand Doshi
2013-07-04 17:18:45 +05:30
44 changed files with 1061 additions and 622 deletions

View File

@@ -26,12 +26,31 @@ wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.js');
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
onload: function(doc, dt, dn) {
this._super(doc, dt, dn);
if(doc.customer && !doc.quotation_to)
doc.quotation_to = "Customer";
else if(doc.lead && !doc.quotation_to)
doc.quotation_to = "Lead";
},
refresh: function(doc, dt, dn) {
this._super();
this._super(doc, dt, dn);
cur_frm.dashboard.reset(doc);
if(!doc.__islocal) {
if(doc.status=="Converted" || doc.status=="Order Confirmed") {
cur_frm.dashboard.set_headline_alert(wn._(doc.status), "alert-success", "icon-ok-sign");
} else if(doc.status==="Order Lost") {
cur_frm.dashboard.set_headline_alert(wn._(doc.status), "alert-danger", "icon-exclamation-sign");
}
}
if(doc.docstatus == 1 && doc.status!='Order Lost') {
if(doc.docstatus == 1 && doc.status!=='Order Lost') {
cur_frm.add_custom_button('Make Sales Order', cur_frm.cscript['Make Sales Order']);
cur_frm.add_custom_button('Set as Lost', cur_frm.cscript['Declare Order Lost']);
if(doc.status!=="Order Confirmed") {
cur_frm.add_custom_button('Set as Lost', cur_frm.cscript['Declare Order Lost']);
}
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
}
@@ -108,20 +127,10 @@ cur_frm.fields_dict['enq_no'].get_query = function(doc,cdt,cdn){
// Make Sales Order
// =====================================================================================
cur_frm.cscript['Make Sales Order'] = function() {
var doc = cur_frm.doc;
if (doc.docstatus == 1) {
var n = wn.model.make_new_doc_and_get_name("Sales Order");
$c('dt_map', args={
'docs':wn.model.compress([locals["Sales Order"][n]]),
'from_doctype':'Quotation',
'to_doctype':'Sales Order',
'from_docname':doc.name,
'from_to_list':"[['Quotation', 'Sales Order'], ['Quotation Item', 'Sales Order Item'],['Sales Taxes and Charges','Sales Taxes and Charges'], ['Sales Team', 'Sales Team'], ['TC Detail', 'TC Detail']]"
}, function(r,rt) {
loaddoc("Sales Order", n);
});
}
wn.model.open_mapped_doc({
method: "selling.doctype.quotation.quotation.make_sales_order",
source_name: cur_frm.doc.name
})
}
//pull enquiry details
@@ -150,51 +159,35 @@ cur_frm.cscript.pull_enquiry_detail = function(doc,cdt,cdn){
// declare order lost
//-------------------------
cur_frm.cscript['Declare Order Lost'] = function(){
var qtn_lost_dialog;
var dialog = new wn.ui.Dialog({
title: "Set as Lost",
fields: [
{"fieldtype": "Text", "label": "Reason for losing", "fieldname": "reason",
"reqd": 1 },
{"fieldtype": "Button", "label": "Update", "fieldname": "update"},
]
});
set_qtn_lost_dialog = function(){
qtn_lost_dialog = new Dialog(400,400,'Add Quotation Lost Reason');
qtn_lost_dialog.make_body([
['HTML', 'Message', '<div class="comment">Please add quotation lost reason</div>'],
['Text', 'Quotation Lost Reason'],
['HTML', 'Response', '<div class = "comment" id="update_quotation_dialog_response"></div>'],
['HTML', 'Add Reason', '<div></div>']
]);
var add_reason_btn1 = $a($i(qtn_lost_dialog.widgets['Add Reason']), 'button', 'button');
add_reason_btn1.innerHTML = 'Add';
add_reason_btn1.onclick = function(){ qtn_lost_dialog.add(); }
var add_reason_btn2 = $a($i(qtn_lost_dialog.widgets['Add Reason']), 'button', 'button');
add_reason_btn2.innerHTML = 'Cancel';
$y(add_reason_btn2,{marginLeft:'4px'});
add_reason_btn2.onclick = function(){ qtn_lost_dialog.hide();}
qtn_lost_dialog.onshow = function() {
qtn_lost_dialog.widgets['Quotation Lost Reason'].value = '';
$i('update_quotation_dialog_response').innerHTML = '';
}
qtn_lost_dialog.add = function() {
// sending...
$i('update_quotation_dialog_response').innerHTML = 'Processing...';
var arg = strip(qtn_lost_dialog.widgets['Quotation Lost Reason'].value);
var call_back = function(r,rt) {
if(r.message == 'true'){
$i('update_quotation_dialog_response').innerHTML = 'Done';
qtn_lost_dialog.hide();
cur_frm.refresh();
dialog.fields_dict.update.$input.click(function() {
args = dialog.get_values();
if(!args) return;
cur_frm.call({
method: "declare_order_lost",
doc: cur_frm.doc,
args: args.reason,
callback: function(r) {
if(r.exc) {
msgprint("There were errors.");
return;
}
}
if(arg) $c_obj(make_doclist(cur_frm.doc.doctype, cur_frm.doc.name),'declare_order_lost',arg,call_back);
else msgprint("Please add Quotation lost reason");
}
}
if(!qtn_lost_dialog){
set_qtn_lost_dialog();
}
qtn_lost_dialog.show();
dialog.hide();
cur_frm.refresh();
},
btn: this
})
});
dialog.show();
}
//================ Last Quoted Price and Last Sold Price suggestion ======================

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()
@@ -191,7 +194,7 @@ class DocType(SellingController):
# declare as order lost
#-------------------------
def declare_order_lost(self,arg):
def declare_order_lost(self, arg):
chk = sql("select t1.name from `tabSales Order` t1, `tabSales Order Item` t2 where t2.parent = t1.name and t1.docstatus=1 and t2.prevdoc_docname = %s",self.doc.name)
if chk:
msgprint("Sales Order No. "+cstr(chk[0][0])+" is submitted against this Quotation. Thus 'Order Lost' can not be declared against it.")
@@ -247,3 +250,37 @@ class DocType(SellingController):
sql("delete from `tabCommunication Log` where parent = '%s'"%self.doc.name)
for d in getlist(self.doclist, 'follow_up'):
d.save()
@webnotes.whitelist()
def make_sales_order(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("Quotation", source_name, {
"Quotation": {
"doctype": "Sales Order",
"field_map": {
"name": "quotation_no",
"transaction_date": "quotation_date"
},
"validation": {
"docstatus": ["=", 1]
}
},
"Quotation Item": {
"doctype": "Sales Order Item",
"field_map": {
"parent": "prevdoc_docname"
}
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
},
"Sales Team": {
"doctype": "Sales Team",
}
}, target_doclist)
return [d.fields for d in doclist]

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:08",
"docstatus": 0,
"modified": "2013-06-28 12:47:10",
"modified": "2013-07-04 10:56:10",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -42,6 +42,13 @@
"doctype": "DocType",
"name": "Quotation"
},
{
"doctype": "DocField",
"fieldname": "customer_section",
"fieldtype": "Section Break",
"label": "Customer",
"options": "icon-user"
},
{
"doctype": "DocField",
"fieldname": "column_break0",
@@ -107,21 +114,19 @@
"read_only": 0
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "customer_name",
"fieldtype": "Data",
"hidden": 0,
"hidden": 1,
"in_list_view": 1,
"label": "Customer Name",
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "address_display",
"fieldtype": "Small Text",
"hidden": 0,
"hidden": 1,
"in_filter": 0,
"label": "Address",
"oldfieldname": "customer_address",
@@ -132,32 +137,29 @@
"search_index": 0
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_display",
"fieldtype": "Small Text",
"hidden": 0,
"hidden": 1,
"in_filter": 0,
"label": "Contact",
"print_hide": 0,
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_mobile",
"fieldtype": "Text",
"hidden": 0,
"hidden": 1,
"label": "Mobile No",
"print_hide": 0,
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_email",
"fieldtype": "Text",
"hidden": 0,
"hidden": 1,
"label": "Contact Email",
"print_hide": 1,
"read_only": 1
@@ -234,6 +236,7 @@
"fieldname": "section_break0",
"fieldtype": "Section Break",
"label": "Price List and Currency",
"options": "icon-tag",
"read_only": 0
},
{
@@ -316,6 +319,7 @@
"fieldtype": "Section Break",
"label": "Items",
"oldfieldtype": "Section Break",
"options": "icon-shopping-cart",
"print_hide": 0,
"read_only": 0,
"search_index": 0
@@ -337,7 +341,6 @@
"doctype": "DocField",
"fieldname": "sec_break23",
"fieldtype": "Section Break",
"options": "Simple",
"read_only": 0
},
{
@@ -413,6 +416,7 @@
"fieldtype": "Section Break",
"label": "Taxes",
"oldfieldtype": "Section Break",
"options": "icon-money",
"read_only": 0
},
{
@@ -512,6 +516,7 @@
"fieldtype": "Section Break",
"label": "Totals",
"oldfieldtype": "Section Break",
"options": "icon-money",
"print_hide": 1,
"read_only": 0
},
@@ -612,6 +617,7 @@
"fieldtype": "Section Break",
"label": "Terms and Conditions",
"oldfieldtype": "Section Break",
"options": "icon-legal",
"print_hide": 0,
"read_only": 0
},
@@ -659,6 +665,7 @@
"fieldname": "contact_section",
"fieldtype": "Section Break",
"label": "Contact Info",
"options": "icon-bullhorn",
"read_only": 0
},
{
@@ -748,6 +755,7 @@
"fieldtype": "Section Break",
"label": "More Info",
"oldfieldtype": "Section Break",
"options": "icon-file-text",
"print_hide": 1,
"read_only": 0
},
@@ -874,8 +882,9 @@
"doctype": "DocField",
"fieldname": "communication_history",
"fieldtype": "Section Break",
"label": "Communication History",
"oldfieldtype": "Section Break",
"options": "Simple",
"options": "icon-comments",
"print_hide": 1,
"read_only": 0
},

View File

@@ -0,0 +1,63 @@
import webnotes, json
from webnotes.utils import flt
import unittest
test_dependencies = ["Sales BOM"]
class TestQuotation(unittest.TestCase):
def test_make_sales_order(self):
from selling.doctype.quotation.quotation import make_sales_order
self.assertRaises(webnotes.ValidationError, make_sales_order, "_T-Quotation-00001")
quotation = webnotes.bean("Quotation","_T-Quotation-00001")
quotation.submit()
sales_order = make_sales_order("_T-Quotation-00001")
self.assertEquals(sales_order[0]["doctype"], "Sales Order")
self.assertEquals(len(sales_order), 2)
self.assertEquals(sales_order[1]["doctype"], "Sales Order Item")
self.assertEquals(sales_order[1]["prevdoc_docname"], "_T-Quotation-00001")
self.assertEquals(sales_order[0]["customer"], "_Test Customer")
sales_order[0]["delivery_date"] = "2014-01-01"
webnotes.print_messages = True
webnotes.bean(sales_order).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,
}
],
]