diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 9a9a865233..c67a30fb69 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -171,18 +171,10 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ erpnext.buying.get_items_from_product_bundle(me.frm); }, __("Get items from")); }, - - company: function() { - var me = this; - if (frappe.meta.get_docfield(this.frm.doctype, "shipping_address") - && !this.frm.doc.shipping_address) { - erpnext.utils.get_shipping_address(this.frm) - } - }, - + shipping_address: function(){ var me = this; - + this.frm.set_query("shipping_address", function(){ if(me.frm.doc.customer){ return{ @@ -200,8 +192,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ } } }); - - erpnext.utils.get_address_display(this.frm, "shipping_address", + + erpnext.utils.get_address_display(this.frm, "shipping_address", "shipping_address_display", is_your_company_address=true) } }); diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6de5154817..a1b38467b0 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -308,7 +308,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date; else var date = this.frm.doc.transaction_date; - set_party_account(set_pricing); + + if (frappe.meta.get_docfield(this.frm.doctype, "shipping_address") && + in_list(['Purchase Order', 'Purchase Receipt', 'Purchase Invoice'], this.frm.doctype)){ + erpnext.utils.get_shipping_address(this.frm, function(){ + set_party_account(set_pricing); + }) + }else{ + set_party_account(set_pricing); + } if(this.frm.doc.company) { erpnext.last_selected_company = this.frm.doc.company; diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js index 1896f88884..a31d841c2b 100644 --- a/erpnext/public/js/utils/party.js +++ b/erpnext/public/js/utils/party.js @@ -69,7 +69,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field, if(r.message) { frm.set_value(display_field, r.message) } - + if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) { if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier", frm.doc.customer || frm.doc.supplier, address_field)) return; @@ -99,7 +99,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field, } else { frm.set_value(display_field, null); } - + } erpnext.utils.get_contact_details = function(frm) { @@ -127,7 +127,7 @@ erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) { return true; } -erpnext.utils.get_shipping_address = function(frm){ +erpnext.utils.get_shipping_address = function(frm, callback){ frappe.call({ method: "erpnext.utilities.doctype.address.address.get_shipping_address", args: {company: frm.doc.company}, @@ -136,6 +136,10 @@ erpnext.utils.get_shipping_address = function(frm){ frm.set_value("shipping_address", r.message[0]) //Address title or name frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page } + + if(callback){ + return callback(); + } } }); }