mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
style: format controllers with prettier
This commit is contained in:
@@ -10,8 +10,12 @@ erpnext.accounts.taxes = {
|
|||||||
frappe.ui.form.on(doctype, {
|
frappe.ui.form.on(doctype, {
|
||||||
setup: function (frm) {
|
setup: function (frm) {
|
||||||
// set conditional display for rate column in taxes
|
// set conditional display for rate column in taxes
|
||||||
$(frm.wrapper).on('grid-row-render', function(e, grid_row) {
|
$(frm.wrapper).on("grid-row-render", function (e, grid_row) {
|
||||||
if(['Sales Taxes and Charges', 'Purchase Taxes and Charges'].includes(grid_row.doc.doctype)) {
|
if (
|
||||||
|
["Sales Taxes and Charges", "Purchase Taxes and Charges"].includes(
|
||||||
|
grid_row.doc.doctype
|
||||||
|
)
|
||||||
|
) {
|
||||||
me.set_conditional_mandatory_rate_or_amount(grid_row);
|
me.set_conditional_mandatory_rate_or_amount(grid_row);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -22,23 +26,28 @@ erpnext.accounts.taxes = {
|
|||||||
if (frm.cscript.tax_table == "Sales Taxes and Charges") {
|
if (frm.cscript.tax_table == "Sales Taxes and Charges") {
|
||||||
var account_type = ["Tax", "Chargeable", "Expense Account"];
|
var account_type = ["Tax", "Chargeable", "Expense Account"];
|
||||||
} else {
|
} else {
|
||||||
var account_type = ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation"];
|
var account_type = [
|
||||||
|
"Tax",
|
||||||
|
"Chargeable",
|
||||||
|
"Income Account",
|
||||||
|
"Expenses Included In Valuation",
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.tax_account_query",
|
query: "erpnext.controllers.queries.tax_account_query",
|
||||||
filters: {
|
filters: {
|
||||||
"account_type": account_type,
|
account_type: account_type,
|
||||||
"company": doc.company,
|
company: doc.company,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
frm.set_query("cost_center", "taxes", function (doc) {
|
frm.set_query("cost_center", "taxes", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"company": doc.company,
|
company: doc.company,
|
||||||
"is_group": 0
|
is_group: 0,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -49,7 +58,6 @@ erpnext.accounts.taxes = {
|
|||||||
frm.get_docfield("taxes", "rate").reqd = 0;
|
frm.get_docfield("taxes", "rate").reqd = 0;
|
||||||
frm.get_docfield("taxes", "tax_amount").reqd = 0;
|
frm.get_docfield("taxes", "tax_amount").reqd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
taxes_on_form_rendered: function (frm) {
|
taxes_on_form_rendered: function (frm) {
|
||||||
me.set_conditional_mandatory_rate_or_amount(frm.open_grid_row());
|
me.set_conditional_mandatory_rate_or_amount(frm.open_grid_row());
|
||||||
@@ -79,25 +87,39 @@ erpnext.accounts.taxes = {
|
|||||||
|
|
||||||
if (d.account_head && !d.description) {
|
if (d.account_head && !d.description) {
|
||||||
// set description from account head
|
// set description from account head
|
||||||
d.description = d.account_head.split(' - ').slice(0, -1).join(' - ');
|
d.description = d.account_head.split(" - ").slice(0, -1).join(" - ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
if (!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
|
||||||
msg = __("Please select Charge Type first");
|
msg = __("Please select Charge Type first");
|
||||||
d.row_id = "";
|
d.row_id = "";
|
||||||
d.rate = d.tax_amount = 0.0;
|
d.rate = d.tax_amount = 0.0;
|
||||||
} else if ((d.charge_type == 'Actual' || d.charge_type == 'On Net Total' || d.charge_type == 'On Paid Amount') && d.row_id) {
|
} else if (
|
||||||
msg = __("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'");
|
(d.charge_type == "Actual" ||
|
||||||
|
d.charge_type == "On Net Total" ||
|
||||||
|
d.charge_type == "On Paid Amount") &&
|
||||||
|
d.row_id
|
||||||
|
) {
|
||||||
|
msg = __(
|
||||||
|
"Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"
|
||||||
|
);
|
||||||
d.row_id = "";
|
d.row_id = "";
|
||||||
} else if ((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
|
} else if (
|
||||||
|
(d.charge_type == "On Previous Row Amount" || d.charge_type == "On Previous Row Total") &&
|
||||||
|
d.row_id
|
||||||
|
) {
|
||||||
if (d.idx == 1) {
|
if (d.idx == 1) {
|
||||||
msg = __("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row");
|
msg = __(
|
||||||
d.charge_type = '';
|
"Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"
|
||||||
|
);
|
||||||
|
d.charge_type = "";
|
||||||
} else if (!d.row_id) {
|
} else if (!d.row_id) {
|
||||||
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
|
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
|
||||||
d.row_id = "";
|
d.row_id = "";
|
||||||
} else if (d.row_id && d.row_id >= d.idx) {
|
} else if (d.row_id && d.row_id >= d.idx) {
|
||||||
msg = __("Cannot refer row number greater than or equal to current row number for this Charge type");
|
msg = __(
|
||||||
|
"Cannot refer row number greater than or equal to current row number for this Charge type"
|
||||||
|
);
|
||||||
d.row_id = "";
|
d.row_id = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,7 +128,6 @@ erpnext.accounts.taxes = {
|
|||||||
refresh_field("taxes");
|
refresh_field("taxes");
|
||||||
frappe.throw(msg);
|
frappe.throw(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setup_tax_filters: function (doctype) {
|
setup_tax_filters: function (doctype) {
|
||||||
@@ -127,14 +148,14 @@ erpnext.accounts.taxes = {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
method: "erpnext.controllers.accounts_controller.get_tax_rate",
|
method: "erpnext.controllers.accounts_controller.get_tax_rate",
|
||||||
args: {"account_head":d.account_head},
|
args: { account_head: d.account_head },
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (d.charge_type !== "Actual") {
|
if (d.charge_type !== "Actual") {
|
||||||
frappe.model.set_value(cdt, cdn, "rate", r.message.tax_rate || 0);
|
frappe.model.set_value(cdt, cdn, "rate", r.message.tax_rate || 0);
|
||||||
}
|
}
|
||||||
frappe.model.set_value(cdt, cdn, "description", r.message.account_name);
|
frappe.model.set_value(cdt, cdn, "description", r.message.account_name);
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
row_id: function (frm, cdt, cdn) {
|
row_id: function (frm, cdt, cdn) {
|
||||||
@@ -153,7 +174,7 @@ erpnext.accounts.taxes = {
|
|||||||
me.set_conditional_mandatory_rate_or_amount(open_form);
|
me.set_conditional_mandatory_rate_or_amount(open_form);
|
||||||
} else {
|
} else {
|
||||||
// apply in current row
|
// apply in current row
|
||||||
me.set_conditional_mandatory_rate_or_amount(frm.get_field('taxes').grid.get_row(cdn));
|
me.set_conditional_mandatory_rate_or_amount(frm.get_field("taxes").grid.get_row(cdn));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
included_in_print_rate: function (frm, cdt, cdn) {
|
included_in_print_rate: function (frm, cdt, cdn) {
|
||||||
@@ -166,20 +187,24 @@ erpnext.accounts.taxes = {
|
|||||||
refresh_field("included_in_print_rate", tax.name, tax.parentfield);
|
refresh_field("included_in_print_rate", tax.name, tax.parentfield);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
validate_inclusive_tax: function (tax, frm) {
|
validate_inclusive_tax: function (tax, frm) {
|
||||||
this.frm = this.frm || frm;
|
this.frm = this.frm || frm;
|
||||||
let actual_type_error = function () {
|
let actual_type_error = function () {
|
||||||
var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
|
var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx]);
|
||||||
frappe.throw(msg);
|
frappe.throw(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
let on_previous_row_error = function (row_range) {
|
let on_previous_row_error = function (row_range) {
|
||||||
var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included",
|
var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included", [
|
||||||
[tax.idx, __(tax.doctype), tax.charge_type, row_range])
|
tax.idx,
|
||||||
|
__(tax.doctype),
|
||||||
|
tax.charge_type,
|
||||||
|
row_range,
|
||||||
|
]);
|
||||||
frappe.throw(msg);
|
frappe.throw(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -187,14 +212,17 @@ erpnext.accounts.taxes = {
|
|||||||
if (tax.charge_type == "Actual") {
|
if (tax.charge_type == "Actual") {
|
||||||
// inclusive tax cannot be of type Actual
|
// inclusive tax cannot be of type Actual
|
||||||
actual_type_error();
|
actual_type_error();
|
||||||
} else if (tax.charge_type == "On Previous Row Amount" && this.frm &&
|
} else if (
|
||||||
|
tax.charge_type == "On Previous Row Amount" &&
|
||||||
|
this.frm &&
|
||||||
!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)
|
!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)
|
||||||
) {
|
) {
|
||||||
// referred row should also be an inclusive tax
|
// referred row should also be an inclusive tax
|
||||||
on_previous_row_error(tax.row_id);
|
on_previous_row_error(tax.row_id);
|
||||||
} else if (tax.charge_type == "On Previous Row Total" && this.frm) {
|
} else if (tax.charge_type == "On Previous Row Total" && this.frm) {
|
||||||
var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
|
var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id), function (t) {
|
||||||
function(t) { return cint(t.included_in_print_rate) ? null : t; });
|
return cint(t.included_in_print_rate) ? null : t;
|
||||||
|
});
|
||||||
if (taxes_not_included.length > 0) {
|
if (taxes_not_included.length > 0) {
|
||||||
// all rows above this tax should be inclusive
|
// all rows above this tax should be inclusive
|
||||||
on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
|
on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
|
||||||
@@ -203,18 +231,18 @@ erpnext.accounts.taxes = {
|
|||||||
frappe.throw(__("Valuation type charges can not marked as Inclusive"));
|
frappe.throw(__("Valuation type charges can not marked as Inclusive"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
erpnext.accounts.payment_triggers = {
|
erpnext.accounts.payment_triggers = {
|
||||||
setup: function (doctype) {
|
setup: function (doctype) {
|
||||||
frappe.ui.form.on(doctype, {
|
frappe.ui.form.on(doctype, {
|
||||||
allocate_advances_automatically(frm) {
|
allocate_advances_automatically(frm) {
|
||||||
frm.trigger('fetch_advances');
|
frm.trigger("fetch_advances");
|
||||||
},
|
},
|
||||||
|
|
||||||
only_include_allocated_payments(frm) {
|
only_include_allocated_payments(frm) {
|
||||||
frm.trigger('fetch_advances');
|
frm.trigger("fetch_advances");
|
||||||
},
|
},
|
||||||
|
|
||||||
fetch_advances(frm) {
|
fetch_advances(frm) {
|
||||||
@@ -224,13 +252,13 @@ erpnext.accounts.payment_triggers = {
|
|||||||
method: "set_advances",
|
method: "set_advances",
|
||||||
callback: function (r, rt) {
|
callback: function (r, rt) {
|
||||||
refresh_field("advances");
|
refresh_field("advances");
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
erpnext.accounts.pos = {
|
erpnext.accounts.pos = {
|
||||||
setup: function (doctype) {
|
setup: function (doctype) {
|
||||||
@@ -238,9 +266,9 @@ erpnext.accounts.pos = {
|
|||||||
mode_of_payment: function (frm, cdt, cdn) {
|
mode_of_payment: function (frm, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
get_payment_mode_account(frm, d.mode_of_payment, function (account) {
|
get_payment_mode_account(frm, d.mode_of_payment, function (account) {
|
||||||
frappe.model.set_value(cdt, cdn, 'account', account)
|
frappe.model.set_value(cdt, cdn, "account", account);
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -256,14 +284,14 @@ erpnext.accounts.pos = {
|
|||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
|
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
|
||||||
args: {
|
args: {
|
||||||
"mode_of_payment": mode_of_payment,
|
mode_of_payment: mode_of_payment,
|
||||||
"company": frm.doc.company
|
company: frm.doc.company,
|
||||||
},
|
},
|
||||||
callback: function (r, rt) {
|
callback: function (r, rt) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
callback(r.message.account)
|
callback(r.message.account);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ erpnext.buying = {
|
|||||||
this.setup_queries(doc, cdt, cdn);
|
this.setup_queries(doc, cdt, cdn);
|
||||||
super.onload();
|
super.onload();
|
||||||
|
|
||||||
this.frm.set_query('shipping_rule', function() {
|
this.frm.set_query("shipping_rule", function () {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"shipping_rule_type": "Buying"
|
shipping_rule_type: "Buying",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -33,29 +33,28 @@ erpnext.buying = {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.frm.doc.__islocal
|
if (
|
||||||
&& frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) {
|
this.frm.doc.__islocal &&
|
||||||
|
frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")
|
||||||
|
) {
|
||||||
var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total");
|
var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total");
|
||||||
var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total);
|
var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total);
|
||||||
this.frm.set_value("disable_rounded_total", disable);
|
this.frm.set_value("disable_rounded_total", disable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// no idea where me is coming from
|
// no idea where me is coming from
|
||||||
if(this.frm.get_field('shipping_address')) {
|
if (this.frm.get_field("shipping_address")) {
|
||||||
this.frm.set_query("shipping_address", () => {
|
this.frm.set_query("shipping_address", () => {
|
||||||
if (this.frm.doc.customer) {
|
if (this.frm.doc.customer) {
|
||||||
return {
|
return {
|
||||||
query: 'frappe.contacts.doctype.address.address.address_query',
|
query: "frappe.contacts.doctype.address.address.address_query",
|
||||||
filters: { link_doctype: 'Customer', link_name: this.frm.doc.customer }
|
filters: { link_doctype: "Customer", link_name: this.frm.doc.customer },
|
||||||
};
|
};
|
||||||
} else
|
} else return erpnext.queries.company_address_query(this.frm.doc);
|
||||||
return erpnext.queries.company_address_query(this.frm.doc)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.frm.get_field('dispatch_address')) {
|
if (this.frm.get_field("dispatch_address")) {
|
||||||
this.frm.set_query("dispatch_address", () => {
|
this.frm.set_query("dispatch_address", () => {
|
||||||
return erpnext.queries.address_query(this.frm.doc);
|
return erpnext.queries.address_query(this.frm.doc);
|
||||||
});
|
});
|
||||||
@@ -68,73 +67,74 @@ erpnext.buying = {
|
|||||||
if (this.frm.fields_dict.buying_price_list) {
|
if (this.frm.fields_dict.buying_price_list) {
|
||||||
this.frm.set_query("buying_price_list", function () {
|
this.frm.set_query("buying_price_list", function () {
|
||||||
return {
|
return {
|
||||||
filters: { 'buying': 1 }
|
filters: { buying: 1 },
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.frm.fields_dict.tc_name) {
|
if (this.frm.fields_dict.tc_name) {
|
||||||
this.frm.set_query("tc_name", function () {
|
this.frm.set_query("tc_name", function () {
|
||||||
return {
|
return {
|
||||||
filters: { 'buying': 1 }
|
filters: { buying: 1 },
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
me.frm.set_query('supplier', erpnext.queries.supplier);
|
me.frm.set_query("supplier", erpnext.queries.supplier);
|
||||||
me.frm.set_query('contact_person', erpnext.queries.contact_query);
|
me.frm.set_query("contact_person", erpnext.queries.contact_query);
|
||||||
me.frm.set_query('supplier_address', erpnext.queries.address_query);
|
me.frm.set_query("supplier_address", erpnext.queries.address_query);
|
||||||
|
|
||||||
me.frm.set_query('billing_address', erpnext.queries.company_address_query);
|
me.frm.set_query("billing_address", erpnext.queries.company_address_query);
|
||||||
erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype);
|
erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype);
|
||||||
|
|
||||||
this.frm.set_query("item_code", "items", function () {
|
this.frm.set_query("item_code", "items", function () {
|
||||||
if (me.frm.doc.is_subcontracted) {
|
if (me.frm.doc.is_subcontracted) {
|
||||||
var filters = {'supplier': me.frm.doc.supplier};
|
var filters = { supplier: me.frm.doc.supplier };
|
||||||
if (me.frm.doc.is_old_subcontracting_flow) {
|
if (me.frm.doc.is_old_subcontracting_flow) {
|
||||||
filters["is_sub_contracted_item"] = 1;
|
filters["is_sub_contracted_item"] = 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
filters["is_stock_item"] = 0;
|
filters["is_stock_item"] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.item_query",
|
query: "erpnext.controllers.queries.item_query",
|
||||||
filters: filters
|
filters: filters,
|
||||||
}
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.item_query",
|
query: "erpnext.controllers.queries.item_query",
|
||||||
filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1, 'has_variants': 0}
|
filters: { supplier: me.frm.doc.supplier, is_purchase_item: 1, has_variants: 0 },
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
this.frm.set_query("manufacturer", "items", function (doc, cdt, cdn) {
|
this.frm.set_query("manufacturer", "items", function (doc, cdt, cdn) {
|
||||||
const row = locals[cdt][cdn];
|
const row = locals[cdt][cdn];
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.item_manufacturer_query",
|
query: "erpnext.controllers.queries.item_manufacturer_query",
|
||||||
filters:{ 'item_code': row.item_code }
|
filters: { item_code: row.item_code },
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
|
if (this.frm.fields_dict["items"].grid.get_field("item_code")) {
|
||||||
this.frm.set_query("item_tax_template", "items", function (doc, cdt, cdn) {
|
this.frm.set_query("item_tax_template", "items", function (doc, cdt, cdn) {
|
||||||
return me.set_query_for_item_tax_template(doc, cdt, cdn)
|
return me.set_query_for_item_tax_template(doc, cdt, cdn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh(doc) {
|
refresh(doc) {
|
||||||
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
|
frappe.dynamic_link = { doc: this.frm.doc, fieldname: "supplier", doctype: "Supplier" };
|
||||||
|
|
||||||
this.frm.toggle_display("supplier_name",
|
this.frm.toggle_display(
|
||||||
(this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
|
"supplier_name",
|
||||||
|
this.frm.doc.supplier_name && this.frm.doc.supplier_name !== this.frm.doc.supplier
|
||||||
|
);
|
||||||
|
|
||||||
if(this.frm.doc.docstatus==0 &&
|
if (
|
||||||
(this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) {
|
this.frm.doc.docstatus == 0 &&
|
||||||
|
(this.frm.doctype === "Purchase Order" || this.frm.doctype === "Material Request")
|
||||||
|
) {
|
||||||
this.set_from_product_bundle();
|
this.set_from_product_bundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,12 +143,15 @@ erpnext.buying = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggle_subcontracting_fields() {
|
toggle_subcontracting_fields() {
|
||||||
if (['Purchase Receipt', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
|
if (["Purchase Receipt", "Purchase Invoice"].includes(this.frm.doc.doctype)) {
|
||||||
this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty',
|
this.frm.fields_dict.supplied_items.grid.update_docfield_property(
|
||||||
'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM');
|
"consumed_qty",
|
||||||
|
"read_only",
|
||||||
|
this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === "BOM"
|
||||||
|
);
|
||||||
|
|
||||||
this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1);
|
this.frm.set_df_property("supplied_items", "cannot_add_rows", 1);
|
||||||
this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1);
|
this.frm.set_df_property("supplied_items", "cannot_delete_rows", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ erpnext.buying = {
|
|||||||
args: {
|
args: {
|
||||||
name: this.frm.doc.company,
|
name: this.frm.doc.company,
|
||||||
billing_address: this.frm.doc.billing_address,
|
billing_address: this.frm.doc.billing_address,
|
||||||
shipping_address: this.frm.doc.shipping_address
|
shipping_address: this.frm.doc.shipping_address,
|
||||||
},
|
},
|
||||||
callback: (r) => {
|
callback: (r) => {
|
||||||
this.frm.set_value("billing_address", r.message.primary_address || "");
|
this.frm.set_value("billing_address", r.message.primary_address || "");
|
||||||
@@ -176,12 +179,17 @@ erpnext.buying = {
|
|||||||
this.frm.set_value("shipping_address", r.message.shipping_address || "");
|
this.frm.set_value("shipping_address", r.message.shipping_address || "");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
erpnext.utils.set_letter_head(this.frm)
|
erpnext.utils.set_letter_head(this.frm);
|
||||||
}
|
}
|
||||||
|
|
||||||
supplier_address() {
|
supplier_address() {
|
||||||
erpnext.utils.get_address_display(this.frm);
|
erpnext.utils.get_address_display(this.frm);
|
||||||
erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address");
|
erpnext.utils.set_taxes_from_address(
|
||||||
|
this.frm,
|
||||||
|
"supplier_address",
|
||||||
|
"supplier_address",
|
||||||
|
"supplier_address"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
buying_price_list() {
|
buying_price_list() {
|
||||||
@@ -201,24 +209,33 @@ erpnext.buying = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qty(doc, cdt, cdn) {
|
qty(doc, cdt, cdn) {
|
||||||
if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && doc.update_stock)) {
|
if (
|
||||||
this.calculate_received_qty(doc, cdt, cdn)
|
doc.doctype == "Purchase Receipt" ||
|
||||||
|
(doc.doctype == "Purchase Invoice" && doc.update_stock)
|
||||||
|
) {
|
||||||
|
this.calculate_received_qty(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
super.qty(doc, cdt, cdn);
|
super.qty(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
rejected_qty(doc, cdt, cdn) {
|
rejected_qty(doc, cdt, cdn) {
|
||||||
this.calculate_received_qty(doc, cdt, cdn)
|
this.calculate_received_qty(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_received_qty(doc, cdt, cdn) {
|
calculate_received_qty(doc, cdt, cdn) {
|
||||||
var item = frappe.get_doc(cdt, cdn);
|
var item = frappe.get_doc(cdt, cdn);
|
||||||
frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
|
frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
|
||||||
|
|
||||||
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return }
|
if (
|
||||||
|
!doc.is_return &&
|
||||||
|
this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item));
|
let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item));
|
||||||
let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty);
|
let received_stock_qty =
|
||||||
|
flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty);
|
||||||
|
|
||||||
frappe.model.set_value(cdt, cdn, "received_qty", received_qty);
|
frappe.model.set_value(cdt, cdn, "received_qty", received_qty);
|
||||||
frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty);
|
frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty);
|
||||||
@@ -229,18 +246,26 @@ erpnext.buying = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate_negative_quantity(cdt, cdn, item, fieldnames) {
|
validate_negative_quantity(cdt, cdn, item, fieldnames) {
|
||||||
if(!item || !fieldnames) { return }
|
if (!item || !fieldnames) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var is_negative_qty = false;
|
var is_negative_qty = false;
|
||||||
for (var i = 0; i < fieldnames.length; i++) {
|
for (var i = 0; i < fieldnames.length; i++) {
|
||||||
if (item[fieldnames[i]] < 0) {
|
if (item[fieldnames[i]] < 0) {
|
||||||
frappe.msgprint(__("Row #{0}: {1} can not be negative for item {2}", [item.idx,__(frappe.meta.get_label(cdt, fieldnames[i], cdn)), item.item_code]));
|
frappe.msgprint(
|
||||||
|
__("Row #{0}: {1} can not be negative for item {2}", [
|
||||||
|
item.idx,
|
||||||
|
__(frappe.meta.get_label(cdt, fieldnames[i], cdn)),
|
||||||
|
item.item_code,
|
||||||
|
])
|
||||||
|
);
|
||||||
is_negative_qty = true;
|
is_negative_qty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_negative_qty
|
return is_negative_qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
warehouse(doc, cdt, cdn) {
|
warehouse(doc, cdt, cdn) {
|
||||||
@@ -253,8 +278,8 @@ erpnext.buying = {
|
|||||||
item_code: item.item_code,
|
item_code: item.item_code,
|
||||||
warehouse: item.warehouse,
|
warehouse: item.warehouse,
|
||||||
company: doc.company,
|
company: doc.company,
|
||||||
include_child_warehouses: true
|
include_child_warehouses: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,8 +287,7 @@ erpnext.buying = {
|
|||||||
project(doc, cdt, cdn) {
|
project(doc, cdt, cdn) {
|
||||||
var item = frappe.get_doc(cdt, cdn);
|
var item = frappe.get_doc(cdt, cdn);
|
||||||
if (item.project) {
|
if (item.project) {
|
||||||
$.each(this.frm.doc["items"] || [],
|
$.each(this.frm.doc["items"] || [], function (i, other_item) {
|
||||||
function(i, other_item) {
|
|
||||||
if (!other_item.project) {
|
if (!other_item.project) {
|
||||||
other_item.project = item.project;
|
other_item.project = item.project;
|
||||||
refresh_field("project", other_item.name, other_item.parentfield);
|
refresh_field("project", other_item.name, other_item.parentfield);
|
||||||
@@ -291,26 +315,42 @@ erpnext.buying = {
|
|||||||
|
|
||||||
set_from_product_bundle() {
|
set_from_product_bundle() {
|
||||||
var me = this;
|
var me = this;
|
||||||
this.frm.add_custom_button(__("Product Bundle"), function() {
|
this.frm.add_custom_button(
|
||||||
|
__("Product Bundle"),
|
||||||
|
function () {
|
||||||
erpnext.buying.get_items_from_product_bundle(me.frm);
|
erpnext.buying.get_items_from_product_bundle(me.frm);
|
||||||
}, __("Get Items From"));
|
},
|
||||||
|
__("Get Items From")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
shipping_address() {
|
shipping_address() {
|
||||||
var me = this;
|
var me = this;
|
||||||
erpnext.utils.get_address_display(this.frm, "shipping_address",
|
erpnext.utils.get_address_display(
|
||||||
"shipping_address_display", true);
|
this.frm,
|
||||||
|
"shipping_address",
|
||||||
|
"shipping_address_display",
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_address() {
|
dispatch_address() {
|
||||||
var me = this;
|
var me = this;
|
||||||
erpnext.utils.get_address_display(this.frm, "dispatch_address",
|
erpnext.utils.get_address_display(
|
||||||
"dispatch_address_display", true);
|
this.frm,
|
||||||
|
"dispatch_address",
|
||||||
|
"dispatch_address_display",
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
billing_address() {
|
billing_address() {
|
||||||
erpnext.utils.get_address_display(this.frm, "billing_address",
|
erpnext.utils.get_address_display(
|
||||||
"billing_address_display", true);
|
this.frm,
|
||||||
|
"billing_address",
|
||||||
|
"billing_address_display",
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tc_name() {
|
tc_name() {
|
||||||
@@ -323,16 +363,22 @@ erpnext.buying = {
|
|||||||
method: "frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
|
method: "frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
|
||||||
args: {
|
args: {
|
||||||
docname: doc.auto_repeat,
|
docname: doc.auto_repeat,
|
||||||
reference:doc.name
|
reference: doc.name,
|
||||||
},
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (r.message == "success") {
|
if (r.message == "success") {
|
||||||
frappe.show_alert({message:__("Auto repeat document updated"), indicator:'green'});
|
frappe.show_alert({
|
||||||
|
message: __("Auto repeat document updated"),
|
||||||
|
indicator: "green",
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
frappe.show_alert({message:__("An error occurred during the update process"), indicator:'red'});
|
frappe.show_alert({
|
||||||
|
message: __("An error occurred during the update process"),
|
||||||
|
indicator: "red",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,14 +389,14 @@ erpnext.buying = {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.stock.doctype.item_manufacturer.item_manufacturer.get_item_manufacturer_part_no",
|
method: "erpnext.stock.doctype.item_manufacturer.item_manufacturer.get_item_manufacturer_part_no",
|
||||||
args: {
|
args: {
|
||||||
'item_code': row.item_code,
|
item_code: row.item_code,
|
||||||
'manufacturer': row.manufacturer
|
manufacturer: row.manufacturer,
|
||||||
},
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
frappe.model.set_value(cdt, cdn, 'manufacturer_part_no', r.message);
|
frappe.model.set_value(cdt, cdn, "manufacturer_part_no", r.message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,19 +405,22 @@ erpnext.buying = {
|
|||||||
const row = locals[cdt][cdn];
|
const row = locals[cdt][cdn];
|
||||||
|
|
||||||
if (row.manufacturer_part_no) {
|
if (row.manufacturer_part_no) {
|
||||||
frappe.model.get_value('Item Manufacturer',
|
frappe.model.get_value(
|
||||||
|
"Item Manufacturer",
|
||||||
{
|
{
|
||||||
'item_code': row.item_code,
|
item_code: row.item_code,
|
||||||
'manufacturer': row.manufacturer,
|
manufacturer: row.manufacturer,
|
||||||
'manufacturer_part_no': row.manufacturer_part_no
|
manufacturer_part_no: row.manufacturer_part_no,
|
||||||
},
|
},
|
||||||
'name',
|
"name",
|
||||||
function (data) {
|
function (data) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
let msg = {
|
let msg = {
|
||||||
message: __("Manufacturer Part Number <b>{0}</b> is invalid", [row.manufacturer_part_no]),
|
message: __("Manufacturer Part Number <b>{0}</b> is invalid", [
|
||||||
title: __("Invalid Part Number")
|
row.manufacturer_part_no,
|
||||||
}
|
]),
|
||||||
|
title: __("Invalid Part Number"),
|
||||||
|
};
|
||||||
frappe.throw(msg);
|
frappe.throw(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,8 +433,7 @@ erpnext.buying = {
|
|||||||
let me = this;
|
let me = this;
|
||||||
let fields = ["has_batch_no", "has_serial_no"];
|
let fields = ["has_batch_no", "has_serial_no"];
|
||||||
|
|
||||||
frappe.db.get_value("Item", item.item_code, fields)
|
frappe.db.get_value("Item", item.item_code, fields).then((r) => {
|
||||||
.then((r) => {
|
|
||||||
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
|
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
item[field] = r.message[field];
|
item[field] = r.message[field];
|
||||||
@@ -394,8 +442,7 @@ erpnext.buying = {
|
|||||||
item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
|
item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward";
|
||||||
item.is_rejected = false;
|
item.is_rejected = false;
|
||||||
|
|
||||||
new erpnext.SerialBatchPackageSelector(
|
new erpnext.SerialBatchPackageSelector(me.frm, item, (r) => {
|
||||||
me.frm, item, (r) => {
|
|
||||||
if (r) {
|
if (r) {
|
||||||
let qty = Math.abs(r.total_qty);
|
let qty = Math.abs(r.total_qty);
|
||||||
if (doc.is_return) {
|
if (doc.is_return) {
|
||||||
@@ -403,10 +450,15 @@ erpnext.buying = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let update_values = {
|
let update_values = {
|
||||||
"serial_and_batch_bundle": r.name,
|
serial_and_batch_bundle: r.name,
|
||||||
"use_serial_batch_fields": 0,
|
use_serial_batch_fields: 0,
|
||||||
"qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
|
qty:
|
||||||
}
|
qty /
|
||||||
|
flt(
|
||||||
|
item.conversion_factor || 1,
|
||||||
|
precision("conversion_factor", item)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
if (r.warehouse) {
|
if (r.warehouse) {
|
||||||
update_values["warehouse"] = r.warehouse;
|
update_values["warehouse"] = r.warehouse;
|
||||||
@@ -414,8 +466,7 @@ erpnext.buying = {
|
|||||||
|
|
||||||
frappe.model.set_value(item.doctype, item.name, update_values);
|
frappe.model.set_value(item.doctype, item.name, update_values);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -425,8 +476,7 @@ erpnext.buying = {
|
|||||||
let me = this;
|
let me = this;
|
||||||
let fields = ["has_batch_no", "has_serial_no"];
|
let fields = ["has_batch_no", "has_serial_no"];
|
||||||
|
|
||||||
frappe.db.get_value("Item", item.item_code, fields)
|
frappe.db.get_value("Item", item.item_code, fields).then((r) => {
|
||||||
.then((r) => {
|
|
||||||
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
|
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
item[field] = r.message[field];
|
item[field] = r.message[field];
|
||||||
@@ -435,8 +485,7 @@ erpnext.buying = {
|
|||||||
item.type_of_transaction = !doc.is_return > 0 ? "Inward" : "Outward";
|
item.type_of_transaction = !doc.is_return > 0 ? "Inward" : "Outward";
|
||||||
item.is_rejected = true;
|
item.is_rejected = true;
|
||||||
|
|
||||||
new erpnext.SerialBatchPackageSelector(
|
new erpnext.SerialBatchPackageSelector(me.frm, item, (r) => {
|
||||||
me.frm, item, (r) => {
|
|
||||||
if (r) {
|
if (r) {
|
||||||
let qty = Math.abs(r.total_qty);
|
let qty = Math.abs(r.total_qty);
|
||||||
if (doc.is_return) {
|
if (doc.is_return) {
|
||||||
@@ -444,10 +493,15 @@ erpnext.buying = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let update_values = {
|
let update_values = {
|
||||||
"rejected_serial_and_batch_bundle": r.name,
|
rejected_serial_and_batch_bundle: r.name,
|
||||||
"use_serial_batch_fields": 0,
|
use_serial_batch_fields: 0,
|
||||||
"rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item))
|
rejected_qty:
|
||||||
}
|
qty /
|
||||||
|
flt(
|
||||||
|
item.conversion_factor || 1,
|
||||||
|
precision("conversion_factor", item)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
if (r.warehouse) {
|
if (r.warehouse) {
|
||||||
update_values["rejected_warehouse"] = r.warehouse;
|
update_values["rejected_warehouse"] = r.warehouse;
|
||||||
@@ -455,26 +509,25 @@ erpnext.buying = {
|
|||||||
|
|
||||||
frappe.model.set_value(item.doctype, item.name, update_values);
|
frappe.model.set_value(item.doctype, item.name, update_values);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
erpnext.buying.link_to_mrs = function (frm) {
|
erpnext.buying.link_to_mrs = function (frm) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.buying.utils.get_linked_material_requests",
|
method: "erpnext.buying.utils.get_linked_material_requests",
|
||||||
args: {
|
args: {
|
||||||
items: frm.doc.items.map((item) => item.item_code)
|
items: frm.doc.items.map((item) => item.item_code),
|
||||||
},
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (!r.message || r.message.length == 0) {
|
if (!r.message || r.message.length == 0) {
|
||||||
frappe.throw({
|
frappe.throw({
|
||||||
message: __("No pending Material Requests found to link for the given items."),
|
message: __("No pending Material Requests found to link for the given items."),
|
||||||
title: __("Note")
|
title: __("Note"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,8 +535,12 @@ erpnext.buying.link_to_mrs = function(frm) {
|
|||||||
for (let item of frm.doc.items) {
|
for (let item of frm.doc.items) {
|
||||||
var qty = item.qty;
|
var qty = item.qty;
|
||||||
(r.message[0] || []).forEach(function (d) {
|
(r.message[0] || []).forEach(function (d) {
|
||||||
if (d.qty > 0 && qty > 0 && item.item_code == d.item_code && !item.material_request_item)
|
if (
|
||||||
{
|
d.qty > 0 &&
|
||||||
|
qty > 0 &&
|
||||||
|
item.item_code == d.item_code &&
|
||||||
|
!item.material_request_item
|
||||||
|
) {
|
||||||
item.material_request = d.mr_name;
|
item.material_request = d.mr_name;
|
||||||
item.material_request_item = d.mr_item;
|
item.material_request_item = d.mr_item;
|
||||||
var my_qty = Math.min(qty, d.qty);
|
var my_qty = Math.min(qty, d.qty);
|
||||||
@@ -492,15 +549,15 @@ erpnext.buying.link_to_mrs = function(frm) {
|
|||||||
item.stock_qty = my_qty * item.conversion_factor;
|
item.stock_qty = my_qty * item.conversion_factor;
|
||||||
item.qty = my_qty;
|
item.qty = my_qty;
|
||||||
|
|
||||||
frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")");
|
frappe.msgprint(
|
||||||
if (qty > 0)
|
"Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")"
|
||||||
{
|
);
|
||||||
|
if (qty > 0) {
|
||||||
frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
|
frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
|
||||||
var newrow = frappe.model.add_child(frm.doc, item.doctype, "items");
|
var newrow = frappe.model.add_child(frm.doc, item.doctype, "items");
|
||||||
item_length++;
|
item_length++;
|
||||||
|
|
||||||
for (var key in item)
|
for (var key in item) {
|
||||||
{
|
|
||||||
newrow[key] = item[key];
|
newrow[key] = item[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,15 +567,14 @@ erpnext.buying.link_to_mrs = function(frm) {
|
|||||||
|
|
||||||
newrow["material_request"] = "";
|
newrow["material_request"] = "";
|
||||||
newrow["material_request_item"] = "";
|
newrow["material_request_item"] = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
refresh_field("items");
|
refresh_field("items");
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
erpnext.buying.get_default_bom = function (frm) {
|
erpnext.buying.get_default_bom = function (frm) {
|
||||||
$.each(frm.doc["items"] || [], function (i, d) {
|
$.each(frm.doc["items"] || [], function (i, d) {
|
||||||
@@ -527,38 +583,38 @@ erpnext.buying.get_default_bom = function(frm) {
|
|||||||
type: "GET",
|
type: "GET",
|
||||||
method: "erpnext.stock.get_item_details.get_default_bom",
|
method: "erpnext.stock.get_item_details.get_default_bom",
|
||||||
args: {
|
args: {
|
||||||
"item_code": d.item_code,
|
item_code: d.item_code,
|
||||||
},
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (r) {
|
if (r) {
|
||||||
frappe.model.set_value(d.doctype, d.name, "bom", r.message);
|
frappe.model.set_value(d.doctype, d.name, "bom", r.message);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
erpnext.buying.get_items_from_product_bundle = function (frm) {
|
erpnext.buying.get_items_from_product_bundle = function (frm) {
|
||||||
var dialog = new frappe.ui.Dialog({
|
var dialog = new frappe.ui.Dialog({
|
||||||
title: __("Get Items from Product Bundle"),
|
title: __("Get Items from Product Bundle"),
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
"fieldtype": "Link",
|
fieldtype: "Link",
|
||||||
"label": __("Product Bundle"),
|
label: __("Product Bundle"),
|
||||||
"fieldname": "product_bundle",
|
fieldname: "product_bundle",
|
||||||
"options":"Product Bundle",
|
options: "Product Bundle",
|
||||||
"reqd": 1
|
reqd: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldtype": "Currency",
|
fieldtype: "Currency",
|
||||||
"label": __("Quantity"),
|
label: __("Quantity"),
|
||||||
"fieldname": "quantity",
|
fieldname: "quantity",
|
||||||
"reqd": 1,
|
reqd: 1,
|
||||||
"default": 1
|
default: 1,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
primary_action_label: 'Get Items',
|
primary_action_label: "Get Items",
|
||||||
primary_action(args) {
|
primary_action(args) {
|
||||||
if (!args) return;
|
if (!args) return;
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
@@ -581,7 +637,7 @@ erpnext.buying.get_items_from_product_bundle = function(frm) {
|
|||||||
is_subcontracted: frm.doc.is_subcontracted,
|
is_subcontracted: frm.doc.is_subcontracted,
|
||||||
transaction_date: frm.doc.transaction_date || frm.doc.posting_date,
|
transaction_date: frm.doc.transaction_date || frm.doc.posting_date,
|
||||||
ignore_pricing_rule: frm.doc.ignore_pricing_rule,
|
ignore_pricing_rule: frm.doc.ignore_pricing_rule,
|
||||||
doctype: frm.doc.doctype
|
doctype: frm.doc.doctype,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
freeze: true,
|
freeze: true,
|
||||||
@@ -615,10 +671,10 @@ erpnext.buying.get_items_from_product_bundle = function(frm) {
|
|||||||
}
|
}
|
||||||
frm.refresh_field("items");
|
frm.refresh_field("items");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
|
|||||||
if (row.barcode) {
|
if (row.barcode) {
|
||||||
erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
|
erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
|
||||||
frappe.model.set_value(cdt, cdn, {
|
frappe.model.set_value(cdt, cdn, {
|
||||||
"item_code": r.message.item_code,
|
item_code: r.message.item_code,
|
||||||
"qty": 1,
|
qty: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,30 +32,30 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
|
|||||||
|
|
||||||
setup_posting_date_time_check() {
|
setup_posting_date_time_check() {
|
||||||
// make posting date default and read only unless explictly checked
|
// make posting date default and read only unless explictly checked
|
||||||
frappe.ui.form.on(this.frm.doctype, 'set_posting_date_and_time_read_only', function(frm) {
|
frappe.ui.form.on(this.frm.doctype, "set_posting_date_and_time_read_only", function (frm) {
|
||||||
if (frm.doc.docstatus == 0 && frm.doc.set_posting_time) {
|
if (frm.doc.docstatus == 0 && frm.doc.set_posting_time) {
|
||||||
frm.set_df_property('posting_date', 'read_only', 0);
|
frm.set_df_property("posting_date", "read_only", 0);
|
||||||
frm.set_df_property('posting_time', 'read_only', 0);
|
frm.set_df_property("posting_time", "read_only", 0);
|
||||||
} else {
|
} else {
|
||||||
frm.set_df_property('posting_date', 'read_only', 1);
|
frm.set_df_property("posting_date", "read_only", 1);
|
||||||
frm.set_df_property('posting_time', 'read_only', 1);
|
frm.set_df_property("posting_time", "read_only", 1);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
frappe.ui.form.on(this.frm.doctype, 'set_posting_time', function(frm) {
|
|
||||||
frm.trigger('set_posting_date_and_time_read_only');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
frappe.ui.form.on(this.frm.doctype, 'refresh', function(frm) {
|
frappe.ui.form.on(this.frm.doctype, "set_posting_time", function (frm) {
|
||||||
|
frm.trigger("set_posting_date_and_time_read_only");
|
||||||
|
});
|
||||||
|
|
||||||
|
frappe.ui.form.on(this.frm.doctype, "refresh", function (frm) {
|
||||||
// set default posting date / time
|
// set default posting date / time
|
||||||
if (frm.doc.docstatus == 0) {
|
if (frm.doc.docstatus == 0) {
|
||||||
if (!frm.doc.posting_date) {
|
if (!frm.doc.posting_date) {
|
||||||
frm.set_value('posting_date', frappe.datetime.nowdate());
|
frm.set_value("posting_date", frappe.datetime.nowdate());
|
||||||
}
|
}
|
||||||
if (!frm.doc.posting_time) {
|
if (!frm.doc.posting_time) {
|
||||||
frm.set_value('posting_time', frappe.datetime.now_time());
|
frm.set_value("posting_time", frappe.datetime.now_time());
|
||||||
}
|
}
|
||||||
frm.trigger('set_posting_date_and_time_read_only');
|
frm.trigger("set_posting_date_and_time_read_only");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -63,36 +63,43 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
|
|||||||
show_stock_ledger() {
|
show_stock_ledger() {
|
||||||
var me = this;
|
var me = this;
|
||||||
if (this.frm.doc.docstatus > 0) {
|
if (this.frm.doc.docstatus > 0) {
|
||||||
cur_frm.add_custom_button(__("Stock Ledger"), function() {
|
cur_frm.add_custom_button(
|
||||||
|
__("Stock Ledger"),
|
||||||
|
function () {
|
||||||
frappe.route_options = {
|
frappe.route_options = {
|
||||||
voucher_no: me.frm.doc.name,
|
voucher_no: me.frm.doc.name,
|
||||||
from_date: me.frm.doc.posting_date,
|
from_date: me.frm.doc.posting_date,
|
||||||
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
|
to_date: moment(me.frm.doc.modified).format("YYYY-MM-DD"),
|
||||||
company: me.frm.doc.company,
|
company: me.frm.doc.company,
|
||||||
show_cancelled_entries: me.frm.doc.docstatus === 2,
|
show_cancelled_entries: me.frm.doc.docstatus === 2,
|
||||||
ignore_prepared_report: true
|
ignore_prepared_report: true,
|
||||||
};
|
};
|
||||||
frappe.set_route("query-report", "Stock Ledger");
|
frappe.set_route("query-report", "Stock Ledger");
|
||||||
}, __("View"));
|
},
|
||||||
|
__("View")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
show_general_ledger() {
|
show_general_ledger() {
|
||||||
let me = this;
|
let me = this;
|
||||||
if (this.frm.doc.docstatus > 0) {
|
if (this.frm.doc.docstatus > 0) {
|
||||||
cur_frm.add_custom_button(__('Accounting Ledger'), function() {
|
cur_frm.add_custom_button(
|
||||||
|
__("Accounting Ledger"),
|
||||||
|
function () {
|
||||||
frappe.route_options = {
|
frappe.route_options = {
|
||||||
voucher_no: me.frm.doc.name,
|
voucher_no: me.frm.doc.name,
|
||||||
from_date: me.frm.doc.posting_date,
|
from_date: me.frm.doc.posting_date,
|
||||||
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
|
to_date: moment(me.frm.doc.modified).format("YYYY-MM-DD"),
|
||||||
company: me.frm.doc.company,
|
company: me.frm.doc.company,
|
||||||
categorize_by: "Categorize by Voucher (Consolidated)",
|
categorize_by: "Categorize by Voucher (Consolidated)",
|
||||||
show_cancelled_entries: me.frm.doc.docstatus === 2,
|
show_cancelled_entries: me.frm.doc.docstatus === 2,
|
||||||
ignore_prepared_report: true
|
ignore_prepared_report: true,
|
||||||
};
|
};
|
||||||
frappe.set_route("query-report", "General Ledger");
|
frappe.set_route("query-report", "General Ledger");
|
||||||
}, __("View"));
|
},
|
||||||
|
__("View")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
effective_item_rate = item.blanket_order_rate;
|
effective_item_rate = item.blanket_order_rate;
|
||||||
}
|
}
|
||||||
if (item.margin_type == "Percentage") {
|
if (item.margin_type == "Percentage") {
|
||||||
item.rate_with_margin = flt(effective_item_rate)
|
item.rate_with_margin =
|
||||||
+ flt(effective_item_rate) * ( flt(item.margin_rate_or_amount) / 100);
|
flt(effective_item_rate) + flt(effective_item_rate) * (flt(item.margin_rate_or_amount) / 100);
|
||||||
} else {
|
} else {
|
||||||
item.rate_with_margin = flt(effective_item_rate) + flt(item.margin_rate_or_amount);
|
item.rate_with_margin = flt(effective_item_rate) + flt(item.margin_rate_or_amount);
|
||||||
}
|
}
|
||||||
@@ -23,12 +23,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
item_rate = flt(item.rate_with_margin, precision("rate", item));
|
item_rate = flt(item.rate_with_margin, precision("rate", item));
|
||||||
|
|
||||||
if (item.discount_percentage && !item.discount_amount) {
|
if (item.discount_percentage && !item.discount_amount) {
|
||||||
item.discount_amount = flt(item.rate_with_margin) * flt(item.discount_percentage) / 100;
|
item.discount_amount = (flt(item.rate_with_margin) * flt(item.discount_percentage)) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.discount_amount > 0) {
|
if (item.discount_amount > 0) {
|
||||||
item_rate = flt((item.rate_with_margin) - (item.discount_amount), precision('rate', item));
|
item_rate = flt(item.rate_with_margin - item.discount_amount, precision("rate", item));
|
||||||
item.discount_percentage = 100 * flt(item.discount_amount) / flt(item.rate_with_margin);
|
item.discount_percentage = (100 * flt(item.discount_amount)) / flt(item.rate_with_margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.model.set_value(item.doctype, item.name, "rate", item_rate);
|
frappe.model.set_value(item.doctype, item.name, "rate", item_rate);
|
||||||
@@ -52,17 +52,17 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
// Advance calculation applicable to Sales/Purchase Invoice
|
// Advance calculation applicable to Sales/Purchase Invoice
|
||||||
if (
|
if (
|
||||||
["Sales Invoice", "POS Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype)
|
["Sales Invoice", "POS Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype) &&
|
||||||
&& this.frm.doc.docstatus < 2
|
this.frm.doc.docstatus < 2 &&
|
||||||
&& !this.frm.doc.is_return
|
!this.frm.doc.is_return
|
||||||
) {
|
) {
|
||||||
this.calculate_total_advance(update_paid_amount);
|
this.calculate_total_advance(update_paid_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)
|
["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype) &&
|
||||||
&& this.frm.doc.is_pos
|
this.frm.doc.is_pos &&
|
||||||
&& this.frm.doc.is_return
|
this.frm.doc.is_return
|
||||||
) {
|
) {
|
||||||
await this.set_total_amount_to_default_mop();
|
await this.set_total_amount_to_default_mop();
|
||||||
this.calculate_paid_amount();
|
this.calculate_paid_amount();
|
||||||
@@ -76,9 +76,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
// Update paid amount on return/debit note creation
|
// Update paid amount on return/debit note creation
|
||||||
if (
|
if (
|
||||||
this.frm.doc.doctype === "Purchase Invoice"
|
this.frm.doc.doctype === "Purchase Invoice" &&
|
||||||
&& this.frm.doc.is_return
|
this.frm.doc.is_return &&
|
||||||
&& (this.frm.doc.grand_total > this.frm.doc.paid_amount)
|
this.frm.doc.grand_total > this.frm.doc.paid_amount
|
||||||
) {
|
) {
|
||||||
this.frm.doc.paid_amount = flt(this.frm.doc.grand_total, precision("grand_total"));
|
this.frm.doc.paid_amount = flt(this.frm.doc.grand_total, precision("grand_total"));
|
||||||
}
|
}
|
||||||
@@ -109,9 +109,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate_conversion_rate() {
|
validate_conversion_rate() {
|
||||||
this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, (cur_frm) ? precision("conversion_rate") : 9);
|
this.frm.doc.conversion_rate = flt(
|
||||||
var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
|
this.frm.doc.conversion_rate,
|
||||||
this.frm.doc.name);
|
cur_frm ? precision("conversion_rate") : 9
|
||||||
|
);
|
||||||
|
var conversion_rate_label = frappe.meta.get_label(
|
||||||
|
this.frm.doc.doctype,
|
||||||
|
"conversion_rate",
|
||||||
|
this.frm.doc.name
|
||||||
|
);
|
||||||
var company_currency = this.get_company_currency();
|
var company_currency = this.get_company_currency();
|
||||||
|
|
||||||
if (!this.frm.doc.conversion_rate) {
|
if (!this.frm.doc.conversion_rate) {
|
||||||
@@ -119,7 +125,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
this.frm.set_value("conversion_rate", 1);
|
this.frm.set_value("conversion_rate", 1);
|
||||||
} else {
|
} else {
|
||||||
const subs = [conversion_rate_label, this.frm.doc.currency, company_currency];
|
const subs = [conversion_rate_label, this.frm.doc.currency, company_currency];
|
||||||
const err_message = __('{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}', subs);
|
const err_message = __(
|
||||||
|
"{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}",
|
||||||
|
subs
|
||||||
|
);
|
||||||
frappe.throw(err_message);
|
frappe.throw(err_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,12 +144,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
if (!(me.frm.doc.is_return || me.frm.doc.is_debit_note)) {
|
if (!(me.frm.doc.is_return || me.frm.doc.is_debit_note)) {
|
||||||
item.net_amount = item.amount = flt(item.rate * item.qty, precision("amount", item));
|
item.net_amount = item.amount = flt(item.rate * item.qty, precision("amount", item));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// allow for '0' qty on Credit/Debit notes
|
// allow for '0' qty on Credit/Debit notes
|
||||||
let qty = flt(item.qty);
|
let qty = flt(item.qty);
|
||||||
if (!qty) {
|
if (!qty) {
|
||||||
qty = (me.frm.doc.is_debit_note ? 1 : -1);
|
qty = me.frm.doc.is_debit_note ? 1 : -1;
|
||||||
if (me.frm.doc.doctype !== "Purchase Receipt" && me.frm.doc.is_return === 1) {
|
if (me.frm.doc.doctype !== "Purchase Receipt" && me.frm.doc.is_return === 1) {
|
||||||
// In case of Purchase Receipt, qty can be 0 if all items are rejected
|
// In case of Purchase Receipt, qty can be 0 if all items are rejected
|
||||||
qty = flt(item.qty);
|
qty = flt(item.qty);
|
||||||
@@ -153,7 +161,13 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
item.item_tax_amount = 0.0;
|
item.item_tax_amount = 0.0;
|
||||||
item.total_weight = flt(item.weight_per_unit * item.stock_qty);
|
item.total_weight = flt(item.weight_per_unit * item.stock_qty);
|
||||||
|
|
||||||
me.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
|
me.set_in_company_currency(item, [
|
||||||
|
"price_list_rate",
|
||||||
|
"rate",
|
||||||
|
"amount",
|
||||||
|
"net_rate",
|
||||||
|
"net_amount",
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +175,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
set_in_company_currency(doc, fields) {
|
set_in_company_currency(doc, fields) {
|
||||||
var me = this;
|
var me = this;
|
||||||
$.each(fields, function (i, f) {
|
$.each(fields, function (i, f) {
|
||||||
doc["base_"+f] = flt(flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate, precision("base_" + f, doc));
|
doc["base_" + f] = flt(
|
||||||
|
flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate,
|
||||||
|
precision("base_" + f, doc)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,16 +189,25 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (!tax.dont_recompute_tax) {
|
if (!tax.dont_recompute_tax) {
|
||||||
tax.item_wise_tax_detail = {};
|
tax.item_wise_tax_detail = {};
|
||||||
}
|
}
|
||||||
var tax_fields = ["total", "tax_amount_after_discount_amount",
|
var tax_fields = [
|
||||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
"total",
|
||||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"];
|
"tax_amount_after_discount_amount",
|
||||||
|
"tax_amount_for_current_item",
|
||||||
|
"grand_total_for_current_item",
|
||||||
|
"tax_fraction_for_current_item",
|
||||||
|
"grand_total_fraction_for_current_item",
|
||||||
|
];
|
||||||
|
|
||||||
if (cstr(tax.charge_type) != "Actual" &&
|
if (
|
||||||
!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total")) {
|
cstr(tax.charge_type) != "Actual" &&
|
||||||
|
!(me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
|
||||||
|
) {
|
||||||
tax_fields.push("tax_amount");
|
tax_fields.push("tax_amount");
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0; });
|
$.each(tax_fields, function (i, fieldname) {
|
||||||
|
tax[fieldname] = 0.0;
|
||||||
|
});
|
||||||
|
|
||||||
if (!this.discount_amount_applied) {
|
if (!this.discount_amount_applied) {
|
||||||
erpnext.accounts.taxes.validate_taxes_and_charges(tax.doctype, tax.name);
|
erpnext.accounts.taxes.validate_taxes_and_charges(tax.doctype, tax.name);
|
||||||
@@ -197,16 +223,16 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
if (me.frm.doc.company) {
|
if (me.frm.doc.company) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
"method": "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts",
|
method: "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts",
|
||||||
"args": {
|
args: {
|
||||||
"company": me.frm.doc.company,
|
company: me.frm.doc.company,
|
||||||
"account_list": frappe.flags.round_off_applicable_accounts
|
account_list: frappe.flags.round_off_applicable_accounts,
|
||||||
},
|
},
|
||||||
callback(r) {
|
callback(r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
frappe.flags.round_off_applicable_accounts.push(...r.message);
|
frappe.flags.round_off_applicable_accounts.push(...r.message);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +240,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
method: "erpnext.controllers.taxes_and_totals.get_rounding_tax_settings",
|
method: "erpnext.controllers.taxes_and_totals.get_rounding_tax_settings",
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
frappe.flags.round_off_settings = r.message;
|
frappe.flags.round_off_settings = r.message;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +274,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
total_inclusive_tax_amount_per_qty += inclusive_tax_amount_per_qty * flt(item.qty);
|
total_inclusive_tax_amount_per_qty += inclusive_tax_amount_per_qty * flt(item.qty);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!me.discount_amount_applied && item.qty && (total_inclusive_tax_amount_per_qty || cumulated_tax_fraction)) {
|
if (
|
||||||
|
!me.discount_amount_applied &&
|
||||||
|
item.qty &&
|
||||||
|
(total_inclusive_tax_amount_per_qty || cumulated_tax_fraction)
|
||||||
|
) {
|
||||||
var amount = flt(item.amount) - total_inclusive_tax_amount_per_qty;
|
var amount = flt(item.amount) - total_inclusive_tax_amount_per_qty;
|
||||||
item.net_amount = flt(amount / (1 + cumulated_tax_fraction), precision("net_amount", item));
|
item.net_amount = flt(amount / (1 + cumulated_tax_fraction), precision("net_amount", item));
|
||||||
item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0;
|
item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0;
|
||||||
@@ -268,14 +298,14 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
var tax_rate = this._get_tax_rate(tax, item_tax_map);
|
var tax_rate = this._get_tax_rate(tax, item_tax_map);
|
||||||
|
|
||||||
if (tax.charge_type == "On Net Total") {
|
if (tax.charge_type == "On Net Total") {
|
||||||
current_tax_fraction = (tax_rate / 100.0);
|
current_tax_fraction = tax_rate / 100.0;
|
||||||
|
|
||||||
} else if (tax.charge_type == "On Previous Row Amount") {
|
} else if (tax.charge_type == "On Previous Row Amount") {
|
||||||
current_tax_fraction = (tax_rate / 100.0) *
|
current_tax_fraction =
|
||||||
|
(tax_rate / 100.0) *
|
||||||
this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_fraction_for_current_item;
|
this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_fraction_for_current_item;
|
||||||
|
|
||||||
} else if (tax.charge_type == "On Previous Row Total") {
|
} else if (tax.charge_type == "On Previous Row Total") {
|
||||||
current_tax_fraction = (tax_rate / 100.0) *
|
current_tax_fraction =
|
||||||
|
(tax_rate / 100.0) *
|
||||||
this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
|
this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
|
||||||
} else if (tax.charge_type == "On Item Quantity") {
|
} else if (tax.charge_type == "On Item Quantity") {
|
||||||
inclusive_tax_amount_per_qty = flt(tax_rate);
|
inclusive_tax_amount_per_qty = flt(tax_rate);
|
||||||
@@ -290,13 +320,19 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_tax_rate(tax, item_tax_map) {
|
_get_tax_rate(tax, item_tax_map) {
|
||||||
return (Object.keys(item_tax_map).indexOf(tax.account_head) != -1) ?
|
return Object.keys(item_tax_map).indexOf(tax.account_head) != -1
|
||||||
flt(item_tax_map[tax.account_head], precision("rate", tax)) : tax.rate;
|
? flt(item_tax_map[tax.account_head], precision("rate", tax))
|
||||||
|
: tax.rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_net_total() {
|
calculate_net_total() {
|
||||||
var me = this;
|
var me = this;
|
||||||
this.frm.doc.total_qty = this.frm.doc.total = this.frm.doc.base_total = this.frm.doc.net_total = this.frm.doc.base_net_total = 0.0;
|
this.frm.doc.total_qty =
|
||||||
|
this.frm.doc.total =
|
||||||
|
this.frm.doc.base_total =
|
||||||
|
this.frm.doc.net_total =
|
||||||
|
this.frm.doc.base_net_total =
|
||||||
|
0.0;
|
||||||
|
|
||||||
$.each(this.frm._items || [], function (i, item) {
|
$.each(this.frm._items || [], function (i, item) {
|
||||||
me.frm.doc.total += item.amount;
|
me.frm.doc.total += item.amount;
|
||||||
@@ -325,12 +361,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
let me = this;
|
let me = this;
|
||||||
|
|
||||||
if (item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
if (item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
||||||
if (typeof (item_tax_map) == "string") {
|
if (typeof item_tax_map == "string") {
|
||||||
item_tax_map = JSON.parse(item_tax_map);
|
item_tax_map = JSON.parse(item_tax_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(item_tax_map, function (tax, rate) {
|
$.each(item_tax_map, function (tax, rate) {
|
||||||
let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax);
|
let found = (me.frm.doc.taxes || []).find((d) => d.account_head === tax);
|
||||||
if (!found) {
|
if (!found) {
|
||||||
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
||||||
child.charge_type = "On Net Total";
|
child.charge_type = "On Net Total";
|
||||||
@@ -374,8 +410,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// accumulate tax amount into tax.tax_amount
|
// accumulate tax amount into tax.tax_amount
|
||||||
if (tax.charge_type != "Actual" &&
|
if (
|
||||||
!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total")) {
|
tax.charge_type != "Actual" &&
|
||||||
|
!(me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
|
||||||
|
) {
|
||||||
tax.tax_amount += current_tax_amount;
|
tax.tax_amount += current_tax_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,9 +428,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (tax.category) {
|
if (tax.category) {
|
||||||
// if just for valuation, do not add the tax amount in total
|
// if just for valuation, do not add the tax amount in total
|
||||||
// hence, setting it as 0 for further steps
|
// hence, setting it as 0 for further steps
|
||||||
current_tax_amount = (tax.category == "Valuation") ? 0.0 : current_tax_amount;
|
current_tax_amount = tax.category == "Valuation" ? 0.0 : current_tax_amount;
|
||||||
|
|
||||||
current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
|
current_tax_amount *= tax.add_deduct_tax == "Deduct" ? -1.0 : 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: grand_total_for_current_item contains the contribution of
|
// note: grand_total_for_current_item contains the contribution of
|
||||||
@@ -400,19 +438,26 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
|
tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
|
||||||
} else {
|
} else {
|
||||||
tax.grand_total_for_current_item =
|
tax.grand_total_for_current_item = flt(
|
||||||
flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount);
|
me.frm.doc["taxes"][i - 1].grand_total_for_current_item + current_tax_amount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const discount_amount_applied = this.discount_amount_applied;
|
const discount_amount_applied = this.discount_amount_applied;
|
||||||
if (doc.apply_discount_on === "Grand Total" && (discount_amount_applied || doc.discount_amount || doc.additional_discount_percentage)) {
|
if (
|
||||||
|
doc.apply_discount_on === "Grand Total" &&
|
||||||
|
(discount_amount_applied || doc.discount_amount || doc.additional_discount_percentage)
|
||||||
|
) {
|
||||||
const tax_amount_precision = precision("tax_amount", doc.taxes[0]);
|
const tax_amount_precision = precision("tax_amount", doc.taxes[0]);
|
||||||
|
|
||||||
for (const [i, tax] of doc.taxes.entries()) {
|
for (const [i, tax] of doc.taxes.entries()) {
|
||||||
if (discount_amount_applied)
|
if (discount_amount_applied)
|
||||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, tax_amount_precision);
|
tax.tax_amount_after_discount_amount = flt(
|
||||||
|
tax.tax_amount_after_discount_amount,
|
||||||
|
tax_amount_precision
|
||||||
|
);
|
||||||
|
|
||||||
this.set_cumulative_total(i, tax);
|
this.set_cumulative_total(i, tax);
|
||||||
}
|
}
|
||||||
@@ -421,14 +466,17 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
this.grand_total_for_distributing_discount = doc.taxes[doc.taxes.length - 1].total;
|
this.grand_total_for_distributing_discount = doc.taxes[doc.taxes.length - 1].total;
|
||||||
} else {
|
} else {
|
||||||
this.grand_total_diff = flt(
|
this.grand_total_diff = flt(
|
||||||
this.grand_total_for_distributing_discount - doc.discount_amount - doc.taxes[doc.taxes.length - 1].total, precision("grand_total"));
|
this.grand_total_for_distributing_discount -
|
||||||
|
doc.discount_amount -
|
||||||
|
doc.taxes[doc.taxes.length - 1].total,
|
||||||
|
precision("grand_total")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [i, tax] of doc.taxes.entries()) {
|
for (const [i, tax] of doc.taxes.entries()) {
|
||||||
me.round_off_totals(tax);
|
me.round_off_totals(tax);
|
||||||
me.set_in_company_currency(tax,
|
me.set_in_company_currency(tax, ["tax_amount", "tax_amount_after_discount_amount"]);
|
||||||
["tax_amount", "tax_amount_after_discount_amount"]);
|
|
||||||
|
|
||||||
me.round_off_base_values(tax);
|
me.round_off_base_values(tax);
|
||||||
|
|
||||||
@@ -441,11 +489,13 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
set_cumulative_total(row_idx, tax) {
|
set_cumulative_total(row_idx, tax) {
|
||||||
var tax_amount = tax.tax_amount_after_discount_amount;
|
var tax_amount = tax.tax_amount_after_discount_amount;
|
||||||
if (tax.category == 'Valuation') {
|
if (tax.category == "Valuation") {
|
||||||
tax_amount = 0;
|
tax_amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tax.add_deduct_tax == "Deduct") { tax_amount = -1*tax_amount; }
|
if (tax.add_deduct_tax == "Deduct") {
|
||||||
|
tax_amount = -1 * tax_amount;
|
||||||
|
}
|
||||||
|
|
||||||
if (row_idx == 0) {
|
if (row_idx == 0) {
|
||||||
tax.total = flt(this.frm.doc.net_total + tax_amount, precision("total", tax));
|
tax.total = flt(this.frm.doc.net_total + tax_amount, precision("total", tax));
|
||||||
@@ -467,32 +517,35 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (["On Previous Row Amount", "On Previous Row Total"].includes(tax.charge_type)) {
|
if (["On Previous Row Amount", "On Previous Row Total"].includes(tax.charge_type)) {
|
||||||
if (tax.idx === 1) {
|
if (tax.idx === 1) {
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
|
__(
|
||||||
|
"Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!tax.row_id) {
|
if (!tax.row_id) {
|
||||||
tax.row_id = tax.idx - 1;
|
tax.row_id = tax.idx - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tax.charge_type == "Actual") {
|
if (tax.charge_type == "Actual") {
|
||||||
current_net_amount = item.net_amount
|
current_net_amount = item.net_amount;
|
||||||
// distribute the tax amount proportionally to each item row
|
// distribute the tax amount proportionally to each item row
|
||||||
var actual = flt(tax.tax_amount, precision("tax_amount", tax));
|
var actual = flt(tax.tax_amount, precision("tax_amount", tax));
|
||||||
current_tax_amount = this.frm.doc.net_total ?
|
current_tax_amount = this.frm.doc.net_total
|
||||||
((item.net_amount / this.frm.doc.net_total) * actual) : 0.0;
|
? (item.net_amount / this.frm.doc.net_total) * actual
|
||||||
|
: 0.0;
|
||||||
} else if (tax.charge_type == "On Net Total") {
|
} else if (tax.charge_type == "On Net Total") {
|
||||||
if (tax.account_head in item_tax_map) {
|
if (tax.account_head in item_tax_map) {
|
||||||
current_net_amount = item.net_amount
|
current_net_amount = item.net_amount;
|
||||||
};
|
}
|
||||||
current_tax_amount = (tax_rate / 100.0) * item.net_amount;
|
current_tax_amount = (tax_rate / 100.0) * item.net_amount;
|
||||||
} else if (tax.charge_type == "On Previous Row Amount") {
|
} else if (tax.charge_type == "On Previous Row Amount") {
|
||||||
current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item
|
current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item;
|
||||||
current_tax_amount = (tax_rate / 100.0) *
|
current_tax_amount =
|
||||||
this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item;
|
(tax_rate / 100.0) * this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item;
|
||||||
} else if (tax.charge_type == "On Previous Row Total") {
|
} else if (tax.charge_type == "On Previous Row Total") {
|
||||||
current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item
|
current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
|
||||||
current_tax_amount = (tax_rate / 100.0) *
|
current_tax_amount =
|
||||||
this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
|
(tax_rate / 100.0) * this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
|
||||||
} else if (tax.charge_type == "On Item Quantity") {
|
} else if (tax.charge_type == "On Item Quantity") {
|
||||||
// don't sum current net amount due to the field being a currency field
|
// don't sum current net amount due to the field being a currency field
|
||||||
current_tax_amount = tax_rate * item.qty;
|
current_tax_amount = tax_rate * item.qty;
|
||||||
@@ -510,7 +563,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
let tax_detail = tax.item_wise_tax_detail;
|
let tax_detail = tax.item_wise_tax_detail;
|
||||||
let key = item.item_code || item.item_name;
|
let key = item.item_code || item.item_name;
|
||||||
|
|
||||||
if(typeof (tax_detail) == "string") {
|
if (typeof tax_detail == "string") {
|
||||||
tax.item_wise_tax_detail = JSON.parse(tax.item_wise_tax_detail);
|
tax.item_wise_tax_detail = JSON.parse(tax.item_wise_tax_detail);
|
||||||
tax_detail = tax.item_wise_tax_detail;
|
tax_detail = tax.item_wise_tax_detail;
|
||||||
}
|
}
|
||||||
@@ -543,7 +596,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
||||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
|
tax.tax_amount_after_discount_amount = flt(
|
||||||
|
tax.tax_amount_after_discount_amount,
|
||||||
|
precision("tax_amount", tax)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
round_off_base_values(tax) {
|
round_off_base_values(tax) {
|
||||||
@@ -558,7 +614,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
*/
|
*/
|
||||||
manipulate_grand_total_for_inclusive_tax() {
|
manipulate_grand_total_for_inclusive_tax() {
|
||||||
// for backward compatablility - if in case used by an external application
|
// for backward compatablility - if in case used by an external application
|
||||||
this.adjust_grand_total_for_inclusive_tax()
|
this.adjust_grand_total_for_inclusive_tax();
|
||||||
}
|
}
|
||||||
|
|
||||||
adjust_grand_total_for_inclusive_tax() {
|
adjust_grand_total_for_inclusive_tax() {
|
||||||
@@ -572,17 +628,20 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
});
|
});
|
||||||
if (any_inclusive_tax) {
|
if (any_inclusive_tax) {
|
||||||
var last_tax = me.frm.doc["taxes"].slice(-1)[0];
|
var last_tax = me.frm.doc["taxes"].slice(-1)[0];
|
||||||
var non_inclusive_tax_amount = frappe.utils.sum($.map(this.frm.doc.taxes || [],
|
var non_inclusive_tax_amount = frappe.utils.sum(
|
||||||
function(d) {
|
$.map(this.frm.doc.taxes || [], function (d) {
|
||||||
if (!d.included_in_print_rate) {
|
if (!d.included_in_print_rate) {
|
||||||
let tax_amount = d.category === "Valuation" ? 0 : d.tax_amount_after_discount_amount;
|
let tax_amount =
|
||||||
|
d.category === "Valuation" ? 0 : d.tax_amount_after_discount_amount;
|
||||||
if (d.add_deduct_tax === "Deduct") tax_amount *= -1;
|
if (d.add_deduct_tax === "Deduct") tax_amount *= -1;
|
||||||
return tax_amount;
|
return tax_amount;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
));
|
);
|
||||||
var diff = me.frm.doc.total + non_inclusive_tax_amount
|
var diff =
|
||||||
- flt(last_tax.total, precision("grand_total"));
|
me.frm.doc.total +
|
||||||
|
non_inclusive_tax_amount -
|
||||||
|
flt(last_tax.total, precision("grand_total"));
|
||||||
|
|
||||||
if (me.discount_amount_applied && me.frm.doc.discount_amount) {
|
if (me.discount_amount_applied && me.frm.doc.discount_amount) {
|
||||||
diff -= flt(me.frm.doc.discount_amount);
|
diff -= flt(me.frm.doc.discount_amount);
|
||||||
@@ -590,7 +649,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
diff = flt(diff, precision("rounding_adjustment"));
|
diff = flt(diff, precision("rounding_adjustment"));
|
||||||
|
|
||||||
if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) {
|
if (diff && Math.abs(diff) <= 5.0 / Math.pow(10, precision("tax_amount", last_tax))) {
|
||||||
me.grand_total_diff = diff;
|
me.grand_total_diff = diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -603,13 +662,18 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
const tax_count = this.frm.doc.taxes?.length;
|
const tax_count = this.frm.doc.taxes?.length;
|
||||||
const grand_total_diff = this.grand_total_diff || 0;
|
const grand_total_diff = this.grand_total_diff || 0;
|
||||||
|
|
||||||
this.frm.doc.grand_total = flt(tax_count
|
this.frm.doc.grand_total = flt(
|
||||||
? this.frm.doc["taxes"][tax_count - 1].total + grand_total_diff
|
tax_count ? this.frm.doc["taxes"][tax_count - 1].total + grand_total_diff : this.frm.doc.net_total
|
||||||
: this.frm.doc.net_total);
|
);
|
||||||
|
|
||||||
if(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) {
|
if (
|
||||||
this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ?
|
["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"].includes(
|
||||||
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total;
|
this.frm.doc.doctype
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
this.frm.doc.base_grand_total = this.frm.doc.total_taxes_and_charges
|
||||||
|
? flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate)
|
||||||
|
: this.frm.doc.base_net_total;
|
||||||
} else {
|
} else {
|
||||||
// other charges added/deducted
|
// other charges added/deducted
|
||||||
this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0;
|
this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0;
|
||||||
@@ -619,24 +683,35 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
if (tax.add_deduct_tax == "Add") {
|
if (tax.add_deduct_tax == "Add") {
|
||||||
me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount_after_discount_amount);
|
me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount_after_discount_amount);
|
||||||
} else {
|
} else {
|
||||||
me.frm.doc.taxes_and_charges_deducted += flt(tax.tax_amount_after_discount_amount);
|
me.frm.doc.taxes_and_charges_deducted += flt(
|
||||||
|
tax.tax_amount_after_discount_amount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frappe.model.round_floats_in(this.frm.doc,
|
frappe.model.round_floats_in(this.frm.doc, [
|
||||||
["taxes_and_charges_added", "taxes_and_charges_deducted"]);
|
"taxes_and_charges_added",
|
||||||
|
"taxes_and_charges_deducted",
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.doc.base_grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
|
this.frm.doc.base_grand_total = flt(
|
||||||
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total);
|
this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted
|
||||||
|
? flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate)
|
||||||
|
: this.frm.doc.base_net_total
|
||||||
|
);
|
||||||
|
|
||||||
this.set_in_company_currency(this.frm.doc,
|
this.set_in_company_currency(this.frm.doc, [
|
||||||
["taxes_and_charges_added", "taxes_and_charges_deducted"]);
|
"taxes_and_charges_added",
|
||||||
|
"taxes_and_charges_deducted",
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total
|
this.frm.doc.total_taxes_and_charges = flt(
|
||||||
- grand_total_diff, precision("total_taxes_and_charges"));
|
this.frm.doc.grand_total - this.frm.doc.net_total - grand_total_diff,
|
||||||
|
precision("total_taxes_and_charges")
|
||||||
|
);
|
||||||
|
|
||||||
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
|
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
|
||||||
|
|
||||||
@@ -663,10 +738,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
|
if (frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
|
||||||
this.frm.doc.rounded_total = round_based_on_smallest_currency_fraction(this.frm.doc.grand_total,
|
this.frm.doc.rounded_total = round_based_on_smallest_currency_fraction(
|
||||||
this.frm.doc.currency, precision("rounded_total"));
|
this.frm.doc.grand_total,
|
||||||
this.frm.doc.rounding_adjustment = flt(this.frm.doc.rounded_total - this.frm.doc.grand_total,
|
this.frm.doc.currency,
|
||||||
precision("rounding_adjustment"));
|
precision("rounded_total")
|
||||||
|
);
|
||||||
|
this.frm.doc.rounding_adjustment = flt(
|
||||||
|
this.frm.doc.rounded_total - this.frm.doc.grand_total,
|
||||||
|
precision("rounding_adjustment")
|
||||||
|
);
|
||||||
|
|
||||||
this.set_in_company_currency(this.frm.doc, ["rounding_adjustment", "rounded_total"]);
|
this.set_in_company_currency(this.frm.doc, ["rounding_adjustment", "rounded_total"]);
|
||||||
}
|
}
|
||||||
@@ -685,10 +765,20 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
|
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
|
||||||
var temporary_fields = ["tax_amount_for_current_item", "grand_total_for_current_item",
|
var temporary_fields = [
|
||||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"];
|
"tax_amount_for_current_item",
|
||||||
|
"grand_total_for_current_item",
|
||||||
|
"tax_fraction_for_current_item",
|
||||||
|
"grand_total_fraction_for_current_item",
|
||||||
|
];
|
||||||
|
|
||||||
if(!frappe.meta.get_docfield(this.frm.doc["taxes"][0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
|
if (
|
||||||
|
!frappe.meta.get_docfield(
|
||||||
|
this.frm.doc["taxes"][0].doctype,
|
||||||
|
"tax_amount_after_discount_amount",
|
||||||
|
this.frm.doctype
|
||||||
|
)
|
||||||
|
) {
|
||||||
temporary_fields.push("tax_amount_after_discount_amount");
|
temporary_fields.push("tax_amount_after_discount_amount");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,8 +796,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
set_discount_amount() {
|
set_discount_amount() {
|
||||||
if (this.frm.doc.additional_discount_percentage) {
|
if (this.frm.doc.additional_discount_percentage) {
|
||||||
this.frm.doc.discount_amount = flt(flt(this.frm.doc[frappe.scrub(this.frm.doc.apply_discount_on)])
|
this.frm.doc.discount_amount = flt(
|
||||||
* this.frm.doc.additional_discount_percentage / 100, precision("discount_amount"));
|
(flt(this.frm.doc[frappe.scrub(this.frm.doc.apply_discount_on)]) *
|
||||||
|
this.frm.doc.additional_discount_percentage) /
|
||||||
|
100,
|
||||||
|
precision("discount_amount")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,13 +811,17 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
this.frm.doc.base_discount_amount = 0.0;
|
this.frm.doc.base_discount_amount = 0.0;
|
||||||
|
|
||||||
if (this.frm.doc.discount_amount) {
|
if (this.frm.doc.discount_amount) {
|
||||||
if(!this.frm.doc.apply_discount_on)
|
if (!this.frm.doc.apply_discount_on) frappe.throw(__("Please select Apply Discount On"));
|
||||||
frappe.throw(__("Please select Apply Discount On"));
|
|
||||||
|
|
||||||
this.frm.doc.base_discount_amount = flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate,
|
this.frm.doc.base_discount_amount = flt(
|
||||||
precision("base_discount_amount"));
|
this.frm.doc.discount_amount * this.frm.doc.conversion_rate,
|
||||||
|
precision("base_discount_amount")
|
||||||
|
);
|
||||||
|
|
||||||
if (this.frm.doc.apply_discount_on == "Grand Total" && this.frm.doc.is_cash_or_non_trade_discount) {
|
if (
|
||||||
|
this.frm.doc.apply_discount_on == "Grand Total" &&
|
||||||
|
this.frm.doc.is_cash_or_non_trade_discount
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,10 +832,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
// calculate item amount after Discount Amount
|
// calculate item amount after Discount Amount
|
||||||
if (total_for_discount_amount) {
|
if (total_for_discount_amount) {
|
||||||
$.each(this.frm._items || [], function (i, item) {
|
$.each(this.frm._items || [], function (i, item) {
|
||||||
distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
|
distributed_amount =
|
||||||
|
(flt(me.frm.doc.discount_amount) * item.net_amount) / total_for_discount_amount;
|
||||||
|
|
||||||
const adjusted_net_amount = item.net_amount - distributed_amount;
|
const adjusted_net_amount = item.net_amount - distributed_amount;
|
||||||
expected_net_total += adjusted_net_amount
|
expected_net_total += adjusted_net_amount;
|
||||||
item.net_amount = flt(adjusted_net_amount, precision("net_amount", item));
|
item.net_amount = flt(adjusted_net_amount, precision("net_amount", item));
|
||||||
net_total += item.net_amount;
|
net_total += item.net_amount;
|
||||||
|
|
||||||
@@ -745,10 +844,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
// assignment to rounding_difference is intentional
|
// assignment to rounding_difference is intentional
|
||||||
const rounding_difference = flt(expected_net_total - net_total, precision("net_total"));
|
const rounding_difference = flt(expected_net_total - net_total, precision("net_total"));
|
||||||
if (rounding_difference) {
|
if (rounding_difference) {
|
||||||
item.net_amount = flt(item.net_amount + rounding_difference, precision("net_amount", item));
|
item.net_amount = flt(
|
||||||
|
item.net_amount + rounding_difference,
|
||||||
|
precision("net_amount", item)
|
||||||
|
);
|
||||||
net_total += rounding_difference;
|
net_total += rounding_difference;
|
||||||
}
|
}
|
||||||
item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0;
|
item.net_rate = item.qty
|
||||||
|
? flt(item.net_amount / item.qty, precision("net_rate", item))
|
||||||
|
: 0;
|
||||||
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -761,8 +865,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
get_total_for_discount_amount() {
|
get_total_for_discount_amount() {
|
||||||
const doc = this.frm.doc;
|
const doc = this.frm.doc;
|
||||||
|
|
||||||
if (doc.apply_discount_on == "Net Total" || !doc.taxes?.length)
|
if (doc.apply_discount_on == "Net Total" || !doc.taxes?.length) return doc.net_total;
|
||||||
return doc.net_total;
|
|
||||||
|
|
||||||
let total_actual_tax = 0.0;
|
let total_actual_tax = 0.0;
|
||||||
let actual_taxes_dict = {};
|
let actual_taxes_dict = {};
|
||||||
@@ -773,11 +876,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
actual_taxes_dict[tax.idx] = {
|
actual_taxes_dict[tax.idx] = {
|
||||||
tax_amount: tax_amount,
|
tax_amount: tax_amount,
|
||||||
cumulative_total: total_actual_tax
|
cumulative_total: total_actual_tax,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.taxes.forEach(tax => {
|
doc.taxes.forEach((tax) => {
|
||||||
if (["Actual", "On Item Quantity"].includes(tax.charge_type)) {
|
if (["Actual", "On Item Quantity"].includes(tax.charge_type)) {
|
||||||
update_actual_taxes_dict(tax, tax.tax_amount);
|
update_actual_taxes_dict(tax, tax.tax_amount);
|
||||||
return;
|
return;
|
||||||
@@ -788,17 +891,22 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
// if charge type is 'On Previous Row Amount', calculate tax on previous row amount
|
// if charge type is 'On Previous Row Amount', calculate tax on previous row amount
|
||||||
// else (On Previous Row Total) calculate tax on cumulative total
|
// else (On Previous Row Total) calculate tax on cumulative total
|
||||||
const base_tax_amount = tax.charge_type == "On Previous Row Amount" ? base_row["tax_amount"]: base_row["cumulative_total"];
|
const base_tax_amount =
|
||||||
update_actual_taxes_dict(tax, base_tax_amount * tax.rate / 100);
|
tax.charge_type == "On Previous Row Amount"
|
||||||
|
? base_row["tax_amount"]
|
||||||
|
: base_row["cumulative_total"];
|
||||||
|
update_actual_taxes_dict(tax, (base_tax_amount * tax.rate) / 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (this.grand_total_for_distributing_discount || doc.grand_total) - total_actual_tax;
|
return (this.grand_total_for_distributing_discount || doc.grand_total) - total_actual_tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_total_advance(update_paid_amount) {
|
calculate_total_advance(update_paid_amount) {
|
||||||
var total_allocated_amount = frappe.utils.sum($.map(this.frm.doc["advances"] || [], function(adv) {
|
var total_allocated_amount = frappe.utils.sum(
|
||||||
|
$.map(this.frm.doc["advances"] || [], function (adv) {
|
||||||
return flt(adv.allocated_amount, precision("allocated_amount", adv));
|
return flt(adv.allocated_amount, precision("allocated_amount", adv));
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
|
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
|
||||||
|
|
||||||
if (this.frm.doc.write_off_outstanding_amount_automatically) {
|
if (this.frm.doc.write_off_outstanding_amount_automatically) {
|
||||||
@@ -810,7 +918,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is_internal_invoice() {
|
is_internal_invoice() {
|
||||||
if (['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
|
if (["Sales Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype)) {
|
||||||
if (this.frm.doc.company === this.frm.doc.represents_company) {
|
if (this.frm.doc.company === this.frm.doc.represents_company) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -826,7 +934,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
this.calculate_paid_amount();
|
this.calculate_paid_amount();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.frm.doc.is_return || (this.frm.doc.docstatus > 0) || this.is_internal_invoice()) return;
|
if (this.frm.doc.is_return || this.frm.doc.docstatus > 0 || this.is_internal_invoice()) return;
|
||||||
|
|
||||||
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]);
|
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]);
|
||||||
|
|
||||||
@@ -835,12 +943,15 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
|
let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
|
||||||
|
|
||||||
if (this.frm.doc.party_account_currency == this.frm.doc.currency) {
|
if (this.frm.doc.party_account_currency == this.frm.doc.currency) {
|
||||||
var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance
|
var total_amount_to_pay = flt(
|
||||||
- this.frm.doc.write_off_amount), precision("grand_total"));
|
grand_total - this.frm.doc.total_advance - this.frm.doc.write_off_amount,
|
||||||
|
precision("grand_total")
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
var total_amount_to_pay = flt(
|
var total_amount_to_pay = flt(
|
||||||
(flt(base_grand_total, precision("base_grand_total"))
|
flt(base_grand_total, precision("base_grand_total")) -
|
||||||
- this.frm.doc.total_advance - this.frm.doc.base_write_off_amount),
|
this.frm.doc.total_advance -
|
||||||
|
this.frm.doc.base_write_off_amount,
|
||||||
precision("base_grand_total")
|
precision("base_grand_total")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -854,18 +965,28 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) {
|
if (["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) {
|
||||||
let total_amount_for_payment = (this.frm.doc.redeem_loyalty_points && this.frm.doc.loyalty_amount)
|
let total_amount_for_payment =
|
||||||
? flt(total_amount_to_pay - this.frm.doc.loyalty_amount, precision("base_grand_total"))
|
this.frm.doc.redeem_loyalty_points && this.frm.doc.loyalty_amount
|
||||||
|
? flt(
|
||||||
|
total_amount_to_pay - this.frm.doc.loyalty_amount,
|
||||||
|
precision("base_grand_total")
|
||||||
|
)
|
||||||
: total_amount_to_pay;
|
: total_amount_to_pay;
|
||||||
this.set_default_payment(total_amount_for_payment, update_paid_amount);
|
this.set_default_payment(total_amount_for_payment, update_paid_amount);
|
||||||
this.calculate_paid_amount();
|
this.calculate_paid_amount();
|
||||||
}
|
}
|
||||||
this.calculate_change_amount();
|
this.calculate_change_amount();
|
||||||
|
|
||||||
var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ?
|
var paid_amount =
|
||||||
this.frm.doc.paid_amount : this.frm.doc.base_paid_amount;
|
this.frm.doc.party_account_currency == this.frm.doc.currency
|
||||||
this.frm.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) +
|
? this.frm.doc.paid_amount
|
||||||
flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate), precision("outstanding_amount"));
|
: this.frm.doc.base_paid_amount;
|
||||||
|
this.frm.doc.outstanding_amount = flt(
|
||||||
|
total_amount_to_pay -
|
||||||
|
flt(paid_amount) +
|
||||||
|
flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate),
|
||||||
|
precision("outstanding_amount")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -880,13 +1001,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var total_amount_to_pay = flt(
|
var total_amount_to_pay = flt(
|
||||||
(
|
flt(base_grand_total, precision("base_grand_total")) -
|
||||||
flt(
|
this.frm.doc.total_advance -
|
||||||
base_grand_total,
|
this.frm.doc.base_write_off_amount,
|
||||||
precision("base_grand_total")
|
|
||||||
)
|
|
||||||
- this.frm.doc.total_advance - this.frm.doc.base_write_off_amount
|
|
||||||
),
|
|
||||||
precision("base_grand_total")
|
precision("base_grand_total")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -898,8 +1015,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let payment_amount = 0;
|
let payment_amount = 0;
|
||||||
this.frm.doc.payments.forEach(payment => {
|
this.frm.doc.payments.forEach((payment) => {
|
||||||
payment_amount += payment.amount
|
payment_amount += payment.amount;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (payment_amount == total_amount_to_pay) {
|
if (payment_amount == total_amount_to_pay) {
|
||||||
@@ -913,14 +1030,14 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
|
|
||||||
if (this.frm.doc.return_against) {
|
if (this.frm.doc.return_against) {
|
||||||
let { message: return_against_mop } = await frappe.call({
|
let { message: return_against_mop } = await frappe.call({
|
||||||
method: 'erpnext.controllers.sales_and_purchase_return.get_payment_data',
|
method: "erpnext.controllers.sales_and_purchase_return.get_payment_data",
|
||||||
args: {
|
args: {
|
||||||
invoice: this.frm.doc.return_against
|
invoice: this.frm.doc.return_against,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (return_against_mop.length === 1) {
|
if (return_against_mop.length === 1) {
|
||||||
this.frm.doc.payments.forEach(payment => {
|
this.frm.doc.payments.forEach((payment) => {
|
||||||
if (payment.mode_of_payment == return_against_mop[0].mode_of_payment) {
|
if (payment.mode_of_payment == return_against_mop[0].mode_of_payment) {
|
||||||
payment.amount = total_amount_to_pay;
|
payment.amount = total_amount_to_pay;
|
||||||
} else {
|
} else {
|
||||||
@@ -932,11 +1049,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.doc.payments.find(payment => {
|
this.frm.doc.payments.find((payment) => {
|
||||||
if (payment.default) {
|
if (payment.default) {
|
||||||
payment.amount = total_amount_to_pay;
|
payment.amount = total_amount_to_pay;
|
||||||
} else {
|
} else {
|
||||||
payment.amount = 0
|
payment.amount = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -948,11 +1065,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
var payment_status = true;
|
var payment_status = true;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.frm.doc.is_pos
|
this.frm.doc.is_pos &&
|
||||||
&& cint(this.frm.set_default_payment)
|
cint(this.frm.set_default_payment) &&
|
||||||
&& (update_paid_amount===undefined || update_paid_amount)
|
(update_paid_amount === undefined || update_paid_amount)
|
||||||
) {
|
) {
|
||||||
$.each(this.frm.doc['payments'] || [], function(index, data) {
|
$.each(this.frm.doc["payments"] || [], function (index, data) {
|
||||||
if (data.default && payment_status && total_amount_to_pay > 0) {
|
if (data.default && payment_status && total_amount_to_pay > 0) {
|
||||||
let base_amount, amount;
|
let base_amount, amount;
|
||||||
|
|
||||||
@@ -960,17 +1077,22 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
// if customer/supplier currency is same as company currency
|
// if customer/supplier currency is same as company currency
|
||||||
// total_amount_to_pay is already in customer/supplier currency
|
// total_amount_to_pay is already in customer/supplier currency
|
||||||
// so base_amount has to be calculated using total_amount_to_pay
|
// so base_amount has to be calculated using total_amount_to_pay
|
||||||
base_amount = flt(total_amount_to_pay * me.frm.doc.conversion_rate, precision("base_amount", data));
|
base_amount = flt(
|
||||||
|
total_amount_to_pay * me.frm.doc.conversion_rate,
|
||||||
|
precision("base_amount", data)
|
||||||
|
);
|
||||||
amount = flt(total_amount_to_pay, precision("amount", data));
|
amount = flt(total_amount_to_pay, precision("amount", data));
|
||||||
} else {
|
} else {
|
||||||
base_amount = flt(total_amount_to_pay, precision("base_amount", data));
|
base_amount = flt(total_amount_to_pay, precision("base_amount", data));
|
||||||
amount = flt(total_amount_to_pay / me.frm.doc.conversion_rate, precision("amount", data));
|
amount = flt(
|
||||||
|
total_amount_to_pay / me.frm.doc.conversion_rate,
|
||||||
|
precision("amount", data)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.model.set_value(data.doctype, data.name, "base_amount", base_amount);
|
frappe.model.set_value(data.doctype, data.name, "base_amount", base_amount);
|
||||||
frappe.model.set_value(data.doctype, data.name, "amount", amount);
|
frappe.model.set_value(data.doctype, data.name, "amount", amount);
|
||||||
payment_status = false;
|
payment_status = false;
|
||||||
|
|
||||||
} else if (me.frm.doc.paid_amount) {
|
} else if (me.frm.doc.paid_amount) {
|
||||||
frappe.model.set_value(data.doctype, data.name, "amount", 0.0);
|
frappe.model.set_value(data.doctype, data.name, "amount", 0.0);
|
||||||
}
|
}
|
||||||
@@ -983,8 +1105,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
var paid_amount = 0.0;
|
var paid_amount = 0.0;
|
||||||
var base_paid_amount = 0.0;
|
var base_paid_amount = 0.0;
|
||||||
if (this.frm.doc.is_pos) {
|
if (this.frm.doc.is_pos) {
|
||||||
$.each(this.frm.doc['payments'] || [], function(index, data){
|
$.each(this.frm.doc["payments"] || [], function (index, data) {
|
||||||
data.base_amount = flt(data.amount * me.frm.doc.conversion_rate, precision("base_amount", data));
|
data.base_amount = flt(
|
||||||
|
data.amount * me.frm.doc.conversion_rate,
|
||||||
|
precision("base_amount", data)
|
||||||
|
);
|
||||||
paid_amount += data.amount;
|
paid_amount += data.amount;
|
||||||
base_paid_amount += data.base_amount;
|
base_paid_amount += data.base_amount;
|
||||||
});
|
});
|
||||||
@@ -993,45 +1118,60 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
}
|
}
|
||||||
if (this.frm.doc.redeem_loyalty_points && this.frm.doc.loyalty_amount) {
|
if (this.frm.doc.redeem_loyalty_points && this.frm.doc.loyalty_amount) {
|
||||||
base_paid_amount += this.frm.doc.loyalty_amount;
|
base_paid_amount += this.frm.doc.loyalty_amount;
|
||||||
paid_amount += flt(this.frm.doc.loyalty_amount / me.frm.doc.conversion_rate, precision("paid_amount"));
|
paid_amount += flt(
|
||||||
|
this.frm.doc.loyalty_amount / me.frm.doc.conversion_rate,
|
||||||
|
precision("paid_amount")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.set_value('paid_amount', flt(paid_amount, precision("paid_amount")));
|
this.frm.set_value("paid_amount", flt(paid_amount, precision("paid_amount")));
|
||||||
this.frm.set_value('base_paid_amount', flt(base_paid_amount, precision("base_paid_amount")));
|
this.frm.set_value("base_paid_amount", flt(base_paid_amount, precision("base_paid_amount")));
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_change_amount() {
|
calculate_change_amount() {
|
||||||
this.frm.doc.change_amount = 0.0;
|
this.frm.doc.change_amount = 0.0;
|
||||||
this.frm.doc.base_change_amount = 0.0;
|
this.frm.doc.base_change_amount = 0.0;
|
||||||
if(["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)
|
if (
|
||||||
&& this.frm.doc.paid_amount > this.frm.doc.grand_total && !this.frm.doc.is_return) {
|
["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype) &&
|
||||||
|
this.frm.doc.paid_amount > this.frm.doc.grand_total &&
|
||||||
var payment_types = $.map(this.frm.doc.payments, function(d) { return d.type; });
|
!this.frm.doc.is_return
|
||||||
if (in_list(payment_types, 'Cash')) {
|
) {
|
||||||
|
var payment_types = $.map(this.frm.doc.payments, function (d) {
|
||||||
|
return d.type;
|
||||||
|
});
|
||||||
|
if (in_list(payment_types, "Cash")) {
|
||||||
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
|
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
|
||||||
var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
|
var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
|
||||||
|
|
||||||
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total,
|
this.frm.doc.change_amount = flt(
|
||||||
precision("change_amount"));
|
this.frm.doc.paid_amount - grand_total,
|
||||||
|
precision("change_amount")
|
||||||
|
);
|
||||||
|
|
||||||
this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount -
|
this.frm.doc.base_change_amount = flt(
|
||||||
base_grand_total, precision("base_change_amount"));
|
this.frm.doc.base_paid_amount - base_grand_total,
|
||||||
|
precision("base_change_amount")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_write_off_amount() {
|
calculate_write_off_amount() {
|
||||||
if (this.frm.doc.write_off_outstanding_amount_automatically) {
|
if (this.frm.doc.write_off_outstanding_amount_automatically) {
|
||||||
this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount"));
|
this.frm.doc.write_off_amount = flt(
|
||||||
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
|
this.frm.doc.outstanding_amount,
|
||||||
precision("base_write_off_amount"));
|
precision("write_off_amount")
|
||||||
|
);
|
||||||
|
this.frm.doc.base_write_off_amount = flt(
|
||||||
|
this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
|
||||||
|
precision("base_write_off_amount")
|
||||||
|
);
|
||||||
|
|
||||||
this.calculate_outstanding_amount(false);
|
this.calculate_outstanding_amount(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filtered_items() {
|
filtered_items() {
|
||||||
return this.frm.doc.items.filter(item => !item["is_alternative"]);
|
return this.frm.doc.items.filter((item) => !item["is_alternative"]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user