mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-09 15:29:30 +00:00
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
This commit is contained in:
@@ -77,27 +77,28 @@ erpnext.utils.get_party_details = function (frm, method, args, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
|
const field = party_field(frm, args.party_type);
|
||||||
if (
|
const label = party_label(frm, args.party_type);
|
||||||
!erpnext.utils.validate_mandatory(
|
|
||||||
|
if (frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !args.posting_date) {
|
||||||
|
undo_and_throw(
|
||||||
frm,
|
frm,
|
||||||
__("Posting / Transaction Date"),
|
field,
|
||||||
args.posting_date,
|
__("Cannot load {0} details", [label]),
|
||||||
args.party_type == "Customer" ? "customer" : "supplier"
|
__("{0} is required to apply taxes. Set {0}, then select {1} again.", [date_label(frm), label])
|
||||||
)
|
);
|
||||||
)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!frm.doc.company) {
|
||||||
!erpnext.utils.validate_mandatory(
|
undo_and_throw(
|
||||||
frm,
|
frm,
|
||||||
__("Company"),
|
field,
|
||||||
frm.doc.company,
|
__("Cannot load {0} details", [label]),
|
||||||
args.party_type == "Customer" ? "customer" : "supplier"
|
__(
|
||||||
|
"Company is required to load address, taxes, and payment terms. Set Company, then select {0} again.",
|
||||||
|
[label]
|
||||||
)
|
)
|
||||||
) {
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.currency = frm.doc.currency;
|
args.currency = frm.doc.currency;
|
||||||
@@ -174,30 +175,34 @@ erpnext.utils.set_taxes_from_address = function (
|
|||||||
) {
|
) {
|
||||||
if (frm.updating_party_details) return;
|
if (frm.updating_party_details) return;
|
||||||
|
|
||||||
if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
|
if (!frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
|
||||||
if (
|
|
||||||
!erpnext.utils.validate_mandatory(
|
|
||||||
frm,
|
|
||||||
__("Lead / Customer / Supplier"),
|
|
||||||
frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name,
|
|
||||||
triggered_from_field
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const trigger_label = frappe.meta.get_translated_label(frm.doc.doctype, triggered_from_field);
|
||||||
!erpnext.utils.validate_mandatory(
|
|
||||||
|
if (!(frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name)) {
|
||||||
|
undo_and_throw(
|
||||||
frm,
|
frm,
|
||||||
__("Posting / Transaction Date"),
|
triggered_from_field,
|
||||||
frm.doc.posting_date || frm.doc.transaction_date,
|
__("Cannot apply taxes from this address"),
|
||||||
triggered_from_field
|
__("{0} is required to apply taxes. Set {0}, then select {1} again.", [
|
||||||
)
|
party_label(frm),
|
||||||
) {
|
trigger_label,
|
||||||
return;
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return;
|
if (!(frm.doc.posting_date || frm.doc.transaction_date)) {
|
||||||
|
undo_and_throw(
|
||||||
|
frm,
|
||||||
|
triggered_from_field,
|
||||||
|
__("Cannot apply taxes from this address"),
|
||||||
|
__("{0} is required to apply taxes. Set {0}, then select {1} again.", [
|
||||||
|
date_label(frm),
|
||||||
|
trigger_label,
|
||||||
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@@ -220,34 +225,43 @@ erpnext.utils.set_taxes_from_address = function (
|
|||||||
};
|
};
|
||||||
|
|
||||||
erpnext.utils.set_taxes = function (frm, triggered_from_field) {
|
erpnext.utils.set_taxes = function (frm, triggered_from_field) {
|
||||||
if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
|
if (!frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
|
||||||
if (!erpnext.utils.validate_mandatory(frm, __("Company"), frm.doc.company, triggered_from_field)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const trigger_label = frappe.meta.get_translated_label(frm.doc.doctype, triggered_from_field);
|
||||||
!erpnext.utils.validate_mandatory(
|
|
||||||
|
if (!frm.doc.company) {
|
||||||
|
undo_and_throw(
|
||||||
frm,
|
frm,
|
||||||
__("Lead / Customer / Supplier"),
|
triggered_from_field,
|
||||||
frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name,
|
__("Cannot apply taxes"),
|
||||||
triggered_from_field
|
__("Company is required to apply taxes. Set Company, then select {0} again.", [trigger_label])
|
||||||
)
|
);
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!(frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name)) {
|
||||||
!erpnext.utils.validate_mandatory(
|
undo_and_throw(
|
||||||
frm,
|
frm,
|
||||||
__("Posting / Transaction Date"),
|
triggered_from_field,
|
||||||
frm.doc.posting_date || frm.doc.transaction_date,
|
__("Cannot apply taxes"),
|
||||||
triggered_from_field
|
__("{0} is required to apply taxes. Set {0}, then select {1} again.", [
|
||||||
)
|
party_label(frm),
|
||||||
) {
|
trigger_label,
|
||||||
return;
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return;
|
if (!(frm.doc.posting_date || frm.doc.transaction_date)) {
|
||||||
|
undo_and_throw(
|
||||||
|
frm,
|
||||||
|
triggered_from_field,
|
||||||
|
__("Cannot apply taxes"),
|
||||||
|
__("{0} is required to apply taxes. Set {0}, then select {1} again.", [
|
||||||
|
date_label(frm),
|
||||||
|
trigger_label,
|
||||||
|
])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var party_type, party;
|
var party_type, party;
|
||||||
@@ -265,10 +279,6 @@ erpnext.utils.set_taxes = function (frm, triggered_from_field) {
|
|||||||
party = frm.doc.party_name;
|
party = frm.doc.party_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!frm.doc.company) {
|
|
||||||
frappe.throw(__("Kindly select the company first"));
|
|
||||||
}
|
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.accounts.party.set_taxes",
|
method: "erpnext.accounts.party.set_taxes",
|
||||||
args: {
|
args: {
|
||||||
@@ -337,16 +347,6 @@ function reset_contact_fields(frm) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.utils.validate_mandatory = function (frm, label, value, trigger_on) {
|
|
||||||
if (!value) {
|
|
||||||
frm.doc[trigger_on] = "";
|
|
||||||
refresh_field(trigger_on);
|
|
||||||
frappe.throw({ message: __("Please enter {0} first", [label]), title: __("Mandatory") });
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
erpnext.utils.get_shipping_address = function (frm, callback) {
|
erpnext.utils.get_shipping_address = function (frm, callback) {
|
||||||
if (frm.doc.company) {
|
if (frm.doc.company) {
|
||||||
if (
|
if (
|
||||||
@@ -379,3 +379,48 @@ erpnext.utils.get_shipping_address = function (frm, callback) {
|
|||||||
frappe.msgprint(__("Select company first"));
|
frappe.msgprint(__("Select company first"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function party_field(frm, party_type) {
|
||||||
|
if (frappe.meta.get_docfield(frm.doc.doctype, "party_name")) {
|
||||||
|
return "party_name";
|
||||||
|
}
|
||||||
|
if (party_type === "Customer") {
|
||||||
|
return "customer";
|
||||||
|
}
|
||||||
|
if (party_type === "Supplier") {
|
||||||
|
return "supplier";
|
||||||
|
}
|
||||||
|
if (party_type === "Lead") {
|
||||||
|
return "lead";
|
||||||
|
}
|
||||||
|
return ["customer", "supplier", "lead"].find((field) => frappe.meta.get_docfield(frm.doc.doctype, field));
|
||||||
|
}
|
||||||
|
|
||||||
|
function party_label(frm, party_type) {
|
||||||
|
if (frm.doc.quotation_to) {
|
||||||
|
return __(frm.doc.quotation_to);
|
||||||
|
}
|
||||||
|
return frappe.meta.get_translated_label(frm.doc.doctype, party_field(frm, party_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
function date_label(frm) {
|
||||||
|
const field = frappe.meta.get_docfield(frm.doc.doctype, "posting_date")
|
||||||
|
? "posting_date"
|
||||||
|
: "transaction_date";
|
||||||
|
return frappe.meta.get_translated_label(frm.doc.doctype, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
function undo_and_throw(frm, field, title, message) {
|
||||||
|
frm.doc[field] = "";
|
||||||
|
refresh_field(field);
|
||||||
|
frappe.throw({ title, message });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kept for custom client scripts that call this public helper.
|
||||||
|
erpnext.utils.validate_mandatory = function (frm, label, value, trigger_on) {
|
||||||
|
if (value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
undo_and_throw(frm, trigger_on, __("Mandatory"), __("Please enter {0} first", [label]));
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user