Skip to content

Commit

Permalink
fix: set expense_account and cost_center based on company in stock entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Sugesh393 committed Jan 8, 2025
1 parent 2b45321 commit 12f2065
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions erpnext/stock/doctype/stock_entry/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,6 @@ frappe.ui.form.on("Stock Entry", {
});
},

company: function (frm) {
if (frm.doc.company) {
var company_doc = frappe.get_doc(":Company", frm.doc.company);
if (company_doc.default_letter_head) {
frm.set_value("letter_head", company_doc.default_letter_head);
}
frm.trigger("toggle_display_account_head");

erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}
},

make_retention_stock_entry: function (frm) {
frappe.call({
method: "erpnext.stock.doctype.stock_entry.stock_entry.move_sample_to_retention_warehouse",
Expand Down Expand Up @@ -1060,11 +1048,9 @@ erpnext.stock.StockEntry = class StockEntry extends erpnext.stock.StockControlle

onload_post_render() {
var me = this;
this.set_default_account(function () {
if (me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) {
me.frm.trigger("company");
}
});
if (me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) {
me.company();
}

this.frm.get_field("items").grid.set_multiple_add("item_code", "qty");
}
Expand Down Expand Up @@ -1143,22 +1129,37 @@ erpnext.stock.StockEntry = class StockEntry extends erpnext.stock.StockControlle
this.clean_up();
}

set_default_account(callback) {
company() {
if (this.frm.doc.company) {
var company_doc = frappe.get_doc(":Company", this.frm.doc.company);
if (company_doc.default_letter_head) {
this.frm.set_value("letter_head", company_doc.default_letter_head);
}
this.frm.trigger("toggle_display_account_head");

erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
this.set_default_account("stock_adjustment_account", "expense_account");
this.set_default_account("cost_center", "cost_center");

this.frm.refresh_fields("items");
}
}

set_default_account(company_fieldname, fieldname) {
var me = this;

if (this.frm.doc.company && erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
return this.frm.call({
method: "erpnext.accounts.utils.get_company_default",
args: {
fieldname: "stock_adjustment_account",
fieldname: company_fieldname,
company: this.frm.doc.company,
},
callback: function (r) {
if (!r.exc) {
$.each(me.frm.doc.items || [], function (i, d) {
if (!d.expense_account) d.expense_account = r.message;
d[fieldname] = r.message;
});
if (callback) callback();
}
},
});
Expand Down

0 comments on commit 12f2065

Please sign in to comment.