mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 20:29:09 +00:00
[selling/buying] [fixes] updated js files of various doctypes related to selling/g/buying
This commit is contained in:
@@ -21,101 +21,40 @@ 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, cdt, cdn) {
|
||||
cur_frm.cscript.manage_rounded_total();
|
||||
if(!doc.quotation_to)
|
||||
hide_field(['customer','customer_address','contact_person','customer_name','lead',
|
||||
'address_display', 'contact_display', 'contact_mobile', 'contact_email',
|
||||
'territory', 'customer_group']);
|
||||
if(!doc.price_list_name) set_multiple(cdt,cdn,{price_list_name:sys_defaults.price_list_name});
|
||||
if(!doc.status) set_multiple(cdt,cdn,{status:'Draft'});
|
||||
if(!doc.transaction_date) set_multiple(cdt,cdn,{transaction_date:get_today()});
|
||||
if(!doc.conversion_rate) set_multiple(cdt,cdn,{conversion_rate:'1.00'});
|
||||
if(!doc.currency && sys_defaults.currency) set_multiple(cdt,cdn,{currency:sys_defaults.currency});
|
||||
if(!doc.price_list_currency) set_multiple(cdt, cdn, {price_list_currency: doc.currency, plc_conversion_rate: 1});
|
||||
|
||||
if(!doc.company && sys_defaults.company) set_multiple(cdt,cdn,{company:sys_defaults.company});
|
||||
if(!doc.fiscal_year && sys_defaults.fiscal_year) set_multiple(cdt,cdn,{fiscal_year:sys_defaults.fiscal_year});
|
||||
|
||||
if(doc.quotation_to) {
|
||||
if(doc.quotation_to == 'Customer') {
|
||||
hide_field('lead');
|
||||
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
||||
refresh: function(doc, dt, dn) {
|
||||
this._super();
|
||||
|
||||
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']);
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||
}
|
||||
else if (doc.quotation_to == 'Lead') {
|
||||
hide_field(['customer', 'customer_address', 'contact_person', 'customer_group']);
|
||||
|
||||
if (!doc.__islocal) {
|
||||
cur_frm.communication_view = new wn.views.CommunicationList({
|
||||
list: wn.model.get("Communication", {"quotation": doc.name}),
|
||||
parent: cur_frm.fields_dict.communication_html.wrapper,
|
||||
doc: doc,
|
||||
recipients: doc.contact_email
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hide - unhide fields based on lead or customer..
|
||||
// =======================================================================================================================
|
||||
cur_frm.cscript.lead_cust_show = function(doc,cdt,cdn){
|
||||
hide_field(['lead', 'customer','customer_address','contact_person',
|
||||
'customer_name','address_display','contact_display','contact_mobile','contact_email',
|
||||
'territory','customer_group']);
|
||||
if(doc.quotation_to == 'Lead') unhide_field(['lead']);
|
||||
else if(doc.quotation_to == 'Customer') unhide_field(['customer']);
|
||||
|
||||
this.quotation_to();
|
||||
},
|
||||
|
||||
doc.lead = doc.customer = doc.customer_name = doc.customer_address = doc.contact_person = doc.address_display = doc.contact_display = doc.contact_mobile = doc.contact_email = doc.territory = doc.customer_group = "";
|
||||
}
|
||||
quotation_to: function() {
|
||||
this.frm.toggle_reqd("lead", this.frm.doc.quotation_to == "Lead");
|
||||
this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
//================ hide - unhide fields on basis of quotation to either lead or customer ===============================
|
||||
cur_frm.cscript.quotation_to = function(doc,cdt,cdn){
|
||||
cur_frm.cscript.lead_cust_show(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
|
||||
// REFRESH
|
||||
// ===================================================================================
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.clear_custom_buttons();
|
||||
|
||||
if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, cdt, cdn);
|
||||
|
||||
|
||||
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']);
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||
}
|
||||
|
||||
erpnext.hide_naming_series();
|
||||
cur_frm.toggle_display("contact_section", doc.customer || doc.lead);
|
||||
|
||||
if (!doc.__islocal) {
|
||||
cur_frm.communication_view = new wn.views.CommunicationList({
|
||||
list: wn.model.get("Communication", {"quotation": doc.name}),
|
||||
parent: cur_frm.fields_dict.communication_html.wrapper,
|
||||
doc: doc,
|
||||
recipients: doc.contact_email
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//customer
|
||||
cur_frm.cscript.customer = function(doc,dt,dn) {
|
||||
var pl = doc.price_list_name;
|
||||
var callback = function(r,rt) {
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
cur_frm.refresh();
|
||||
if (pl != doc.price_list_name) cur_frm.cscript.price_list_name(doc, dt, dn);
|
||||
}
|
||||
|
||||
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name),
|
||||
'get_default_customer_address', '', callback);
|
||||
if(doc.customer) unhide_field(['customer_address','contact_person','territory', 'customer_group']);
|
||||
cur_frm.toggle_display("contact_section", doc.customer || doc.lead);
|
||||
console.log(doc.customer_group);
|
||||
}
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new erpnext.selling.QuotationController({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({
|
||||
@@ -240,31 +179,6 @@ cur_frm.cscript['Declare Order Lost'] = function(){
|
||||
qtn_lost_dialog.show();
|
||||
}
|
||||
|
||||
//===================== Quotation to validation - either customer or lead mandatory ====================
|
||||
cur_frm.cscript.quot_to_validate = function(doc,cdt,cdn){
|
||||
|
||||
if(doc.quotation_to == 'Lead'){
|
||||
|
||||
if(!doc.lead){
|
||||
alert("Lead is mandatory.");
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
else if(doc.quotation_to == 'Customer'){
|
||||
if(!doc.customer){
|
||||
alert("Customer is mandatory.");
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===================validation function =================================
|
||||
|
||||
cur_frm.cscript.validate = function(doc,cdt,cdn){
|
||||
cur_frm.cscript.recalculate_values(doc, cdt, cdn);
|
||||
cur_frm.cscript.quot_to_validate(doc,cdt,cdn);
|
||||
}
|
||||
|
||||
//================ Last Quoted Price and Last Sold Price suggestion ======================
|
||||
cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query= function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
|
||||
@@ -182,6 +182,20 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
warehouse: function(doc, cdt, cdn) {
|
||||
var item = webnotes.get_doc(cdt, cdn);
|
||||
if(item.item_code && (item.warehouse || item.reserved_warehouse)) {
|
||||
this.frm.call({
|
||||
method: "selling.utils.get_available_qty",
|
||||
child: item,
|
||||
args: {
|
||||
item_code: item.item_code,
|
||||
warehouse: item.warehouse || item.reserved_warehouse,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
toggle_rounded_total: function() {
|
||||
var me = this;
|
||||
if(cint(wn.defaults.get_global_default("disable_rounded_total"))) {
|
||||
@@ -194,6 +208,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
|
||||
calculate_taxes_and_totals: function() {
|
||||
this._super();
|
||||
this.calculate_total_advance();
|
||||
this.calculate_commission();
|
||||
this.calculate_contribution();
|
||||
|
||||
@@ -310,6 +325,23 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
this.frm.doc.rounded_total_export = Math.round(this.frm.doc.grand_total_export);
|
||||
},
|
||||
|
||||
calculate_total_advance: function() {
|
||||
this._super("Sales Invoice", "advance_adjustment_details");
|
||||
},
|
||||
|
||||
calculate_outstanding_amount: function() {
|
||||
// TODO - I find this incorrect!
|
||||
// see TODO of sales invoice.js / write_off_outstanding_amount_automatically
|
||||
|
||||
if(this.frm.doc.doctype == "Sales Invoice" && this.frm.doc.docstatus < 2) {
|
||||
wn.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount",
|
||||
"paid_amount"]);
|
||||
var total_amount_to_pay = this.frm.doc.grand_total - this.frm.doc.write_off_amount;
|
||||
this.frm.doc.outstanding_amount = flt(total_amount_to_pay - this.frm.doc.total_advance -
|
||||
this.frm.doc.paid_amount, precision("outstanding_amount"));
|
||||
}
|
||||
},
|
||||
|
||||
calculate_commission: function() {
|
||||
if(this.frm.doc.commission_rate > 100) {
|
||||
var msg = wn._(wn.meta.get_label(this.frm.doc.doctype, "commission_rate", this.frm.doc.name)) +
|
||||
|
||||
@@ -48,26 +48,6 @@ class DocType(TransactionBase):
|
||||
|
||||
self.msg = []
|
||||
|
||||
|
||||
# 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.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', obj.doclist)
|
||||
ch.sales_person = d and cstr(d[0]) or ''
|
||||
ch.allocated_percentage = d and flt(d[1]) or 0
|
||||
ch.allocated_amount = d and flt(d[2]) or 0
|
||||
ch.incentives = d and flt(d[3]) or 0
|
||||
ch.idx = idx
|
||||
idx += 1
|
||||
return obj.doclist
|
||||
|
||||
|
||||
# Get customer's contact person details
|
||||
# ==============================================================
|
||||
def get_contact_details(self, obj = '', primary = 0):
|
||||
@@ -100,161 +80,6 @@ class DocType(TransactionBase):
|
||||
if obj.doc.company:
|
||||
acc_head = webnotes.conn.sql("select name from `tabAccount` where name = '%s' and docstatus != 2" % (cstr(obj.doc.customer) + " - " + webnotes.conn.get_value('Company', obj.doc.company, 'abbr')))
|
||||
obj.doc.debit_to = acc_head and acc_head[0][0] or ''
|
||||
|
||||
|
||||
|
||||
# Get Item Details
|
||||
# ===============================================================
|
||||
# def get_item_details(self, args, obj):
|
||||
# import json
|
||||
# if not obj.doc.price_list_name:
|
||||
# msgprint("Please Select Price List before selecting Items", raise_exception=True)
|
||||
# item = webnotes.conn.sql("""select description, item_name, brand, item_group, stock_uom,
|
||||
# default_warehouse, default_income_account, default_sales_cost_center,
|
||||
# purchase_account, description_html, barcode from `tabItem`
|
||||
# where name = %s and (ifnull(end_of_life,'')='' or end_of_life > now()
|
||||
# or end_of_life = '0000-00-00') and (is_sales_item = 'Yes'
|
||||
# or is_service_item = 'Yes')""", args['item_code'], as_dict=1)
|
||||
# tax = webnotes.conn.sql("""select tax_type, tax_rate from `tabItem Tax`
|
||||
# where parent = %s""", args['item_code'])
|
||||
# t = {}
|
||||
# for x in tax: t[x[0]] = flt(x[1])
|
||||
# ret = {
|
||||
# 'description': item and item[0]['description_html'] or \
|
||||
# item[0]['description'],
|
||||
# 'barcode': item and item[0]['barcode'] or '',
|
||||
# 'item_group': item and item[0]['item_group'] or '',
|
||||
# 'item_name': item and item[0]['item_name'] or '',
|
||||
# 'brand': item and item[0]['brand'] or '',
|
||||
# 'stock_uom': item and item[0]['stock_uom'] or '',
|
||||
# 'reserved_warehouse': item and item[0]['default_warehouse'] or '',
|
||||
# 'warehouse': item and item[0]['default_warehouse'] or \
|
||||
# args.get('warehouse'),
|
||||
# 'income_account': item and item[0]['default_income_account'] or \
|
||||
# args.get('income_account'),
|
||||
# 'expense_account': item and item[0]['purchase_account'] or \
|
||||
# args.get('expense_account'),
|
||||
# 'cost_center': item and item[0]['default_sales_cost_center'] or \
|
||||
# args.get('cost_center'),
|
||||
# # this is done coz if item once fetched is fetched again than its qty shld be reset to 1
|
||||
# 'qty': 1.00,
|
||||
# 'adj_rate': 0,
|
||||
# 'amount': 0,
|
||||
# 'export_amount': 0,
|
||||
# 'item_tax_rate': json.dumps(t),
|
||||
# 'batch_no': ''
|
||||
# }
|
||||
# if(obj.doc.price_list_name and item): #this is done to fetch the changed BASIC RATE and REF RATE based on PRICE LIST
|
||||
# base_ref_rate = self.get_ref_rate(args['item_code'], obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
||||
# ret['ref_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||
# ret['export_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||
# ret['base_ref_rate'] = flt(base_ref_rate)
|
||||
# ret['basic_rate'] = flt(base_ref_rate)
|
||||
#
|
||||
# if ret['warehouse'] or ret['reserved_warehouse']:
|
||||
# av_qty = self.get_available_qty({'item_code': args['item_code'], 'warehouse': ret['warehouse'] or ret['reserved_warehouse']})
|
||||
# ret.update(av_qty)
|
||||
#
|
||||
# # get customer code for given item from Item Customer Detail
|
||||
# customer_item_code_row = webnotes.conn.sql("""\
|
||||
# select ref_code from `tabItem Customer Detail`
|
||||
# where parent = %s and customer_name = %s""",
|
||||
# (args['item_code'], obj.doc.customer))
|
||||
# if customer_item_code_row and customer_item_code_row[0][0]:
|
||||
# ret['customer_item_code'] = customer_item_code_row[0][0]
|
||||
#
|
||||
# return ret
|
||||
|
||||
# TODO: deprecate it
|
||||
def get_item_defaults(self, args):
|
||||
item = webnotes.conn.sql("""select default_warehouse, default_income_account,
|
||||
default_sales_cost_center, purchase_account from `tabItem` where name = %s
|
||||
and (ifnull(end_of_life,'') = '' or end_of_life > now() or end_of_life = '0000-00-00')
|
||||
and (is_sales_item = 'Yes' or is_service_item = 'Yes') """,
|
||||
(args['item_code']), as_dict=1)
|
||||
ret = {
|
||||
'reserved_warehouse': item and item[0]['default_warehouse'] or '',
|
||||
'warehouse': item and item[0]['default_warehouse'] or args.get('warehouse'),
|
||||
'income_account': item and item[0]['default_income_account'] or \
|
||||
args.get('income_account'),
|
||||
'expense_account': item and item[0]['purchase_account'] or args.get('expense_account'),
|
||||
'cost_center': item and item[0]['default_sales_cost_center'] or args.get('cost_center'),
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
# def get_available_qty(self,args):
|
||||
# tot_avail_qty = webnotes.conn.sql("select projected_qty, actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)
|
||||
# ret = {
|
||||
# 'projected_qty' : tot_avail_qty and flt(tot_avail_qty[0]['projected_qty']) or 0,
|
||||
# 'actual_qty' : tot_avail_qty and flt(tot_avail_qty[0]['actual_qty']) or 0
|
||||
# }
|
||||
# return ret
|
||||
|
||||
|
||||
# ***************** Get Ref rate as entered in Item Master ********************
|
||||
# def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate):
|
||||
# ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s and selling=1",
|
||||
# (item_code, price_list_name, price_list_currency))
|
||||
# base_ref_rate = ref_rate and flt(ref_rate[0][0]) * flt(plc_conv_rate) or 0
|
||||
# return base_ref_rate
|
||||
|
||||
# ****** Re-cancellculates Basic Rate & amount based on Price List Selected ******
|
||||
# def get_adj_percent(self, obj):
|
||||
# for d in getlist(obj.doclist, obj.fname):
|
||||
# base_ref_rate = self.get_ref_rate(d.item_code, obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
||||
# d.adj_rate = 0
|
||||
# d.ref_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||
# d.basic_rate = flt(base_ref_rate)
|
||||
# d.base_ref_rate = flt(base_ref_rate)
|
||||
# d.export_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||
# d.amount = flt(d.qty)*flt(base_ref_rate)
|
||||
# d.export_amount = flt(d.qty)*flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||
|
||||
|
||||
# # Load Default Taxes
|
||||
# # ====================
|
||||
# def load_default_taxes(self, obj):
|
||||
# if cstr(obj.doc.charge):
|
||||
# return self.get_other_charges(obj)
|
||||
# else:
|
||||
# return self.get_other_charges(obj, 1)
|
||||
#
|
||||
#
|
||||
# # Get other charges from Master
|
||||
# # =================================================================================
|
||||
# def get_other_charges(self,obj, default=0):
|
||||
# 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)+'"'
|
||||
# idx = 0
|
||||
# other_charge = webnotes.conn.sql("""\
|
||||
# select t1.*
|
||||
# from
|
||||
# `tabSales Taxes and Charges` t1,
|
||||
# `tabSales Taxes and Charges Master` t2
|
||||
# where
|
||||
# t1.parent = t2.name and
|
||||
# t2.company = '%s' and
|
||||
# %s
|
||||
# order by t1.idx""" % (obj.doc.company, add_cond), as_dict=1)
|
||||
# from webnotes.model import default_fields
|
||||
# for other in other_charge:
|
||||
# # remove default fields like parent, parenttype etc.
|
||||
# # from query results
|
||||
# for field in default_fields:
|
||||
# if field in other: del other[field]
|
||||
#
|
||||
# d = addchild(obj.doc, 'other_charges', 'Sales Taxes and Charges',
|
||||
# obj.doclist)
|
||||
# d.fields.update(other)
|
||||
# d.rate = flt(d.rate)
|
||||
# d.tax_amount = flt(d.tax_rate)
|
||||
# d.included_in_print_rate = cint(d.included_in_print_rate)
|
||||
# d.idx = idx
|
||||
# idx += 1
|
||||
# return obj.doclist
|
||||
|
||||
# Get TERMS AND CONDITIONS
|
||||
# =======================================================================================
|
||||
|
||||
@@ -26,90 +26,54 @@ 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');
|
||||
|
||||
|
||||
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
cur_frm.cscript.toggle_rounded_total();
|
||||
|
||||
if(!doc.status) set_multiple(cdt,cdn,{status:'Draft'});
|
||||
if(!doc.transaction_date) set_multiple(cdt,cdn,{transaction_date:get_today()});
|
||||
if(!doc.price_list_currency) set_multiple(cdt, cdn, {price_list_currency: doc.currency, plc_conversion_rate: 1});
|
||||
// load default charges
|
||||
|
||||
if(doc.__islocal && !doc.customer){
|
||||
hide_field(['customer_address','contact_person', 'customer_name',
|
||||
'address_display', 'contact_display', 'contact_mobile',
|
||||
'contact_email', 'territory', 'customer_group']);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.clear_custom_buttons();
|
||||
erpnext.hide_naming_series();
|
||||
|
||||
cur_frm.toggle_display("contact_info", doc.customer);
|
||||
|
||||
if(doc.docstatus==1) {
|
||||
if(doc.status != 'Stopped') {
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||
// delivery note
|
||||
if(flt(doc.per_delivered, 2) < 100 && doc.order_type=='Sales')
|
||||
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
|
||||
erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend({
|
||||
refresh: function(doc, dt, dn) {
|
||||
this._super();
|
||||
|
||||
if(doc.docstatus==1) {
|
||||
if(doc.status != 'Stopped') {
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||
// delivery note
|
||||
if(flt(doc.per_delivered, 2) < 100 && doc.order_type=='Sales')
|
||||
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
|
||||
|
||||
// maintenance
|
||||
if(flt(doc.per_delivered, 2) < 100 && (doc.order_type !='Sales')) {
|
||||
cur_frm.add_custom_button('Make Maint. Visit', cur_frm.cscript.make_maintenance_visit);
|
||||
cur_frm.add_custom_button('Make Maint. Schedule', cur_frm.cscript['Make Maintenance Schedule']);
|
||||
// maintenance
|
||||
if(flt(doc.per_delivered, 2) < 100 && (doc.order_type !='Sales')) {
|
||||
cur_frm.add_custom_button('Make Maint. Visit', cur_frm.cscript.make_maintenance_visit);
|
||||
cur_frm.add_custom_button('Make Maint. Schedule', cur_frm.cscript['Make Maintenance Schedule']);
|
||||
}
|
||||
|
||||
// indent
|
||||
if(!doc.order_type || (doc.order_type == 'Sales'))
|
||||
cur_frm.add_custom_button('Make ' + wn._('Material Request'), cur_frm.cscript['Make Material Request']);
|
||||
|
||||
// sales invoice
|
||||
if(flt(doc.per_billed, 2) < 100)
|
||||
cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
|
||||
|
||||
// stop
|
||||
if(flt(doc.per_delivered, 2) < 100 || doc.per_billed < 100)
|
||||
cur_frm.add_custom_button('Stop!', cur_frm.cscript['Stop Sales Order']);
|
||||
} else {
|
||||
// un-stop
|
||||
cur_frm.add_custom_button('Unstop', cur_frm.cscript['Unstop Sales Order']);
|
||||
}
|
||||
|
||||
// indent
|
||||
if(!doc.order_type || (doc.order_type == 'Sales'))
|
||||
cur_frm.add_custom_button('Make ' + wn._('Material Request'), cur_frm.cscript['Make Material Request']);
|
||||
|
||||
// sales invoice
|
||||
if(flt(doc.per_billed, 2) < 100)
|
||||
cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
|
||||
|
||||
// stop
|
||||
if(flt(doc.per_delivered, 2) < 100 || doc.per_billed < 100)
|
||||
cur_frm.add_custom_button('Stop!', cur_frm.cscript['Stop Sales Order']);
|
||||
} else {
|
||||
// un-stop
|
||||
cur_frm.add_custom_button('Unstop', cur_frm.cscript['Unstop Sales Order']);
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.order_type(doc);
|
||||
}
|
||||
|
||||
cur_frm.cscript.order_type = function(doc) {
|
||||
if(doc.order_type == "Sales") {
|
||||
cur_frm.toggle_reqd("delivery_date", 1);
|
||||
} else {
|
||||
cur_frm.toggle_reqd("delivery_date", 0);
|
||||
}
|
||||
}
|
||||
|
||||
//customer
|
||||
cur_frm.cscript.customer = function(doc,dt,dn) {
|
||||
cur_frm.toggle_display("contact_info", doc.customer);
|
||||
this.order_type(doc);
|
||||
},
|
||||
|
||||
var pl = doc.price_list_name;
|
||||
var callback = function(r,rt) {
|
||||
var callback2 = function(r, rt) {
|
||||
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);
|
||||
order_type: function() {
|
||||
this.frm.toggle_reqd("delivery_date", this.frm.doc.order_type == "Sales");
|
||||
},
|
||||
|
||||
reserved_warehouse: function(doc, cdt, cdn) {
|
||||
this.warehouse(doc, cdt, cdn);
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||
get_server_fields('get_shipping_address',doc.customer,'',doc, dt, dn, 0, callback2);
|
||||
|
||||
}
|
||||
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name),
|
||||
'get_default_customer_address', '', callback);
|
||||
}
|
||||
// for backward compatibility: combine new and previous states
|
||||
$.extend(cur_frm.cscript, new erpnext.selling.SalesOrderController({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);
|
||||
@@ -165,15 +129,6 @@ cur_frm.fields_dict['quotation_no'].get_query = function(doc) {
|
||||
ORDER BY `tabQuotation`.`name` DESC LIMIT 50', {cond:cond});
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.reserved_warehouse = function(doc, cdt , cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
if (d.reserved_warehouse) {
|
||||
arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.reserved_warehouse +"'}";
|
||||
get_server_fields('get_available_qty',arg,'sales_order_details',doc,cdt,cdn,1);
|
||||
}
|
||||
}
|
||||
|
||||
//----------- make maintenance schedule----------
|
||||
cur_frm.cscript['Make Maintenance Schedule'] = function() {
|
||||
var doc = cur_frm.doc;
|
||||
|
||||
@@ -58,22 +58,6 @@ class DocType(SellingController):
|
||||
def get_comm_rate(self, sales_partner):
|
||||
return get_obj('Sales Common').get_comm_rate(sales_partner, 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'), '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]
|
||||
|
||||
def get_adj_percent(self, arg=''):
|
||||
get_obj('Sales Common').get_adj_percent(self)
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ def get_item_details(args):
|
||||
out.update(_get_price_list_rate(args, item_bean, meta))
|
||||
|
||||
if out.warehouse or out.reserved_warehouse:
|
||||
out.update(_get_available_qty(args, out.warehouse or out.reserved_warehouse))
|
||||
out.update(get_available_qty(args.item_code, out.warehouse or out.reserved_warehouse))
|
||||
|
||||
out.customer_item_code = _get_customer_item_code(args, item_bean)
|
||||
|
||||
@@ -109,6 +109,7 @@ def _validate_item_details(args, item):
|
||||
def _get_basic_details(args, item_bean):
|
||||
item = item_bean.doc
|
||||
out = webnotes._dict({
|
||||
"item_code": item.name,
|
||||
"description": item.description_html or item.description,
|
||||
"reserved_warehouse": item.default_warehouse,
|
||||
"warehouse": item.default_warehouse or args.warehouse,
|
||||
@@ -129,7 +130,7 @@ def _get_basic_details(args, item_bean):
|
||||
|
||||
return out
|
||||
|
||||
def _get_price_list_rate(args, item_bean, meta=None):
|
||||
def _get_price_list_rate(args, item_bean, meta):
|
||||
base_ref_rate = item_bean.doclist.get({
|
||||
"parentfield": "ref_rate_details",
|
||||
"price_list_name": args.price_list_name,
|
||||
@@ -143,10 +144,11 @@ def _get_price_list_rate(args, item_bean, meta=None):
|
||||
from utilities.transaction_base import validate_currency
|
||||
validate_currency(args, item_bean.doc, meta)
|
||||
|
||||
return {"base_ref_rate": flt(base_ref_rate[0].ref_rate / args.plc_conversion_rate)}
|
||||
|
||||
def _get_available_qty(args, warehouse):
|
||||
return webnotes.conn.get_value("Bin", {"item_code": args.item_code, "warehouse": warehouse},
|
||||
return {"ref_rate": flt(base_ref_rate[0].ref_rate * args.plc_conversion_rate / args.conversion_rate)}
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_available_qty(item_code, warehouse):
|
||||
return webnotes.conn.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
|
||||
["projected_qty", "actual_qty"], as_dict=True) or {}
|
||||
|
||||
def _get_customer_item_code(args, item_bean):
|
||||
@@ -173,6 +175,6 @@ def apply_pos_settings(pos_settings, opts):
|
||||
out[fieldname] = pos_settings.get(fieldname)
|
||||
|
||||
if out.get("warehouse"):
|
||||
out["actual_qty"] = _get_available_qty(opts, out.get("warehouse")).get("actual_qty")
|
||||
out["actual_qty"] = get_available_qty(opts.item_code, out.get("warehouse")).get("actual_qty")
|
||||
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user