Merge branch 'master' into dev
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
index 00bdc47..2c228a7 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
@@ -44,7 +44,7 @@
dl = sql("select t1.name, t1.cheque_no, t1.cheque_date, t2.debit, t2.credit, t1.posting_date, t2.against_account from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t2.parent = t1.name and t2.account = %s and (clearance_date is null or clearance_date = '0000-00-00' or clearance_date = '') and (t1.cheque_no is not null or t1.cheque_no != '') and t1.posting_date >= %s and t1.posting_date <= %s and t1.docstatus=1", (self.doc.bank_account, self.doc.from_date, self.doc.to_date))
- self.doc.clear_table(self.doclist, 'entries')
+ self.doclist = self.doc.clear_table(self.doclist, 'entries')
self.doc.total_amount = 0.0
for d in dl:
diff --git a/erpnext/accounts/doctype/budget_distribution/budget_distribution.js b/erpnext/accounts/doctype/budget_distribution/budget_distribution.js
index 84726e8..d7deb9a 100644
--- a/erpnext/accounts/doctype/budget_distribution/budget_distribution.js
+++ b/erpnext/accounts/doctype/budget_distribution/budget_distribution.js
@@ -20,6 +20,6 @@
refresh_field('budget_distribution_details');
}
- $c('runserverobj',args={'method' : 'get_months', 'docs' : compress_doclist([doc])},callback1);
+ $c('runserverobj',args={'method' : 'get_months', 'docs' : compress_doclist(make_doclist(doc.doctype, doc.name))},callback1);
}
}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/form_16a/form_16a.py b/erpnext/accounts/doctype/form_16a/form_16a.py
index d847ec5..fa2adb1 100644
--- a/erpnext/accounts/doctype/form_16a/form_16a.py
+++ b/erpnext/accounts/doctype/form_16a/form_16a.py
@@ -77,7 +77,7 @@
# Get TDS Return acknowledgement
#-------------------------------
def get_return_ack_details(self):
- self.doc.clear_table(self.doclist, 'form_16A_ack_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'form_16A_ack_details')
if not (self.doc.from_date and self.doc.to_date):
msgprint("Please enter From Date, To Date")
else:
@@ -90,7 +90,7 @@
# Get tds payment details
#-------------------------------
def get_tds(self):
- self.doc.clear_table(self.doclist,'form_16A_tax_details')
+ self.doclist = self.doc.clear_table(self.doclist,'form_16A_tax_details')
import datetime
if self.doc.from_date and self.doc.to_date and self.doc.tds_category:
tot=0.0
diff --git a/erpnext/accounts/doctype/gl_control/gl_control.py b/erpnext/accounts/doctype/gl_control/gl_control.py
index 66a0d65..bfeddb0 100644
--- a/erpnext/accounts/doctype/gl_control/gl_control.py
+++ b/erpnext/accounts/doctype/gl_control/gl_control.py
@@ -289,7 +289,7 @@
def get_advances(self, obj, account_head, table_name,table_field_name, dr_or_cr):
jv_detail = webnotes.conn.sql("select t1.name, t1.remark, t2.%s, t2.name, t1.ded_amount from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t1.name = t2.parent and (t2.against_voucher is null or t2.against_voucher = '') and (t2.against_invoice is null or t2.against_invoice = '') and (t2.against_jv is null or t2.against_jv = '') and t2.account = '%s' and t2.is_advance = 'Yes' and t1.docstatus = 1 order by t1.voucher_date " % (dr_or_cr,account_head))
# clear advance table
- obj.doc.clear_table(obj.doclist,table_field_name)
+ obj.doclist = obj.doc.clear_table(obj.doclist,table_field_name)
# Create advance table
for d in jv_detail:
add = addchild(obj.doc, table_field_name, table_name, 1, obj.doclist)
@@ -300,6 +300,8 @@
add.allocate_amount = 0
if table_name == 'Purchase Invoice Advance':
add.tds_amount = flt(d[4])
+
+ return obj.doclist
# Clear rows which is not adjusted
#-------------------------------------
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
index 32bd387..7fed129 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
@@ -378,7 +378,7 @@
# get outstanding invoices
# -------------------------
def get_outstanding_invoices(self):
- self.doc.clear_table(self.doclist, 'entries')
+ self.doclist = self.doc.clear_table(self.doclist, 'entries')
total = 0
for d in self.get_values():
total += flt(d[2])
diff --git a/erpnext/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/erpnext/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
index 138f3d5..d615013 100644
--- a/erpnext/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
+++ b/erpnext/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
@@ -73,7 +73,7 @@
Payment entry will be decided based on account type (Dr/Cr)
"""
- self.doc.clear_table(self.doclist, 'ir_payment_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'ir_payment_details')
gle = self.get_gl_entries()
self.create_payment_table(gle)
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index f57cfe7..668d2ef 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -170,7 +170,7 @@
# Advance Allocation
# -------------------
def get_advances(self):
- get_obj('GL Control').get_advances( self, self.doc.credit_to, 'Purchase Invoice Advance','advance_allocation_details','debit')
+ self.doclist = get_obj('GL Control').get_advances(self, self.doc.credit_to, 'Purchase Invoice Advance','advance_allocation_details','debit')
# ============= OTHER CHARGES ====================
@@ -183,7 +183,7 @@
# Get Purchase Taxes and Charges Master
# -----------------------------------------------------------
def get_purchase_tax_details(self):
- return get_obj('Purchase Common').get_purchase_tax_details(self)
+ self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self)
def get_rate1(self,acc):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index f07c7b3..82314ca 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -140,13 +140,13 @@
# Delivery Note
if self.doc.delivery_note_main:
self.validate_prev_docname('delivery note')
- self.doc.clear_table(self.doclist,'other_charges')
+ self.doclist = self.doc.clear_table(self.doclist,'other_charges')
self.doclist = get_obj('DocType Mapper', 'Delivery Note-Sales Invoice').dt_map('Delivery Note', 'Sales Invoice', self.doc.delivery_note_main, self.doc, self.doclist, "[['Delivery Note', 'Sales Invoice'],['Delivery Note Item', 'Sales Invoice Item'],['Sales Taxes and Charges','Sales Taxes and Charges'],['Sales Team','Sales Team']]")
self.get_income_account('entries')
# Sales Order
elif self.doc.sales_order_main:
self.validate_prev_docname('sales order')
- self.doc.clear_table(self.doclist,'other_charges')
+ self.doclist = self.doc.clear_table(self.doclist,'other_charges')
get_obj('DocType Mapper', 'Sales Order-Sales Invoice').dt_map('Sales Order', 'Sales Invoice', self.doc.sales_order_main, self.doc, self.doclist, "[['Sales Order', 'Sales Invoice'],['Sales Order Item', 'Sales Invoice Item'],['Sales Taxes and Charges','Sales Taxes and Charges'], ['Sales Team', 'Sales Team']]")
self.get_income_account('entries')
@@ -240,18 +240,17 @@
# Load Default Charges
# ----------------------------------------------------------
def load_default_taxes(self):
- return get_obj('Sales Common').load_default_taxes(self)
+ self.doclist = get_obj('Sales Common').load_default_taxes(self)
# Get Sales Taxes and Charges Master Details
# --------------------------
def get_other_charges(self):
- return get_obj('Sales Common').get_other_charges(self)
-
+ self.doclist = get_obj('Sales Common').get_other_charges(self)
# Get Advances
# -------------
def get_advances(self):
- get_obj('GL Control').get_advances(self, self.doc.debit_to, 'Sales Invoice Advance', 'advance_adjustment_details', 'credit')
+ self.doclist = get_obj('GL Control').get_advances(self, self.doc.debit_to, 'Sales Invoice Advance', 'advance_adjustment_details', 'credit')
#pull project customer
#-------------------------
diff --git a/erpnext/accounts/doctype/tds_payment/tds_payment.py b/erpnext/accounts/doctype/tds_payment/tds_payment.py
index 346c565..c1874d9 100644
--- a/erpnext/accounts/doctype/tds_payment/tds_payment.py
+++ b/erpnext/accounts/doctype/tds_payment/tds_payment.py
@@ -67,7 +67,7 @@
# Fetch voucherwise tds details
#-------------------------------
def get_tds_list(self):
- self.doc.clear_table(self.doclist,'tds_payment_details')
+ self.doclist = self.doc.clear_table(self.doclist,'tds_payment_details')
self.doc.total_tds = 0
import datetime
if not self.doc.tds_category:
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index e230e0f..fd02b02 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -621,7 +621,7 @@
# Get other charges from Master
# =================================================================================
def get_purchase_tax_details(self,obj):
- self.doc.clear_table(obj.doclist,'purchase_tax_details')
+ obj.doclist = self.doc.clear_table(obj.doclist,'purchase_tax_details')
idx = 0
other_charge = sql("select category, add_deduct_tax, charge_type,row_id,description,account_head,rate,tax_amount from `tabPurchase Taxes and Charges` where parent = '%s' order by idx" %(obj.doc.purchase_other_charges), as_dict = 1)
for other in other_charge:
@@ -636,6 +636,7 @@
d.tax_amount = flt(other['tax_amount'])
d.idx = idx
idx += 1
+ return obj.doclist
# Get Tax rate if account type is TAX
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index f3bd8b5..9b7e99c 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -291,7 +291,7 @@
if self.doc.is_subcontracted == 'Yes':
self.add_bom(d)
else:
- self.doc.clear_table(self.doclist,'po_raw_material_details',1)
+ self.doclist = self.doc.clear_table(self.doclist,'po_raw_material_details',1)
self.doc.save()
elif item_det[0][1] == 'No':
self.add_bom(d)
@@ -371,4 +371,4 @@
# **** Pull details from other charges master (Get Other Charges) ****
def get_purchase_tax_details(self):
- return get_obj('Purchase Common').get_purchase_tax_details(self)
+ self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self)
diff --git a/erpnext/buying/doctype/quality_inspection/quality_inspection.py b/erpnext/buying/doctype/quality_inspection/quality_inspection.py
index 48ab112..1519268 100644
--- a/erpnext/buying/doctype/quality_inspection/quality_inspection.py
+++ b/erpnext/buying/doctype/quality_inspection/quality_inspection.py
@@ -45,7 +45,7 @@
def get_item_specification_details(self):
- self.doc.clear_table(self.doclist, 'qa_specification_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'qa_specification_details')
specification = sql("select specification, value from `tabItem Quality Inspection Parameter` where parent = '%s' order by idx" % (self.doc.item_code))
for d in specification:
child = addchild(self.doc, 'qa_specification_details', 'Quality Inspection Reading', 1, self.doclist)
diff --git a/erpnext/hr/doctype/appraisal/appraisal.py b/erpnext/hr/doctype/appraisal/appraisal.py
index f46427c..a889e5f 100644
--- a/erpnext/hr/doctype/appraisal/appraisal.py
+++ b/erpnext/hr/doctype/appraisal/appraisal.py
@@ -48,7 +48,7 @@
if not self.doc.kra_template:
msgprint("Please select Appraisal Template to be be fetched")
raise Exception
- self.doc.clear_table(self.doclist,'appraisal_details')
+ self.doclist = self.doc.clear_table(self.doclist,'appraisal_details')
get_obj('DocType Mapper', 'Appraisal Template-Appraisal').dt_map('Appraisal Template', 'Appraisal', self.doc.kra_template, self.doc, self.doclist, "[['Appraisal Template','Appraisal'],['Appraisal Template Goal', 'Appraisal Goal']]")
def validate_dates(self):
diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.py b/erpnext/hr/doctype/holiday_list/holiday_list.py
index 77bdb1f..78c9e33 100644
--- a/erpnext/hr/doctype/holiday_list/holiday_list.py
+++ b/erpnext/hr/doctype/holiday_list/holiday_list.py
@@ -113,7 +113,7 @@
# clear table
# ------------
def clear_table(self):
- self.doc.clear_table(self.doclist,'holiday_list_details')
+ self.doclist = self.doc.clear_table(self.doclist,'holiday_list_details')
# ***************************************** validate *************************************************
diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.js b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.js
index 54cc8d5..67fe9b5 100644
--- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.js
+++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.js
@@ -24,7 +24,7 @@
// Validation For To Date
// ================================================================================================
cur_frm.cscript.to_date = function(doc, cdt, cdn) {
- $c('runserverobj', args={'method':'to_date_validation','docs':compress_doclist([doc])},
+ $c('runserverobj', args={'method':'to_date_validation','docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r, rt) {
var doc = locals[cdt][cdn];
if (r.message) {
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index c041e48..3439fc8 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -70,8 +70,8 @@
# Pull struct details
#=======================================================
def pull_sal_struct(self, struct):
- self.doc.clear_table(self.doclist, 'earning_details')
- self.doc.clear_table(self.doclist, 'deduction_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'earning_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'deduction_details')
get_obj('DocType Mapper', 'Salary Structure-Salary Slip').dt_map('Salary Structure', 'Salary Slip', struct, self.doc, self.doclist, "[['Salary Structure', 'Salary Slip'],['Salary Structure Earning', 'Salary Slip Earning'],['Salary Structure Deduction','Salary Slip Deduction']]")
diff --git a/erpnext/production/doctype/bom/bom.py b/erpnext/production/doctype/bom/bom.py
index 36df84e..81297b4 100644
--- a/erpnext/production/doctype/bom/bom.py
+++ b/erpnext/production/doctype/bom/bom.py
@@ -322,7 +322,7 @@
def add_to_flat_bom_detail(self, is_submit = 0):
"Add items to Flat BOM table"
- self.doc.clear_table(self.doclist, 'flat_bom_details', 1)
+ self.doclist = self.doc.clear_table(self.doclist, 'flat_bom_details', 1)
for d in self.cur_flat_bom_items:
ch = addchild(self.doc, 'flat_bom_details', 'BOM Explosion Item', 1, self.doclist)
for i in d.keys():
diff --git a/erpnext/production/doctype/production_planning_tool/production_planning_tool.py b/erpnext/production/doctype/production_planning_tool/production_planning_tool.py
index d910a20..21ef599 100644
--- a/erpnext/production/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/production/doctype/production_planning_tool/production_planning_tool.py
@@ -58,13 +58,13 @@
def clear_so_table(self):
""" Clears sales order table"""
- self.doc.clear_table(self.doclist, 'pp_so_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'pp_so_details')
def clear_item_table(self):
""" Clears item table"""
- self.doc.clear_table(self.doclist, 'pp_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'pp_details')
diff --git a/erpnext/projects/doctype/project_activity/project_activity.js b/erpnext/projects/doctype/project_activity/project_activity.js
index 46531b7..ad33e3c 100644
--- a/erpnext/projects/doctype/project_activity/project_activity.js
+++ b/erpnext/projects/doctype/project_activity/project_activity.js
@@ -95,5 +95,5 @@
cur_frm.mylist.run();
}
- $c_obj([doc],'add_update','',callback);
+ $c_obj(make_doclist(doc.doctype, doc.name),'add_update','',callback);
}
diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js
index 389dce0..57f2bee 100644
--- a/erpnext/selling/doctype/lead/lead.js
+++ b/erpnext/selling/doctype/lead/lead.js
@@ -87,7 +87,7 @@
// ===============================================================
cur_frm.cscript['Create Customer'] = function(){
var doc = cur_frm.doc;
- $c('runserverobj',args={ 'method':'check_status', 'docs':compress_doclist([doc])},
+ $c('runserverobj',args={ 'method':'check_status', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message == 'Converted'){
msgprint("This lead is already converted to customer");
@@ -124,7 +124,7 @@
// ===============================================================
cur_frm.cscript['Create Opportunity'] = function(){
var doc = cur_frm.doc;
- $c('runserverobj',args={ 'method':'check_status', 'docs':compress_doclist([doc])},
+ $c('runserverobj',args={ 'method':'check_status', 'docs':compress_doclist(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");
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index e444a66..9a45c70 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -50,10 +50,9 @@
}
}
cur_frm.cscript.make_communication_body();
-
}
-cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
+cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
var callback = function(doc, dt, dn) {
// defined in sales_common.js
cur_frm.cscript.update_item_details(doc, dt, dn);
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 5756710..c0306e8 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -53,7 +53,7 @@
# Pull Opportunity Details
# --------------------
def pull_enq_details(self):
- self.doc.clear_table(self.doclist, 'quotation_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'quotation_details')
get_obj('DocType Mapper', 'Opportunity-Quotation').dt_map('Opportunity', 'Quotation', self.doc.enq_no, self.doc, self.doclist, "[['Opportunity', 'Quotation'],['Opportunity Item', 'Quotation Item']]")
self.get_adj_percent()
@@ -81,12 +81,19 @@
obj = get_obj('Sales Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
- arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'),
- 'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')};
- ret = obj.get_item_defaults(arg)
- for r in ret:
- if not doc.fields.get(r):
- doc.fields[r] = ret[r]
+ arg = {
+ 'item_code': doc.fields.get('item_code'),
+ 'income_account': doc.fields.get('income_account'),
+ 'cost_center': doc.fields.get('cost_center'),
+ 'warehouse': doc.fields.get('warehouse')
+ }
+ fields_dict = obj.get_item_details(arg, self)
+ if fields_dict:
+ doc.fields.update(fields_dict)
+ #ret = obj.get_item_defaults(arg)
+ #for r in ret:
+ # if not doc.fields.get(r):
+ # doc.fields[r] = ret[r]
# Re-calculates Basic Rate & amount based on Price List Selected
@@ -108,12 +115,12 @@
# Load Default Charges
# ----------------------------------------------------------
def load_default_taxes(self):
- return get_obj('Sales Common').load_default_taxes(self)
+ self.doclist = get_obj('Sales Common').load_default_taxes(self)
# Pull details from other charges master (Get Sales Taxes and Charges Master)
# ----------------------------------------------------------
def get_other_charges(self):
- return get_obj('Sales Common').get_other_charges(self)
+ self.doclist = get_obj('Sales Common').get_other_charges(self)
# GET TERMS AND CONDITIONS
diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py
index f942a2f..fdd7013 100644
--- a/erpnext/selling/doctype/sales_common/sales_common.py
+++ b/erpnext/selling/doctype/sales_common/sales_common.py
@@ -72,9 +72,11 @@
# Get Sales Person Details
# ==========================
+
+ # TODO: To be deprecated if not in use
def get_sales_person_details(self, obj):
if obj.doc.doctype != 'Quotation':
- obj.doc.clear_table(obj.doclist,'sales_team')
+ obj.doclist = obj.doc.clear_table(obj.doclist,'sales_team')
idx = 0
for d in webnotes.conn.sql("select sales_person, allocated_percentage, allocated_amount, incentives from `tabSales Team` where parent = '%s'" % obj.doc.customer):
ch = addchild(obj.doc, 'sales_team', 'Sales Team', 1, obj.doclist)
@@ -84,6 +86,7 @@
ch.incentives = d and flt(d[3]) or 0
ch.idx = idx
idx += 1
+ return obj.doclist
# Get customer's contact person details
@@ -215,15 +218,15 @@
# ====================
def load_default_taxes(self, obj):
if cstr(obj.doc.charge):
- self.get_other_charges(obj)
+ return self.get_other_charges(obj)
else:
- self.get_other_charges(obj, 1)
+ return self.get_other_charges(obj, 1)
# Get other charges from Master
# =================================================================================
def get_other_charges(self,obj, default=0):
- obj.doc.clear_table(obj.doclist,'other_charges')
+ obj.doclist = obj.doc.clear_table(obj.doclist, 'other_charges')
if not getlist(obj.doclist, 'other_charges'):
if default: add_cond = 'ifnull(t2.is_default,0) = 1'
else: add_cond = 't1.parent = "'+cstr(obj.doc.charge)+'"'
@@ -253,6 +256,7 @@
d.included_in_print_rate = cint(d.included_in_print_rate)
d.idx = idx
idx += 1
+ return obj.doclist
# Get TERMS AND CONDITIONS
# =======================================================================================
@@ -484,11 +488,22 @@
self.cleanup_packing_list(obj, parent_items)
def cleanup_packing_list(self, obj, parent_items):
- """Remove all those parent items which are no longer present in main item table"""
+ """Remove all those child items which are no longer present in main item table"""
+ delete_list = []
for d in getlist(obj.doclist, 'packing_details'):
if [d.parent_item, d.parent_detail_docname] not in parent_items:
- d.parent = ''
+ # mark for deletion from doclist
+ delete_list.append(d.name)
+ if not delete_list: return
+
+ # delete from doclist
+ obj.doclist = filter(lambda d: d.name not in delete_list, obj.doclist)
+
+ # delete from db
+ webnotes.conn.sql("""\
+ delete from `tabDelivery Note Packing Item`
+ where name in ("%s")""" % '", "'.join(delete_list))
# Get total in words
# ==================================================================
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 660a288..9cb1b4a 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -35,8 +35,9 @@
from utilities.transaction_base import TransactionBase
class DocType(TransactionBase):
- def __init__(self, doc, doclist=[]):
+ def __init__(self, doc, doclist=None):
self.doc = doc
+ if not doclist: doclist = []
self.doclist = doclist
self.tname = 'Sales Order Item'
self.fname = 'sales_order_details'
@@ -55,10 +56,10 @@
# Pull Quotation Items
# -----------------------
def pull_quotation_details(self):
- self.doc.clear_table(self.doclist, 'other_charges')
- self.doc.clear_table(self.doclist, 'sales_order_details')
- self.doc.clear_table(self.doclist, 'sales_team')
- self.doc.clear_table(self.doclist, 'tc_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'other_charges')
+ self.doclist = self.doc.clear_table(self.doclist, 'sales_order_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'sales_team')
+ self.doclist = self.doc.clear_table(self.doclist, 'tc_details')
if self.doc.quotation_no:
get_obj('DocType Mapper', 'Quotation-Sales Order').dt_map('Quotation', 'Sales Order', self.doc.quotation_no, self.doc, self.doclist, "[['Quotation', 'Sales Order'],['Quotation Item', 'Sales Order Item'],['Sales Taxes and Charges','Sales Taxes and Charges'],['Sales Team','Sales Team'],['TC Detail','TC Detail']]")
else:
@@ -135,12 +136,12 @@
# Load Default Charges
# ----------------------------------------------------------
def load_default_taxes(self):
- return get_obj('Sales Common').load_default_taxes(self)
+ self.doclist = get_obj('Sales Common').load_default_taxes(self)
# Pull details from other charges master (Get Sales Taxes and Charges Master)
# ----------------------------------------------------------
def get_other_charges(self):
- return get_obj('Sales Common').get_other_charges(self)
+ self.doclist = get_obj('Sales Common').get_other_charges(self)
# GET TERMS & CONDITIONS
@@ -322,7 +323,7 @@
# this is to verify that the allocated % of sales persons is 100%
sales_com_obj.get_allocated_sum(self)
sales_com_obj.make_packing_list(self,'sales_order_details')
-
+
# get total in words
dcc = TransactionBase().get_company_currency(self.doc.company)
self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total)
diff --git a/erpnext/setup/doctype/contact_control/contact_control.js b/erpnext/setup/doctype/contact_control/contact_control.js
index 1d17244..a07fd83 100755
--- a/erpnext/setup/doctype/contact_control/contact_control.js
+++ b/erpnext/setup/doctype/contact_control/contact_control.js
@@ -55,7 +55,7 @@
// get sates on country trigger
// -----------------------------
cur_frm.cscript.get_states=function(doc,dt,dn){
- $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist([doc])},
+ $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message) {
set_field_options('state', r.message);
diff --git a/erpnext/setup/doctype/naming_series/naming_series.js b/erpnext/setup/doctype/naming_series/naming_series.js
index c7897e44..7e702c4 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.js
+++ b/erpnext/setup/doctype/naming_series/naming_series.js
@@ -19,7 +19,7 @@
var callback = function(r, rt){
set_field_options('select_doc_for_series', r.message);
}
- $c_obj([doc],'get_transactions','',callback);
+ $c_obj(make_doclist(doc.doctype, doc.name),'get_transactions','',callback);
cur_frm.cscript.refresh();
// add page head
//var ph = new PageHeader(cur_frm.fields_dict['head_html'].wrapper, 'Setup Series', 'Set prefix for numbering series on your transactions');
@@ -36,5 +36,5 @@
refresh_field('set_options');
}
- $c_obj([doc],'get_options','',callback)
+ $c_obj(make_doclist(doc.doctype, doc.name),'get_options','',callback)
}
diff --git a/erpnext/setup/doctype/price_list/price_list.js b/erpnext/setup/doctype/price_list/price_list.js
index 9b7f741..a222a65 100644
--- a/erpnext/setup/doctype/price_list/price_list.js
+++ b/erpnext/setup/doctype/price_list/price_list.js
@@ -32,6 +32,6 @@
cur_frm.cscript.clear_prices = function(doc, cdt, cdn) {
if(confirm("This action will clear all rates for '"+ doc.name +"' from the Item Master and cannot be un-done. Are you sure you want to continue?")) {
- $c_obj([doc], 'clear_prices', '', function(r, rt) { });
+ $c_obj(make_doclist(doc.doctype, doc.name), 'clear_prices', '', function(r, rt) { });
}
}
diff --git a/erpnext/setup/doctype/sales_person/sales_person.js b/erpnext/setup/doctype/sales_person/sales_person.js
index b0419bd..453d88a 100644
--- a/erpnext/setup/doctype/sales_person/sales_person.js
+++ b/erpnext/setup/doctype/sales_person/sales_person.js
@@ -26,7 +26,7 @@
}
cur_frm.cscript.country = function(doc, cdt, cdn) {
var mydoc=doc;
- $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist([doc])},
+ $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message) {
var doc = locals[mydoc.doctype][mydoc.name];
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 9c640f4..5d551bb 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -65,7 +65,7 @@
# *************** Pull Sales Order Items ************************
def pull_sales_order_details(self):
self.validate_prev_docname()
- self.doc.clear_table(self.doclist,'other_charges')
+ self.doclist = self.doc.clear_table(self.doclist,'other_charges')
if self.doc.sales_order_no:
get_obj('DocType Mapper', 'Sales Order-Delivery Note').dt_map('Sales Order', 'Delivery Note', self.doc.sales_order_no, self.doc, self.doclist, "[['Sales Order', 'Delivery Note'],['Sales Order Item', 'Delivery Note Item'],['Sales Taxes and Charges','Sales Taxes and Charges'],['Sales Team','Sales Team']]")
@@ -151,12 +151,12 @@
# Load Default Charges
# ----------------------------------------------------------
def load_default_taxes(self):
- return get_obj('Sales Common').load_default_taxes(self)
+ self.doclist = get_obj('Sales Common').load_default_taxes(self)
# **** Pull details from other charges master (Get Sales Taxes and Charges Master) ****
def get_other_charges(self):
- return get_obj('Sales Common').get_other_charges(self)
+ self.doclist = get_obj('Sales Common').get_other_charges(self)
#check in manage account if sales order required or not.
diff --git a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
index 6123ac2..c2df6c1 100644
--- a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
+++ b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
@@ -43,7 +43,7 @@
def get_purchase_receipts(self):
""" Get purchase receipts for given period """
- self.doc.clear_table(self.doclist,'lc_pr_details',1)
+ self.doclist = self.doc.clear_table(self.doclist,'lc_pr_details',1)
self.check_mandatory()
pr = sql("select name from `tabPurchase Receipt` where docstatus = 1 and posting_date >= '%s' and posting_date <= '%s' and currency = '%s' order by name " % (self.doc.from_pr_date, self.doc.to_pr_date, self.doc.currency), as_dict = 1)
@@ -58,7 +58,7 @@
def get_landed_cost_master_details(self):
""" pull details from landed cost master"""
- self.doc.clear_table(self.doclist, 'landed_cost_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'landed_cost_details')
idx = 0
landed_cost = sql("select account_head, description from `tabLanded Cost Master Detail` where parent=%s", (self.doc.landed_cost), as_dict = 1)
for cost in landed_cost:
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index f6ff505..10fecbf 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -370,7 +370,7 @@
raise Exception
self.add_bom(d)
else:
- self.doc.clear_table(self.doclist,'pr_raw_material_details',1)
+ self.doclist = self.doc.clear_table(self.doclist,'pr_raw_material_details',1)
self.doc.save()
elif item_det[0][1] == 'No':
if not self.doc.supplier_warehouse:
@@ -479,4 +479,4 @@
# **** Pull details from other charges master (Get Other Charges) ****
def get_purchase_tax_details(self):
- return get_obj('Purchase Common').get_purchase_tax_details(self)
+ self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self)
diff --git a/erpnext/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py b/erpnext/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
index 414198a..00319bd 100644
--- a/erpnext/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
+++ b/erpnext/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
@@ -57,7 +57,7 @@
# Create Item Table
# -----------------------------
def create_item_table(self, det):
- self.doc.clear_table(self.doclist, 'return_details', 1)
+ self.doclist = self.doc.clear_table(self.doclist, 'return_details', 1)
for i in det:
ch = addchild(self.doc, 'return_details', 'Sales and Purchase Return Item', 1, self.doclist)
ch.detail_name = i and i[0] or ''
@@ -73,5 +73,5 @@
# Clear return table
# --------------------------------
def clear_return_table(self):
- self.doc.clear_table(self.doclist, 'return_details', 1)
+ self.doclist = self.doc.clear_table(self.doclist, 'return_details', 1)
self.doc.save()
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index dd6588a..1cc49f8 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -240,7 +240,7 @@
consider_sa_items_as_rm = self.doc.consider_sa_items_as_raw_materials
self.get_raw_materials(bom_no, fg_qty, consider_sa_items_as_rm)
- self.doc.clear_table(self.doclist, 'mtn_details', 1)
+ self.doclist = self.doc.clear_table(self.doclist, 'mtn_details', 1)
sw = (self.doc.process == 'Backflush') and cstr(pro_obj.doc.wip_warehouse) or ''
tw = (self.doc.process == 'Material Transfer') and cstr(pro_obj.doc.wip_warehouse) or ''
diff --git a/erpnext/stock/doctype/warehouse/warehouse.js b/erpnext/stock/doctype/warehouse/warehouse.js
index cf0d4a0..b218063 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.js
+++ b/erpnext/stock/doctype/warehouse/warehouse.js
@@ -16,7 +16,7 @@
cur_frm.cscript.country = function(doc, cdt, cdn) {
var mydoc=doc;
- $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist([doc])},
+ $c('runserverobj', args={'method':'check_state', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message) {
var doc = locals[mydoc.doctype][mydoc.name];
diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
index 27ec01e..9ad9eb9 100644
--- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -42,8 +42,8 @@
# pull sales order details
#--------------------------
def pull_sales_order_detail(self):
- self.doc.clear_table(self.doclist, 'item_maintenance_detail')
- self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
+ self.doclist = self.doc.clear_table(self.doclist, 'item_maintenance_detail')
+ self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
self.doclist = get_obj('DocType Mapper', 'Sales Order-Maintenance Schedule').dt_map('Sales Order', 'Maintenance Schedule', self.doc.sales_order_no, self.doc, self.doclist, "[['Sales Order', 'Maintenance Schedule'],['Sales Order Item', 'Maintenance Schedule Item']]")
#pull item details
@@ -60,7 +60,7 @@
#-------------------------------------
def generate_schedule(self):
import datetime
- self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
+ self.doclist = self.doc.clear_table(self.doclist, 'maintenance_schedule_detail')
count = 0
sql("delete from `tabMaintenance Schedule Detail` where parent='%s'" %(self.doc.name))
for d in getlist(self.doclist, 'item_maintenance_detail'):
diff --git a/erpnext/support/doctype/maintenance_visit/maintenance_visit.py b/erpnext/support/doctype/maintenance_visit/maintenance_visit.py
index 70b39ec..fd0c414 100644
--- a/erpnext/support/doctype/maintenance_visit/maintenance_visit.py
+++ b/erpnext/support/doctype/maintenance_visit/maintenance_visit.py
@@ -56,7 +56,7 @@
msgprint("You can not fetch details of both, Sales Order and Customer Issue, in same Maintenance Visit")
raise Exception
- self.doc.clear_table(self.doclist, 'maintenance_visit_details')
+ self.doclist = self.doc.clear_table(self.doclist, 'maintenance_visit_details')
if self.doc.sales_order_no:
self.doclist = get_obj('DocType Mapper', 'Sales Order-Maintenance Visit').dt_map('Sales Order', 'Maintenance Visit', self.doc.sales_order_no, self.doc, self.doclist, "[['Sales Order', 'Maintenance Visit'],['Sales Order Item', 'Maintenance Visit Purpose']]")
diff --git a/erpnext/support/doctype/support_ticket/support_ticket.js b/erpnext/support/doctype/support_ticket/support_ticket.js
index 48c80b5..c9c9ea1 100644
--- a/erpnext/support/doctype/support_ticket/support_ticket.js
+++ b/erpnext/support/doctype/support_ticket/support_ticket.js
@@ -99,7 +99,7 @@
},
send: function(doc, dt, dn) {
- $c_obj([doc], 'send_response', '', function(r,rt) {
+ $c_obj(make_doclist(doc.doctype, doc.name), 'send_response', '', function(r,rt) {
locals[dt][dn].new_response = '';
if(!(r.exc || r.server_messages)) {
cur_frm.refresh();
@@ -124,7 +124,7 @@
var answer = confirm("Close Ticket "+doc.name+"?\n\nAllocated To: "+doc.allocated_to+"\n\nSubject: "+doc.subject+"");
if(answer) {
if(doc.name)
- $c_obj([doc],'close_ticket','',function(r,rt) {
+ $c_obj(make_doclist(doc.doctype, doc.name),'close_ticket','',function(r,rt) {
if(!r.exc) {
cur_frm.refresh();
}
@@ -138,7 +138,7 @@
var answer = confirm("Re-Open Ticket "+doc.name+"?\n\nAllocated To: "+doc.allocated_to+"\n\nSubject: "+doc.subject+"");
if(answer) {
if(doc.name)
- $c_obj([doc],'reopen_ticket','',function(r,rt) {
+ $c_obj(make_doclist(doc.doctype, doc.name),'reopen_ticket','',function(r,rt) {
if(!r.exc) {
cur_frm.refresh();
}
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 2a0183a..88ed823 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -214,7 +214,7 @@
# Get Sales Person Details of Customer
# ------------------------------------
def get_sales_person(self, name):
- self.doc.clear_table(self.doclist,'sales_team')
+ self.doclist = self.doc.clear_table(self.doclist,'sales_team')
idx = 0
for d in webnotes.conn.sql("select sales_person, allocated_percentage, allocated_amount, incentives from `tabSales Team` where parent = '%s'" % name):
ch = addchild(self.doc, 'sales_team', 'Sales Team', 1, self.doclist)
diff --git a/public/js/all-app.js b/public/js/all-app.js
index dbdc42f..384f8f9 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -396,7 +396,7 @@
return;}
if(r.server_messages)msgprint(r.server_messages)
if(r.exc){console.log(r.exc);};if(r['403']){wn.container.change_to('403');}
-if(r.docs)LocalDB.sync(r.docs);}
+if(r.docs){LocalDB.sync(r.docs);}}
wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
if(opts.error)opts.error(xhr)}})}
wn.call=function(opts){var args=$.extend({},opts.args)
@@ -735,19 +735,20 @@
$(me.btn2).css('display','inline-block');else $dh(me.btn2);}}
me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;}
me.get_value=function(){return me.txt.value;}
-$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display)
-return;me.set_input_value('');}})}
+$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){var val=$(this).val();me.set_input_value_executed=false;if(!val){if(selector&&selector.display)
+return;me.set_input_value('');}else{setTimeout(function(){if(!me.set_input_value_executed){me.set_input_value(val);}},100);}})}
LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm)
var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}}
LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);}
if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}}
me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}}
_f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}}
-LinkField.prototype.set_input_value=function(val){var me=this;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
+LinkField.prototype.set_input_value=function(val){var me=this;me.set_input_value_executed=true;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
if(cur_frm){if(val==locals[me.doctype][me.docname][me.df.fieldname]){me.run_trigger();return;}}
me.set(val);if(_f.cur_grid_cell)
_f.cur_grid_cell.grid.cell_deselect();if(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;}
-var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
+me.validate_link(val,from_selector);}
+LinkField.prototype.validate_link=function(val,from_selector){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
fetch=cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');$c('webnotes.widgets.form.utils.validate_link',{'value':val,'options':me.df.options,'fetch':fetch},function(r,rt){if(r.message=='Ok'){if($(me.txt).val()!=val){if((me.grid&&!from_selector)||(!me.grid)){$(me.txt).val(val);}}
if(r.fetch_values)
me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)})
@@ -1313,8 +1314,10 @@
LocalDB.delete_doc=function(dt,dn){var doc=get_local(dt,dn);for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||doc.__oldparent==dn)){delete locals[ndt][ndn];}}}}
delete locals[dt][dn];}
function get_local(dt,dn){return locals[dt]?locals[dt][dn]:null;}
-LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
+LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);if(list){LocalDB.clear_locals(list[0].doctype,list[0].name);}
+for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
+LocalDB.clear_locals=function(dt,dn){var doclist=make_doclist(dt,dn,1);$.each(doclist,function(i,v){v&&delete locals[v.doctype][v.name];});}
local_name_idx={};LocalDB.get_localname=function(doctype){if(!local_name_idx[doctype])local_name_idx[doctype]=1;var n='New '+get_doctype_label(doctype)+' '+local_name_idx[doctype];local_name_idx[doctype]++;return n;}
LocalDB.set_default_values=function(doc){var doctype=doc.doctype;var docfields=wn.meta.docfield_list[doctype];if(!docfields){return;}
var fields_to_refresh=[];for(var fid=0;fid<docfields.length;fid++){var f=docfields[fid];if(!in_list(no_value_fields,f.fieldtype)&&doc[f.fieldname]==null){var v=LocalDB.get_default_value(f.fieldname,f.fieldtype,f['default']);if(v){doc[f.fieldname]=v;fields_to_refresh.push(f.fieldname);}}}
@@ -1344,7 +1347,8 @@
LocalDB.add_child=function(doc,childtype,parentfield){var n=LocalDB.create(childtype);var d=locals[childtype][n];d.parent=doc.name;d.parentfield=parentfield;d.parenttype=doc.doctype;return d;}
LocalDB.no_copy_list=['amended_from','amendment_date','cancel_reason'];LocalDB.copy=function(dt,dn,from_amend){var newdoc=LocalDB.create(dt);for(var key in locals[dt][dn]){var df=get_field(dt,key);if(key!=='name'&&key.substr(0,2)!='__'&&!(df&&((!from_amend&&cint(df.no_copy)==1)||in_list(LocalDB.no_copy_list,df.fieldname)))){locals[dt][newdoc][key]=locals[dt][dn][key];}}
return locals[dt][newdoc];}
-function make_doclist(dt,dn,deleted){var dl=[];dl[0]=locals[dt][dn];for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||(deleted&&doc.__oldparent==dn))){dl[dl.length]=doc;}}}}
+function make_doclist(dt,dn,deleted){if(!locals[dt]){return[];}
+var dl=[];dl[0]=locals[dt][dn];for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||(deleted&&doc.__oldparent==dn))){dl[dl.length]=doc;}}}}
return dl;}
var Meta={};var local_dt={};Meta.make_local_dt=function(dt,dn){var dl=make_doclist('DocType',dt);if(!local_dt[dt])local_dt[dt]={};if(!local_dt[dt][dn])local_dt[dt][dn]={};for(var i=0;i<dl.length;i++){var d=dl[i];if(d.doctype=='DocField'){var key=d.fieldname?d.fieldname:d.label;local_dt[dt][dn][key]=copy_dict(d);}}}
Meta.get_field=function(dt,fn,dn){if(dn&&local_dt[dt]&&local_dt[dt][dn]){return local_dt[dt][dn][fn];}else{if(wn.meta.docfield_map[dt])var d=wn.meta.docfield_map[dt][fn];if(d)return d;}
@@ -1559,19 +1563,20 @@
$(me.btn2).css('display','inline-block');else $dh(me.btn2);}}
me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;}
me.get_value=function(){return me.txt.value;}
-$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display)
-return;me.set_input_value('');}})}
+$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){var val=$(this).val();me.set_input_value_executed=false;if(!val){if(selector&&selector.display)
+return;me.set_input_value('');}else{setTimeout(function(){if(!me.set_input_value_executed){me.set_input_value(val);}},100);}})}
LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm)
var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}}
LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);}
if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}}
me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}}
_f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}}
-LinkField.prototype.set_input_value=function(val){var me=this;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
+LinkField.prototype.set_input_value=function(val){var me=this;me.set_input_value_executed=true;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
if(cur_frm){if(val==locals[me.doctype][me.docname][me.df.fieldname]){me.run_trigger();return;}}
me.set(val);if(_f.cur_grid_cell)
_f.cur_grid_cell.grid.cell_deselect();if(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;}
-var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
+me.validate_link(val,from_selector);}
+LinkField.prototype.validate_link=function(val,from_selector){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
fetch=cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');$c('webnotes.widgets.form.utils.validate_link',{'value':val,'options':me.df.options,'fetch':fetch},function(r,rt){if(r.message=='Ok'){if($(me.txt).val()!=val){if((me.grid&&!from_selector)||(!me.grid)){$(me.txt).val(val);}}
if(r.fetch_values)
me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)})
@@ -2114,7 +2119,7 @@
refresh_field(fl[i],dn,args.table_field);else
refresh_field(fl[i]);}}
$c('webnotes.widgets.form.utils.get_fields',args,call_back);}
-get_server_fields=function(method,arg,table_field,doc,dt,dn,allow_edit,call_back){if(!allow_edit)freeze('Fetching Data...');$c('runserverobj',args={'method':method,'docs':compress_doclist([doc]),'arg':arg},function(r,rt){if(r.message){var d=locals[dt][dn];var field_dict=r.message;for(var key in field_dict){d[key]=field_dict[key];if(table_field)refresh_field(key,d.name,table_field);else refresh_field(key);}}
+get_server_fields=function(method,arg,table_field,doc,dt,dn,allow_edit,call_back){if(!allow_edit)freeze('Fetching Data...');$c('runserverobj',args={'method':method,'docs':compress_doclist(make_doclist(doc.doctype,doc.name)),'arg':arg},function(r,rt){if(r.message){var d=locals[dt][dn];var field_dict=r.message;for(var key in field_dict){d[key]=field_dict[key];if(table_field)refresh_field(key,d.name,table_field);else refresh_field(key);}}
if(call_back){doc=locals[doc.doctype][doc.name];call_back(doc,dt,dn);}
if(!allow_edit)unfreeze();});}
set_multiple=function(dt,dn,dict,table_field){var d=locals[dt][dn];for(var key in dict){d[key]=dict[key];if(table_field)refresh_field(key,d.name,table_field);else refresh_field(key);}}
diff --git a/public/js/all-web.js b/public/js/all-web.js
index c4cc240..de09c32 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -283,7 +283,7 @@
return;}
if(r.server_messages)msgprint(r.server_messages)
if(r.exc){console.log(r.exc);};if(r['403']){wn.container.change_to('403');}
-if(r.docs)LocalDB.sync(r.docs);}
+if(r.docs){LocalDB.sync(r.docs);}}
wn.request.call=function(opts){wn.request.prepare(opts);$.ajax({url:opts.url||wn.request.url,data:opts.args,type:opts.type||'POST',dataType:opts.dataType||'json',success:function(r,xhr){wn.request.cleanup(opts,r);opts.success(r,xhr.responseText);},error:function(xhr,textStatus){wn.request.cleanup(opts,{});show_alert('Unable to complete request: '+textStatus)
if(opts.error)opts.error(xhr)}})}
wn.call=function(opts){var args=$.extend({},opts.args)
@@ -626,8 +626,10 @@
LocalDB.delete_doc=function(dt,dn){var doc=get_local(dt,dn);for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||doc.__oldparent==dn)){delete locals[ndt][ndn];}}}}
delete locals[dt][dn];}
function get_local(dt,dn){return locals[dt]?locals[dt][dn]:null;}
-LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
+LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);if(list){LocalDB.clear_locals(list[0].doctype,list[0].name);}
+for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
+LocalDB.clear_locals=function(dt,dn){var doclist=make_doclist(dt,dn,1);$.each(doclist,function(i,v){v&&delete locals[v.doctype][v.name];});}
local_name_idx={};LocalDB.get_localname=function(doctype){if(!local_name_idx[doctype])local_name_idx[doctype]=1;var n='New '+get_doctype_label(doctype)+' '+local_name_idx[doctype];local_name_idx[doctype]++;return n;}
LocalDB.set_default_values=function(doc){var doctype=doc.doctype;var docfields=wn.meta.docfield_list[doctype];if(!docfields){return;}
var fields_to_refresh=[];for(var fid=0;fid<docfields.length;fid++){var f=docfields[fid];if(!in_list(no_value_fields,f.fieldtype)&&doc[f.fieldname]==null){var v=LocalDB.get_default_value(f.fieldname,f.fieldtype,f['default']);if(v){doc[f.fieldname]=v;fields_to_refresh.push(f.fieldname);}}}
@@ -657,7 +659,8 @@
LocalDB.add_child=function(doc,childtype,parentfield){var n=LocalDB.create(childtype);var d=locals[childtype][n];d.parent=doc.name;d.parentfield=parentfield;d.parenttype=doc.doctype;return d;}
LocalDB.no_copy_list=['amended_from','amendment_date','cancel_reason'];LocalDB.copy=function(dt,dn,from_amend){var newdoc=LocalDB.create(dt);for(var key in locals[dt][dn]){var df=get_field(dt,key);if(key!=='name'&&key.substr(0,2)!='__'&&!(df&&((!from_amend&&cint(df.no_copy)==1)||in_list(LocalDB.no_copy_list,df.fieldname)))){locals[dt][newdoc][key]=locals[dt][dn][key];}}
return locals[dt][newdoc];}
-function make_doclist(dt,dn,deleted){var dl=[];dl[0]=locals[dt][dn];for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||(deleted&&doc.__oldparent==dn))){dl[dl.length]=doc;}}}}
+function make_doclist(dt,dn,deleted){if(!locals[dt]){return[];}
+var dl=[];dl[0]=locals[dt][dn];for(var ndt in locals){if(locals[ndt]){for(var ndn in locals[ndt]){var doc=locals[ndt][ndn];if(doc&&doc.parenttype==dt&&(doc.parent==dn||(deleted&&doc.__oldparent==dn))){dl[dl.length]=doc;}}}}
return dl;}
var Meta={};var local_dt={};Meta.make_local_dt=function(dt,dn){var dl=make_doclist('DocType',dt);if(!local_dt[dt])local_dt[dt]={};if(!local_dt[dt][dn])local_dt[dt][dn]={};for(var i=0;i<dl.length;i++){var d=dl[i];if(d.doctype=='DocField'){var key=d.fieldname?d.fieldname:d.label;local_dt[dt][dn][key]=copy_dict(d);}}}
Meta.get_field=function(dt,fn,dn){if(dn&&local_dt[dt]&&local_dt[dt][dn]){return local_dt[dt][dn][fn];}else{if(wn.meta.docfield_map[dt])var d=wn.meta.docfield_map[dt][fn];if(d)return d;}
diff --git a/public/js/fields.js b/public/js/fields.js
index dba9e5c..dbd77c0 100644
--- a/public/js/fields.js
+++ b/public/js/fields.js
@@ -98,19 +98,20 @@
$(me.btn2).css('display','inline-block');else $dh(me.btn2);}}
me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;}
me.get_value=function(){return me.txt.value;}
-$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display)
-return;me.set_input_value('');}})}
+$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('<li></li>').data('item.autocomplete',item).append(repl('<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>',item)).appendTo(ul);};$(this.txt).change(function(){var val=$(this).val();me.set_input_value_executed=false;if(!val){if(selector&&selector.display)
+return;me.set_input_value('');}else{setTimeout(function(){if(!me.set_input_value_executed){me.set_input_value(val);}},100);}})}
LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm)
var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}}
LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);}
if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}}
me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}}
_f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}}
-LinkField.prototype.set_input_value=function(val){var me=this;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
+LinkField.prototype.set_input_value=function(val){var me=this;me.set_input_value_executed=true;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;}
if(cur_frm){if(val==locals[me.doctype][me.docname][me.df.fieldname]){me.run_trigger();return;}}
me.set(val);if(_f.cur_grid_cell)
_f.cur_grid_cell.grid.cell_deselect();if(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;}
-var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
+me.validate_link(val,from_selector);}
+LinkField.prototype.validate_link=function(val,from_selector){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname])
fetch=cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');$c('webnotes.widgets.form.utils.validate_link',{'value':val,'options':me.df.options,'fetch':fetch},function(r,rt){if(r.message=='Ok'){if($(me.txt).val()!=val){if((me.grid&&!from_selector)||(!me.grid)){$(me.txt).val(val);}}
if(r.fetch_values)
me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)})