chore: Add landed cost taxes and charges common in bundles

This commit is contained in:
Deepesh Garg 2023-07-22 21:19:48 +05:30
parent 9e791efc82
commit 0b1e78e127
8 changed files with 74 additions and 72 deletions

View File

@ -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'

View File

@ -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)));
}
});
}
}

View File

@ -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;

View File

@ -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");

View File

@ -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)));
}
});
});

View File

@ -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) => {

View File

@ -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) => {

View File

@ -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