From 0b1e78e12779d26a836e81e238aabfdd12245fac Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 22 Jul 2023 21:19:48 +0530 Subject: [PATCH] chore: Add landed cost taxes and charges common in bundles --- erpnext/public/js/erpnext.bundle.js | 1 + .../utils/landed_taxes_and_charges_common.js | 62 +++++++++++++++++++ .../landed_cost_voucher.js | 3 +- .../stock/doctype/stock_entry/stock_entry.js | 13 ++-- .../stock/landed_taxes_and_charges_common.js | 61 ------------------ .../subcontracting_order.js | 2 +- .../subcontracting_receipt.js | 2 +- erpnext/www/book_appointment/index.js | 2 +- 8 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 erpnext/public/js/utils/landed_taxes_and_charges_common.js delete mode 100644 erpnext/stock/landed_taxes_and_charges_common.js diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js index 0f4a65017ca..3d5025dd255 100644 --- a/erpnext/public/js/erpnext.bundle.js +++ b/erpnext/public/js/erpnext.bundle.js @@ -25,5 +25,6 @@ import "./utils/crm_activities"; import "./templates/crm_activities.html"; import "./templates/crm_notes.html"; import "./controllers/accounts.js" +import "./utils/landed_taxes_and_charges_common.js"; // import { sum } from 'frappe/public/utils/util.js' diff --git a/erpnext/public/js/utils/landed_taxes_and_charges_common.js b/erpnext/public/js/utils/landed_taxes_and_charges_common.js new file mode 100644 index 00000000000..c71f77d45e9 --- /dev/null +++ b/erpnext/public/js/utils/landed_taxes_and_charges_common.js @@ -0,0 +1,62 @@ + +erpnext.landed_cost_taxes_and_charges = { + setup_triggers: function(doctype) { + frappe.ui.form.on(doctype, { + refresh: function(frm) { + let tax_field = frm.doc.doctype == 'Landed Cost Voucher' ? 'taxes' : 'additional_costs'; + frm.set_query("expense_account", tax_field, function() { + return { + filters: { + "account_type": ['in', ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation", "Expenses Included In Asset Valuation"]], + "company": frm.doc.company + } + }; + }); + }, + + set_account_currency: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + if (row.expense_account) { + frappe.db.get_value('Account', row.expense_account, 'account_currency', function(value) { + frappe.model.set_value(cdt, cdn, "account_currency", value.account_currency); + frm.events.set_exchange_rate(frm, cdt, cdn); + }); + } + }, + + set_exchange_rate: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; + + if (row.account_currency == company_currency) { + row.exchange_rate = 1; + frm.set_df_property('taxes', 'hidden', 1, row.name, 'exchange_rate'); + } else if (!row.exchange_rate || row.exchange_rate == 1) { + frm.set_df_property('taxes', 'hidden', 0, row.name, 'exchange_rate'); + frappe.call({ + method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate", + args: { + posting_date: frm.doc.posting_date, + account: row.expense_account, + account_currency: row.account_currency, + company: frm.doc.company + }, + callback: function(r) { + if (r.message) { + frappe.model.set_value(cdt, cdn, "exchange_rate", r.message); + } + } + }); + } + + frm.refresh_field('taxes'); + }, + + set_base_amount: function(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + frappe.model.set_value(cdt, cdn, "base_amount", + flt(flt(row.amount)*row.exchange_rate, precision("base_amount", row))); + } + }); + } +} diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js index 9c1a809f4df..8215efcad39 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js @@ -1,10 +1,9 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -{% include 'erpnext/stock/landed_taxes_and_charges_common.js' %}; - frappe.provide("erpnext.stock"); +erpnext.landed_cost_taxes_and_charges.setup_triggers("Landed Cost Voucher"); erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.StockController { setup() { var me = this; diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 403e04ae60b..e9b7949eb3a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -3,7 +3,7 @@ frappe.provide("erpnext.stock"); frappe.provide("erpnext.accounts.dimensions"); -{% include 'erpnext/stock/landed_taxes_and_charges_common.js' %}; +erpnext.landed_cost_taxes_and_charges.setup_triggers("Stock Entry"); frappe.ui.form.on('Stock Entry', { setup: function(frm) { @@ -56,7 +56,7 @@ frappe.ui.form.on('Stock Entry', { frappe.db.get_value('Stock Settings', {name: 'Stock Settings'}, 'sample_retention_warehouse', (r) => { if (r.sample_retention_warehouse) { - var filters = [ + let filters = [ ["Warehouse", 'company', '=', frm.doc.company], ["Warehouse", "is_group", "=",0], ['Warehouse', 'name', '!=', r.sample_retention_warehouse] @@ -75,17 +75,19 @@ frappe.ui.form.on('Stock Entry', { }); frm.set_query('batch_no', 'items', function(doc, cdt, cdn) { - var item = locals[cdt][cdn]; + let item = locals[cdt][cdn]; + let filters = {}; + if(!item.item_code) { frappe.throw(__("Please enter Item Code to get Batch Number")); } else { if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Send to Subcontractor"], doc.purpose)) { - var filters = { + filters = { 'item_code': item.item_code, 'posting_date': frm.doc.posting_date || frappe.datetime.nowdate() } } else { - var filters = { + filters = { 'item_code': item.item_code } } @@ -686,7 +688,6 @@ frappe.ui.form.on('Stock Entry', { }, process_loss_percentage(frm) { - debugger if (frm.doc.process_loss_percentage) { frm.doc.process_loss_qty = flt((frm.doc.fg_completed_qty * frm.doc.process_loss_percentage) / 100 , precision("process_loss_qty", frm.doc)); refresh_field("process_loss_qty"); diff --git a/erpnext/stock/landed_taxes_and_charges_common.js b/erpnext/stock/landed_taxes_and_charges_common.js deleted file mode 100644 index 1d76a3d95a1..00000000000 --- a/erpnext/stock/landed_taxes_and_charges_common.js +++ /dev/null @@ -1,61 +0,0 @@ -let document_list = ['Landed Cost Voucher', 'Stock Entry', 'Subcontracting Order', 'Subcontracting Receipt']; - -document_list.forEach((doctype) => { - frappe.ui.form.on(doctype, { - refresh: function(frm) { - let tax_field = frm.doc.doctype == 'Landed Cost Voucher' ? 'taxes' : 'additional_costs'; - frm.set_query("expense_account", tax_field, function() { - return { - filters: { - "account_type": ['in', ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation", "Expenses Included In Asset Valuation"]], - "company": frm.doc.company - } - }; - }); - }, - - set_account_currency: function(frm, cdt, cdn) { - let row = locals[cdt][cdn]; - if (row.expense_account) { - frappe.db.get_value('Account', row.expense_account, 'account_currency', function(value) { - frappe.model.set_value(cdt, cdn, "account_currency", value.account_currency); - frm.events.set_exchange_rate(frm, cdt, cdn); - }); - } - }, - - set_exchange_rate: function(frm, cdt, cdn) { - let row = locals[cdt][cdn]; - let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; - - if (row.account_currency == company_currency) { - row.exchange_rate = 1; - frm.set_df_property('taxes', 'hidden', 1, row.name, 'exchange_rate'); - } else if (!row.exchange_rate || row.exchange_rate == 1) { - frm.set_df_property('taxes', 'hidden', 0, row.name, 'exchange_rate'); - frappe.call({ - method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate", - args: { - posting_date: frm.doc.posting_date, - account: row.expense_account, - account_currency: row.account_currency, - company: frm.doc.company - }, - callback: function(r) { - if (r.message) { - frappe.model.set_value(cdt, cdn, "exchange_rate", r.message); - } - } - }); - } - - frm.refresh_field('taxes'); - }, - - set_base_amount: function(frm, cdt, cdn) { - let row = locals[cdt][cdn]; - frappe.model.set_value(cdt, cdn, "base_amount", - flt(flt(row.amount)*row.exchange_rate, precision("base_amount", row))); - } - }); -}); diff --git a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.js b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.js index 15a2ac90912..f2b395ac105 100644 --- a/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.js +++ b/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.js @@ -3,7 +3,7 @@ frappe.provide('erpnext.buying'); -{% include 'erpnext/stock/landed_taxes_and_charges_common.js' %}; +erpnext.landed_cost_taxes_and_charges.setup_triggers("Subcontracting Order"); frappe.ui.form.on('Subcontracting Order', { setup: (frm) => { diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js index 5ee1f7b7169..94a2589b988 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js @@ -3,7 +3,7 @@ frappe.provide('erpnext.buying'); -{% include 'erpnext/stock/landed_taxes_and_charges_common.js' %}; +erpnext.landed_cost_taxes_and_charges.setup_triggers("Subcontracting Receipt"); frappe.ui.form.on('Subcontracting Receipt', { setup: (frm) => { diff --git a/erpnext/www/book_appointment/index.js b/erpnext/www/book_appointment/index.js index d02cdad4cf4..71a34d4e135 100644 --- a/erpnext/www/book_appointment/index.js +++ b/erpnext/www/book_appointment/index.js @@ -243,7 +243,7 @@ async function submit() { } function get_form_data() { - contact = {}; + let contact = {}; let inputs = ['name', 'skype', 'number', 'notes', 'email']; inputs.forEach((id) => contact[id] = document.getElementById(`customer_${id}`).value) return contact