Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter project by customer #38934

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e

if (this.frm.doc.__onload && this.frm.doc.__onload.load_after_mapping) return;

super.customer();

erpnext.utils.get_party_details(this.frm,
"erpnext.accounts.party.get_party_details", {
posting_date: this.frm.doc.posting_date,
Expand Down
10 changes: 9 additions & 1 deletion erpnext/controllers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters):

fields = get_fields(doctype, ["name", "project_name"])
searchfields = frappe.get_meta(doctype).get_search_fields()
searchfields = " or ".join(["`tabProject`." + field + " like %(txt)s" for field in searchfields])
searchfields = (
"(" + " or ".join(["`tabProject`." + field + " like %(txt)s" for field in searchfields]) + ")"
)

return frappe.db.sql(
"""select {fields} from `tabProject`
Expand Down Expand Up @@ -656,6 +658,12 @@ def get_filtered_dimensions(
if meta.has_field("disabled"):
query_filters.append(["disabled", "!=", 1])

if meta.has_field("is_active"):
query_filters.append(["is_active", "!=", "No"])

if meta.has_field("status"):
query_filters.append(["status", "not in", ["Completed", "Cancelled"]])

if meta.has_field("company"):
query_filters.append(["company", "=", filters.get("company")])

Expand Down
12 changes: 12 additions & 0 deletions erpnext/public/js/controllers/buying.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ erpnext.buying = {
}

project(doc, cdt, cdn) {
let me = this;
if (this.frm.doc.project) {
frappe.call({
method: 'erpnext.projects.doctype.project.project.get_cost_center_name',
args: { project: this.frm.doc.project },
callback: function (r, rt) {
if (!r.exc) {
frappe.model.set_value(me.frm.doc.doctype, me.frm.doc.name, "cost_center", r.message);
}
}
})
}
var item = frappe.get_doc(cdt, cdn);
if(item.project) {
$.each(this.frm.doc["items"] || [],
Expand Down
15 changes: 15 additions & 0 deletions erpnext/public/js/controllers/stock_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
}
}

project(doc, cdt, cdn) {
let me = this;
if (this.frm.doc.project) {
frappe.call({
method: 'erpnext.projects.doctype.project.project.get_cost_center_name',
args: { project: this.frm.doc.project },
callback: function (r, rt) {
if (!r.exc) {
frappe.model.set_value(me.frm.doc.doctype, me.frm.doc.name, "cost_center", r.message);
}
}
})
}
}

setup_warehouse_query() {
var me = this;
erpnext.queries.setup_queries(this.frm, "Warehouse", function() {
Expand Down
13 changes: 13 additions & 0 deletions erpnext/public/js/utils/sales_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ erpnext.sales_common = {

customer() {
var me = this;
this.frm.set_query('project', function (doc) {
return {
query: "erpnext.controllers.queries.get_project_name",
filters: {
'customer': doc.customer
}
}
});
erpnext.utils.get_party_details(this.frm, null, null, function() {
me.apply_price_list();
});
Expand Down Expand Up @@ -368,6 +376,11 @@ erpnext.sales_common = {
args: {project: this.frm.doc.project},
callback: function(r, rt) {
if(!r.exc) {
frappe.model.set_value(me.frm.doc.doctype, me.frm.doc.name, "cost_center", r.message);

// is this really necessary? would it make more sense to invoke this on change of cost centre instead?
// would it make sense to set project on each row also?
// should something similar be done on the purchase side of things too?
$.each(me.frm.doc["items"] || [], function(i, row) {
if(r.message) {
frappe.model.set_value(row.doctype, row.name, "cost_center", r.message);
Expand Down
17 changes: 9 additions & 8 deletions erpnext/selling/doctype/sales_order/sales_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,15 @@ frappe.ui.form.on("Sales Order", {
};
});

frm.set_query('project', function(doc, cdt, cdn) {
return {
query: "erpnext.controllers.queries.get_project_name",
filters: {
'customer': doc.customer
}
}
});
// this doesn't do anything. is it ok to remove?
// frm.set_query('project', function(doc, cdt, cdn) {
// return {
// query: "erpnext.controllers.queries.get_project_name",
// filters: {
// 'customer': doc.customer
// }
// }
// });

frm.set_query('warehouse', 'items', function(doc, cdt, cdn) {
let row = locals[cdt][cdn];
Expand Down
Loading