Skip to content

Commit

Permalink
fix: set currency on change of company considering customer default c…
Browse files Browse the repository at this point in the history
…urrency (backport #42405) (#42547)

fix: set currency on change of company considering customer default currency (#42405)

(cherry picked from commit 4986f28)

# Conflicts:
#	erpnext/public/js/controllers/transaction.js

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
  • Loading branch information
mergify[bot] and nabinhait authored Jul 31, 2024
1 parent 64c185f commit 7c8d13c
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
var me = this;
var set_pricing = function() {
if(me.frm.doc.company && me.frm.fields_dict.currency) {
<<<<<<< HEAD
var company_currency = me.get_company_currency();
var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
Expand Down Expand Up @@ -858,15 +859,78 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
me.frm.set_value("tc_name", company_doc.default_buying_terms);
}
}
=======
>>>>>>> 4986f28a89 (fix: set currency on change of company considering customer default currency (#42405))
frappe.run_serially([
() => me.frm.script_manager.trigger("currency"),
() => get_party_currency(),
() => me.update_item_tax_map(),
() => me.apply_default_taxes(),
() => me.apply_pricing_rule()
() => me.apply_pricing_rule(),
() => set_terms(),
() => set_letter_head(),
]);
}
}

var get_party_currency = function() {
var party_type = frappe.meta.has_field(me.frm.doc.doctype, "customer") ? "Customer" : "Supplier";
var party_name = me.frm.doc[party_type.toLowerCase()];
if (party_name) {
frappe.call({
method: "frappe.client.get_value",
args: {
doctype: party_type,
filters: { name: party_name },
fieldname: "default_currency",
},
callback: function (r) {
if (r.message) {
set_currency(r.message.default_currency);
}
}
})
} else {
set_currency();
}
}

var set_currency = function(party_default_currency) {
var company_currency = me.get_company_currency();
var currency = party_default_currency || company_currency;
if (me.frm.doc.currency != currency) {
me.frm.set_value("currency", currency);
}

if (me.frm.doc.currency == company_currency) {
me.frm.set_value("conversion_rate", 1.0);
}
if (me.frm.doc.price_list_currency == company_currency) {
me.frm.set_value('plc_conversion_rate', 1.0);
}

me.frm.script_manager.trigger("currency");
}

var set_terms = function() {
if (frappe.meta.has_field(me.frm.doc.doctype, "tc_name") && !me.frm.doc.tc_name) {
var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
var selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"];
var company_terms_fieldname = selling_doctypes.includes(me.frm.doc.doctype) ? "default_selling_terms" : "default_buying_terms";
if (company_doc && company_doc[company_terms_fieldname]) {
me.frm.set_value("tc_name", company_doc[company_terms_fieldname]);
}
}
}

var set_letter_head = function() {
if(me.frm.fields_dict.letter_head) {
var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
if (company_doc && company_doc.default_letter_head) {
me.frm.set_value("letter_head", company_doc.default_letter_head);
}
}
}

var set_party_account = function(set_pricing) {
if (["Sales Invoice", "Purchase Invoice"].includes(me.frm.doc.doctype)) {
if(me.frm.doc.doctype=="Sales Invoice") {
Expand Down

0 comments on commit 7c8d13c

Please sign in to comment.