mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 17:04:47 +00:00
refactor(Sales Invoice): queries
This commit is contained in:
@@ -596,49 +596,6 @@ cur_frm.cscript["Make Delivery Note"] = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
cur_frm.fields_dict.cash_bank_account.get_query = function (doc) {
|
|
||||||
return {
|
|
||||||
filters: [
|
|
||||||
["Account", "account_type", "in", ["Cash", "Bank"]],
|
|
||||||
["Account", "root_type", "=", "Asset"],
|
|
||||||
["Account", "is_group", "=", 0],
|
|
||||||
["Account", "company", "=", doc.company],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
cur_frm.fields_dict.write_off_account.get_query = function (doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
report_type: "Profit and Loss",
|
|
||||||
is_group: 0,
|
|
||||||
company: doc.company,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Write off cost center
|
|
||||||
//-----------------------
|
|
||||||
cur_frm.fields_dict.write_off_cost_center.get_query = function (doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
is_group: 0,
|
|
||||||
company: doc.company,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cost Center in Details Table
|
|
||||||
// -----------------------------
|
|
||||||
cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function (doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: doc.company,
|
|
||||||
is_group: 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
cur_frm.cscript.income_account = function (doc, cdt, cdn) {
|
cur_frm.cscript.income_account = function (doc, cdt, cdn) {
|
||||||
erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "income_account");
|
erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "income_account");
|
||||||
};
|
};
|
||||||
@@ -651,28 +608,6 @@ cur_frm.cscript.cost_center = function (doc, cdt, cdn) {
|
|||||||
erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "cost_center");
|
erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "cost_center");
|
||||||
};
|
};
|
||||||
|
|
||||||
cur_frm.set_query("debit_to", function (doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
account_type: "Receivable",
|
|
||||||
is_group: 0,
|
|
||||||
company: doc.company,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
cur_frm.set_query("asset", "items", function (doc, cdt, cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
return {
|
|
||||||
filters: [
|
|
||||||
["Asset", "item_code", "=", d.item_code],
|
|
||||||
["Asset", "docstatus", "=", 1],
|
|
||||||
["Asset", "status", "in", ["Submitted", "Partially Depreciated", "Fully Depreciated"]],
|
|
||||||
["Asset", "company", "=", doc.company],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
frappe.ui.form.on("Sales Invoice", {
|
frappe.ui.form.on("Sales Invoice", {
|
||||||
setup: function (frm) {
|
setup: function (frm) {
|
||||||
frm.add_fetch("customer", "tax_id", "tax_id");
|
frm.add_fetch("customer", "tax_id", "tax_id");
|
||||||
@@ -682,71 +617,132 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
frm.set_df_property("packed_items", "cannot_add_rows", true);
|
frm.set_df_property("packed_items", "cannot_add_rows", true);
|
||||||
frm.set_df_property("packed_items", "cannot_delete_rows", true);
|
frm.set_df_property("packed_items", "cannot_delete_rows", true);
|
||||||
|
|
||||||
frm.set_query("account_for_change_amount", function () {
|
frm.set_query("cash_bank_account", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: [
|
||||||
|
["Account", "account_type", "in", ["Cash", "Bank"]],
|
||||||
|
["Account", "root_type", "=", "Asset"],
|
||||||
|
["Account", "is_group", "=", 0],
|
||||||
|
["Account", "company", "=", doc.company],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("write_off_account", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
account_type: ["in", ["Cash", "Bank"]],
|
report_type: "Profit and Loss",
|
||||||
company: frm.doc.company,
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("write_off_cost_center", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("cost_center", "items", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
company: doc.company,
|
||||||
is_group: 0,
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("unrealized_profit_loss_account", function () {
|
frm.set_query("debit_to", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
account_type: "Receivable",
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("asset", "items", function (doc, cdt, cdn) {
|
||||||
|
const row = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: [
|
||||||
|
["Asset", "item_code", "=", row.item_code],
|
||||||
|
["Asset", "docstatus", "=", 1],
|
||||||
|
["Asset", "status", "in", ["Submitted", "Partially Depreciated", "Fully Depreciated"]],
|
||||||
|
["Asset", "company", "=", doc.company],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("account_for_change_amount", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
account_type: ["in", ["Cash", "Bank"]],
|
||||||
|
company: doc.company,
|
||||||
|
is_group: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("unrealized_profit_loss_account", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
company: doc.company,
|
||||||
is_group: 0,
|
is_group: 0,
|
||||||
root_type: "Liability",
|
root_type: "Liability",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("adjustment_against", function () {
|
frm.set_query("adjustment_against", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: doc.company,
|
||||||
customer: frm.doc.customer,
|
customer: doc.customer,
|
||||||
docstatus: 1,
|
docstatus: 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("additional_discount_account", function () {
|
frm.set_query("additional_discount_account", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: doc.company,
|
||||||
is_group: 0,
|
is_group: 0,
|
||||||
report_type: "Profit and Loss",
|
report_type: "Profit and Loss",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("income_account", "items", function () {
|
frm.set_query("income_account", "items", function (doc) {
|
||||||
return {
|
return {
|
||||||
query: "erpnext.controllers.queries.get_income_account",
|
query: "erpnext.controllers.queries.get_income_account",
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: doc.company,
|
||||||
disabled: 0,
|
disabled: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
(frm.custom_make_buttons = {
|
frm.custom_make_buttons = {
|
||||||
"Delivery Note": "Delivery",
|
"Delivery Note": "Delivery",
|
||||||
"Sales Invoice": "Return / Credit Note",
|
"Sales Invoice": "Return / Credit Note",
|
||||||
"Payment Request": "Payment Request",
|
"Payment Request": "Payment Request",
|
||||||
"Payment Entry": "Payment",
|
"Payment Entry": "Payment",
|
||||||
}),
|
};
|
||||||
(frm.fields_dict["timesheets"].grid.get_field("time_sheet").get_query = function (doc, cdt, cdn) {
|
|
||||||
return {
|
|
||||||
query: "erpnext.projects.doctype.timesheet.timesheet.get_timesheet",
|
|
||||||
filters: { project: doc.project },
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// discount account
|
frm.set_query("time_sheet", "timesheets", function (doc, cdt, cdn) {
|
||||||
frm.fields_dict["items"].grid.get_field("discount_account").get_query = function (doc) {
|
return {
|
||||||
|
query: "erpnext.projects.doctype.timesheet.timesheet.get_timesheet",
|
||||||
|
filters: { project: doc.project },
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("discount_account", "items", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
report_type: "Profit and Loss",
|
report_type: "Profit and Loss",
|
||||||
@@ -754,9 +750,9 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
is_group: 0,
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
frm.fields_dict["items"].grid.get_field("deferred_revenue_account").get_query = function (doc) {
|
frm.set_query("deferred_revenue_account", "items", function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
root_type: "Liability",
|
root_type: "Liability",
|
||||||
@@ -764,7 +760,7 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
is_group: 0,
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
frm.set_query("company_address", function (doc) {
|
frm.set_query("company_address", function (doc) {
|
||||||
if (!doc.company) {
|
if (!doc.company) {
|
||||||
@@ -793,25 +789,23 @@ frappe.ui.form.on("Sales Invoice", {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// set get_query for loyalty redemption account
|
frm.set_query("loyalty_redemption_account", function () {
|
||||||
frm.fields_dict["loyalty_redemption_account"].get_query = function () {
|
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
is_group: 0,
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
// set get_query for loyalty redemption cost center
|
frm.set_query("loyalty_redemption_cost_center", function () {
|
||||||
frm.fields_dict["loyalty_redemption_cost_center"].get_query = function () {
|
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
is_group: 0,
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
},
|
},
|
||||||
// When multiple companies are set up. in case company name is changed set default company address
|
// When multiple companies are set up. in case company name is changed set default company address
|
||||||
company: function (frm) {
|
company: function (frm) {
|
||||||
|
|||||||
Reference in New Issue
Block a user