[selling/buying] [fixes] updated js files of various doctypes related to selling/g/buying

This commit is contained in:
Anand Doshi
2013-05-27 19:29:07 +05:30
parent 149b461e62
commit fc77718a3d
21 changed files with 451 additions and 1290 deletions

View File

@@ -20,75 +20,36 @@ cur_frm.cscript.fname = "delivery_note_details";
cur_frm.cscript.other_fname = "other_charges";
cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.js');
// ONLOAD
// ================================================================================================
cur_frm.cscript.onload = function(doc, dt, dn) {
cur_frm.cscript.manage_rounded_total();
if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(!doc.transaction_date) set_multiple(dt,dn,{transaction_date:get_today()});
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
if(doc.__islocal && doc.customer) cur_frm.cscript.customer(doc,dt,dn,onload=true);
if(!doc.price_list_currency) {
set_multiple(dt, dn, {price_list_currency: doc.currency, plc_conversion_rate:1});
}
wn.provide("erpnext.stock");
erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({
refresh: function(doc, dt, dn) {
this._super();
if(doc.__islocal){
hide_field(['customer_address', 'contact_person', 'customer_name',
'address_display', 'contact_display', 'contact_mobile',
'contact_email', 'territory', 'customer_group']);
}
}
// REFRESH
// ================================================================================================
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.clear_custom_buttons();
erpnext.hide_naming_series();
if(flt(doc.per_billed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn);
if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Installation Note', cur_frm.cscript['Make Installation Note']);
if(flt(doc.per_billed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
if (doc.docstatus==1) cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
if(doc.docstatus==0 && !doc.__islocal) {
cur_frm.add_custom_button('Make Packing Slip', cur_frm.cscript['Make Packing Slip']);
}
if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Installation Note', cur_frm.cscript['Make Installation Note']);
if (doc.docstatus==1) cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
if(doc.docstatus==0 && !doc.__islocal) {
cur_frm.add_custom_button('Make Packing Slip', cur_frm.cscript['Make Packing Slip']);
set_print_hide(doc, dt, dn);
// unhide expense_account and cost_center is auto_inventory_accounting enabled
var aii_enabled = cint(sys_defaults.auto_inventory_accounting)
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("expense_account", aii_enabled);
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("cost_center", aii_enabled);
}
cur_frm.toggle_display("contact_info", doc.customer);
set_print_hide(doc, cdt, cdn);
// unhide expense_account and cost_center is auto_inventory_accounting enabled
var aii_enabled = cint(sys_defaults.auto_inventory_accounting)
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("expense_account", aii_enabled);
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("cost_center", aii_enabled);
}
});
//customer
cur_frm.cscript.customer = function(doc,dt,dn,onload) {
cur_frm.toggle_display("contact_info", doc.customer);
var pl = doc.price_list_name;
var callback = function(r,rt) {
var doc = locals[cur_frm.doctype][cur_frm.docname];
if(doc.customer)
unhide_field(['customer_address','contact_person','territory','customer_group']);
cur_frm.refresh();
if(!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn);
}
var args = onload ? 'onload':''
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name),
'get_default_customer_shipping_address', args, callback);
}
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.stock.DeliveryNoteController({frm: cur_frm}));
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
@@ -148,11 +109,6 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) {
return repl('SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "%(company)s" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_delivered,0) < 99.99 and %(cond)s `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50', {company:doc.company,cond:cond})
}
cur_frm.cscript.delivery_type = function(doc, cdt, cdn) {
if (doc.delivery_type = 'Sample') cfn_set_fields(doc, cdt, cdn);
}
cur_frm.cscript.serial_no = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.serial_no) {
@@ -160,17 +116,6 @@ cur_frm.cscript.serial_no = function(doc, cdt, cdn) {
}
}
cur_frm.cscript.warehouse = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (! d.item_code) {alert("please enter item code first"); return};
if (d.warehouse) {
arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.warehouse +"'}";
get_server_fields('get_actual_qty',arg,'delivery_note_details',doc,cdt,cdn,1);
}
}
cur_frm.fields_dict['transporter_name'].get_query = function(doc) {
return 'SELECT DISTINCT `tabSupplier`.`name` FROM `tabSupplier` WHERE `tabSupplier`.supplier_type = "transporter" AND `tabSupplier`.docstatus != 2 AND `tabSupplier`.%(key)s LIKE "%s" ORDER BY `tabSupplier`.`name` LIMIT 50';
}

View File

@@ -34,6 +34,9 @@ class DocType(SellingController):
self.doclist = doclist
self.tname = 'Delivery Note Item'
self.fname = 'delivery_note_details'
def set_customer_defaults(self):
self.get_default_customer_shipping_address()
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
@@ -78,25 +81,6 @@ class DocType(SellingController):
def get_tc_details(self):
return get_obj('Sales Common').get_tc_details(self)
def get_item_details(self, args=None):
import json
args = args and json.loads(args) or {}
if args.get('item_code'):
return get_obj('Sales Common').get_item_details(args, self)
else:
obj = get_obj('Sales Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
arg = {
'item_code':doc.fields.get('item_code'),
'expense_account':doc.fields.get('expense_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]
def get_barcode_details(self, barcode):
return get_obj('Sales Common').get_barcode_details(barcode)
@@ -105,12 +89,6 @@ class DocType(SellingController):
"""Re-calculates Basic Rate & amount based on Price List Selected"""
get_obj('Sales Common').get_adj_percent(self)
def get_actual_qty(self,args):
"""Get Actual Qty of item in warehouse selected"""
return get_obj('Sales Common').get_available_qty(eval(args))
def get_rate(self,arg):
return get_obj('Sales Common').get_rate(arg)

View File

@@ -55,22 +55,7 @@ var new_cscript = new erpnext.buying.MaterialRequestController({frm: cur_frm});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new_cscript);
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
// second call
if(doc.__islocal){
cur_frm.cscript.get_item_defaults(doc);
}
};
cur_frm.cscript.get_item_defaults = function(doc) {
var ch = getchildren( 'Material Request Item', doc.name, 'indent_details');
if (flt(ch.length) > 0){
$c_obj(make_doclist(doc.doctype, doc.name), 'get_item_defaults', '', function(r, rt) {refresh_field('indent_details'); });
}
};
cur_frm.cscript.qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (flt(d.qty) < flt(d.min_order_qty))

View File

@@ -19,10 +19,11 @@ cur_frm.cscript.fname = "purchase_receipt_details";
cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
erpnext.buying.PurchaseReceiptController = erpnext.buying.BuyingController.extend({
wn.provide("erpnext.stock");
erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({
refresh: function() {
this._super();
@@ -37,29 +38,49 @@ erpnext.buying.PurchaseReceiptController = erpnext.buying.BuyingController.exten
if(wn.boot.control_panel.country == 'India') {
unhide_field(['challan_no', 'challan_date']);
}
},
},
received_qty: function(doc, cdt, cdn) {
var item = wn.model.get_doc(cdt, cdn);
wn.model.round_floats_in(item, ["qty", "received_qty"]);
item.qty = (item.qty < item.received_qty) ? item.qty : item.received_qty;
this.qty(doc, cdt, cdn);
},
qty: function(doc, cdt, cdn) {
var item = wn.model.get_doc(cdt, cdn);
wn.model.round_floats_in(item, ["qty", "received_qty"]);
if(item.qty > item.received_qty) {
msgprint(wn._("Error") + ": " + wn._(wn.meta.get_label(item.doctype, "qty", item.name))
+ " > " + wn._(wn.meta.get_label(item.doctype, "received_qty", item.name)));
item.qty = item.rejected_qty = 0.0;
} else {
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
}
this._super();
},
rejected_qty: function(doc, cdt, cdn) {
var item = wn.model.get_doc(cdt, cdn);
wn.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
if(item.rejected_qty > item.received_qty) {
msgprint(wn._("Error") + ": " + wn._(wn.meta.get_label(item.doctype, "rejected_qty", item.name))
+ " > " + wn._(wn.meta.get_label(item.doctype, "received_qty", item.name)));
item.qty = item.rejected_qty = 0.0;
} else {
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
}
this.qty(doc, cdt, cdn);
},
});
var new_cscript = new erpnext.buying.PurchaseReceiptController({frm: cur_frm});
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new_cscript);
cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(!doc.fiscal_year && doc.__islocal){ wn.model.set_default_values(doc);}
if (!doc.posting_date) doc.posting_date = dateutil.obj_to_str(new Date());
if (!doc.transaction_date) doc.transaction_date = dateutil.obj_to_str(new Date());
if (!doc.status) doc.status = 'Draft';
}
cur_frm.cscript.supplier = function(doc,dt,dn) {
if (doc.supplier) {
get_server_fields('get_default_supplier_address',
JSON.stringify({ supplier: doc.supplier }),'', doc, dt, dn, 1, function() {
cur_frm.refresh();
});
}
}
$.extend(cur_frm.cscript, new erpnext.stock.PurchaseReceiptController({frm: cur_frm}));
cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.supplier) get_server_fields('get_supplier_address', JSON.stringify({supplier: doc.supplier, address: doc.supplier_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
@@ -137,81 +158,6 @@ cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn)
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
//========================= Received Qty =============================================================
cur_frm.cscript.received_qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
ret = {
'qty' : (flt(d.qty) && flt(d.qty) < flt(d.received_qty))
? flt(d.qty) : flt(d.received_qty),
'stock_qty': 0,
'rejected_qty' : 0,
}
set_multiple('Purchase Receipt Item', cdn, ret, 'purchase_receipt_details');
cur_frm.cscript.calc_amount(doc, 2);
}
//======================== Qty (Accepted Qty) =========================================================
cur_frm.cscript.qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
// Step 1 :=> Check If Qty > Received Qty
if (flt(d.qty) > flt(d.received_qty)) {
alert("Accepted Qty cannot be greater than Received Qty")
ret = {
'qty' : 0,
'stock_qty': 0,
'rejected_qty' : 0
}
// => Set Qty = 0 and rejected_qty = 0
set_multiple('Purchase Receipt Item', cdn, ret, 'purchase_receipt_details');
cur_frm.cscript.calc_amount(doc, 2);
// => Return
return
}
// Step 2 :=> Check IF Qty <= REceived Qty
else {
ret = {
'rejected_qty':flt(d.received_qty) - flt(d.qty)
}
// => Set Rejected Qty = Received Qty - Qty
set_multiple('Purchase Receipt Item', cdn, ret, 'purchase_receipt_details');
// => Calculate Amount
cur_frm.cscript.calc_amount(doc, 2);
cur_frm.cscript.update_stock_qty(doc,cdt,cdn);
}
}
//======================== Rejected Qty =========================================================
cur_frm.cscript.rejected_qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
// Step 1 :=> Check If Rejected Qty > Received Qty
if (flt(d.rejected_qty) > flt(d.received_qty)) {
alert("Rejected Qty cannot be greater than Received Qty")
ret = {
'qty' : 0,
'stock_qty': 0,
'rejected_qty' : 0
}
// => Set Qty = 0 and rejected_qty = 0
set_multiple('Purchase Receipt Item', cdn, ret, 'purchase_receipt_details');
cur_frm.cscript.calc_amount(doc, 2);
// => Return
return
}
// Step 2 :=> Check IF Rejected Qty <= REceived Qty
else {
ret = {
'qty':flt(d.received_qty) - flt(d.rejected_qty)
}
// => Set Qty = Received Qty - Rejected Qty
set_multiple('Purchase Receipt Item', cdn, ret, 'purchase_receipt_details');
// Calculate Amount
cur_frm.cscript.calc_amount(doc, 2);
cur_frm.cscript.update_stock_qty(doc,cdt,cdn);
}
}
//================================= Purchase Order No Get Query ====================================
cur_frm.fields_dict['purchase_order_no'].get_query = function(doc) {
if (doc.supplier)