diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js index 6f2548ac8ea..7b7c2e69cce 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.js @@ -132,4 +132,19 @@ frappe.ui.form.on("Repost Item Valuation", { }, }); }, + + voucher_type: function (frm) { + console.log(frm.doc); + frm.trigger("set_company_on_transaction"); + }, + + voucher_no: function (frm) { + frm.trigger("set_company_on_transaction"); + }, + + set_company_on_transaction(frm) { + if (frm.doc.voucher_no && frm.doc.voucher_no) { + frm.call("set_company"); + } + }, }); diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index c0f5aa8032b..a9d9d893061 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -70,10 +70,10 @@ class RepostItemValuation(Document): ) def validate(self): + self.set_company() self.validate_period_closing_voucher() self.set_status(write=False) self.reset_field_values() - self.set_company() self.validate_accounts_freeze() self.reset_recreate_stock_ledgers() @@ -162,6 +162,7 @@ class RepostItemValuation(Document): def on_trash(self): self.clear_attachment() + @frappe.whitelist() def set_company(self): if self.based_on == "Transaction": self.company = frappe.get_cached_value(self.voucher_type, self.voucher_no, "company")