callback issues and item default get most priority

This commit is contained in:
Nabin Hait
2012-02-15 14:28:02 +05:30
parent 0e14191163
commit ab90ee04f5
4 changed files with 742 additions and 737 deletions

View File

@@ -22,18 +22,14 @@ cur_frm.cscript.onload = function(doc,dt,dn) {
if(!doc.price_list_currency) set_multiple(dt, dn, {price_list_currency: doc.currency, plc_conversion_rate: 1});
hide_field(['customer_address', 'contact_person','customer_name','address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
//for previously created sales invoice, set required field related to pos
if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn);
}
}
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
var callback = null;
var callback2 = null;
if(doc.customer && doc.__islocal) {
// called from mapper, update the account names for items and customer
callback = function(doc, dt, dn) {
callback2 = function(doc, dt, dn) {
$c_obj(make_doclist(doc.doctype,doc.name),
'load_default_accounts','',
function(r,rt) {
@@ -44,8 +40,13 @@ cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
}
}
// defined in sales_common.js
cur_frm.cscript.update_item_details(doc, cdt, cdn, callback);
var callback1 = function(doc, dt, dn) {
//for previously created sales invoice, set required field related to pos
cur_frm.cscript.update_item_details(doc, dt, dn, callback2);
}
if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn,callback1);
else cur_frm.cscript.update_item_details(doc, dt, dn, callback2);
}
@@ -107,7 +108,7 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
//fetch retail transaction related fields
//--------------------------------------------
cur_frm.cscript.is_pos = function(doc,dt,dn){
cur_frm.cscript.is_pos = function(doc,dt,dn,callback){
cur_frm.cscript.hide_fields(doc, cdt, cdn);
if(doc.is_pos == 1){
if (!doc.company) {
@@ -116,10 +117,11 @@ cur_frm.cscript.is_pos = function(doc,dt,dn){
refresh_field('is_pos');
}
else {
var callback = function(r,rt){
var callback1 = function(r,rt){
if(callback) callback(doc, dt, dn);
cur_frm.refresh();
}
$c_obj(make_doclist(dt,dn),'set_pos_fields','',callback);
$c_obj(make_doclist(dt,dn),'set_pos_fields','',callback1);
}
}
}

View File

@@ -72,9 +72,12 @@ class DocType(TransactionBase):
if not dtl:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
for d in getlist(self.doclist,'entries'):
if dtl and dtl[0]['income_account']: d.income_account = dtl[0]['income_account']
if dtl and dtl[0]['cost_center']: d.cost_center = dtl[0]['cost_center']
if dtl and dtl[0]['warehouse']: d.warehouse = dtl[0]['warehouse']
# overwrite if mentioned in item
item = webnotes.conn.sql("select default_income_account, default_sales_cost_center, default_warehouse from tabItem where name = '%s'" %(d.item_code), as_dict=1)
d.income_account = item and item[0]['default_income_account'] or dtl and dtl[0]['income_account'] or ''
d.cost_center = item and item[0]['default_sales_cost_center'] or dtl and dtl[0]['cost_center'] or ''
d.warehouse = item and item[0]['default_warehouse'] or dtl and dtl[0]['warehouse'] or ''
# Get Account Head to which amount needs to be Debited based on Customer
@@ -168,9 +171,9 @@ class DocType(TransactionBase):
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where user = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)
if not dtl:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % (self.doc.company), as_dict=1)
if dtl and dtl[0]['income_account']: ret['income_account'] = dtl and dtl[0]['income_account']
if dtl and dtl[0]['cost_center']: ret['cost_center'] = dtl and dtl[0]['cost_center']
if dtl and dtl[0]['warehouse']: ret['warehouse'] = dtl and dtl[0]['warehouse']
if dtl and not ret['income_account'] and dtl[0]['income_account']: ret['income_account'] = dtl and dtl[0]['income_account']
if dtl and not ret['cost_center'] and dtl[0]['cost_center']: ret['cost_center'] = dtl and dtl[0]['cost_center']
if dtl and not ret['warehouse'] and dtl[0]['warehouse']: ret['warehouse'] = dtl and dtl[0]['warehouse']
if ret['warehouse']:
actual_qty = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (item_code, ret['warehouse']))
ret['actual_qty']= actual_qty and flt(actual_qty[0][0]) or 0

View File

@@ -140,7 +140,6 @@ class DocType(TransactionBase):
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)
return ret
# ***************** Get Ref rate as entered in Item Master ********************