mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
Co-authored-by: Mihir Kandoi <kandoimihir@gmail.com>
This commit is contained in:
@@ -211,16 +211,28 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
|
|
||||||
if filters and isinstance(filters, dict):
|
if filters and isinstance(filters, dict):
|
||||||
if filters.get("customer") or filters.get("supplier"):
|
if filters.get("customer") or filters.get("supplier"):
|
||||||
|
party_type = "Customer" if filters.get("customer") else "Supplier"
|
||||||
party = filters.get("customer") or filters.get("supplier")
|
party = filters.get("customer") or filters.get("supplier")
|
||||||
|
group = "Customer Group" if filters.get("customer") else "Supplier Group"
|
||||||
item_rules_list = frappe.get_all(
|
item_rules_list = frappe.get_all(
|
||||||
"Party Specific Item",
|
"Party Specific Item",
|
||||||
filters={
|
filters={
|
||||||
"party": ["!=", party],
|
"party": ["!=", party],
|
||||||
"party_type": "Customer" if filters.get("customer") else "Supplier",
|
"party_type": party_type,
|
||||||
},
|
},
|
||||||
fields=["restrict_based_on", "based_on_value"],
|
fields=["restrict_based_on", "based_on_value"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
party_group_rules_list = frappe.get_all(
|
||||||
|
"Party Specific Item",
|
||||||
|
filters={"party_type": group},
|
||||||
|
fields=["party as party_group", "restrict_based_on", "based_on_value"],
|
||||||
|
)
|
||||||
|
current_party_group = frappe.get_value(party_type, party, frappe.scrub(group))
|
||||||
|
for rule in party_group_rules_list:
|
||||||
|
if current_party_group != rule.party_group:
|
||||||
|
item_rules_list.append(rule)
|
||||||
|
|
||||||
filters_dict = {}
|
filters_dict = {}
|
||||||
for rule in item_rules_list:
|
for rule in item_rules_list:
|
||||||
if rule["restrict_based_on"] == "Item":
|
if rule["restrict_based_on"] == "Item":
|
||||||
|
|||||||
@@ -2,6 +2,21 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on("Party Specific Item", {
|
frappe.ui.form.on("Party Specific Item", {
|
||||||
// refresh: function(frm) {
|
setup: function (frm) {
|
||||||
// }
|
frm.trigger("party_type");
|
||||||
|
},
|
||||||
|
|
||||||
|
party_type: function (frm) {
|
||||||
|
if (["Customer Group", "Supplier Group"].includes(frm.doc.party_type)) {
|
||||||
|
frm.set_query("party", function () {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
is_group: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
frm.set_query("party", null);
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
|
"allow_bulk_edit": 1,
|
||||||
"allow_import": 1,
|
"allow_import": 1,
|
||||||
"creation": "2021-08-27 19:28:07.559978",
|
"creation": "2021-08-27 19:28:07.559978",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Party Type",
|
"label": "Party Type",
|
||||||
"options": "Customer\nSupplier",
|
"options": "Customer\nCustomer Group\nSupplier\nSupplier Group",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -52,7 +53,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-03-27 13:10:08.752476",
|
"modified": "2026-05-17 11:46:17.634855",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Party Specific Item",
|
"name": "Party Specific Item",
|
||||||
@@ -71,9 +72,10 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"row_format": "Dynamic",
|
||||||
"sort_field": "creation",
|
"sort_field": "creation",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
"title_field": "party",
|
"title_field": "party",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PartySpecificItem(Document):
|
|||||||
|
|
||||||
based_on_value: DF.DynamicLink
|
based_on_value: DF.DynamicLink
|
||||||
party: DF.DynamicLink
|
party: DF.DynamicLink
|
||||||
party_type: DF.Literal["Customer", "Supplier"]
|
party_type: DF.Literal["Customer", "Customer Group", "Supplier", "Supplier Group"]
|
||||||
restrict_based_on: DF.Literal["Item", "Item Group", "Brand"]
|
restrict_based_on: DF.Literal["Item", "Item Group", "Brand"]
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,23 @@ class TestPartySpecificItem(ERPNextTestSuite):
|
|||||||
)
|
)
|
||||||
self.assertTrue(item in flatten(items))
|
self.assertTrue(item in flatten(items))
|
||||||
|
|
||||||
|
def test_party_group(self):
|
||||||
|
customer = "_Test Customer With Template"
|
||||||
|
item = "_Test Item"
|
||||||
|
frappe.set_value("Customer", customer, "customer_group", "Government")
|
||||||
|
|
||||||
|
create_party_specific_item(
|
||||||
|
party_type="Customer Group",
|
||||||
|
party="Government",
|
||||||
|
restrict_based_on="Item",
|
||||||
|
based_on_value=item,
|
||||||
|
)
|
||||||
|
filters = {"is_sales_item": 1, "customer": customer}
|
||||||
|
items = item_query(
|
||||||
|
doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters=filters, as_dict=False
|
||||||
|
)
|
||||||
|
self.assertTrue(item in flatten(items))
|
||||||
|
|
||||||
|
|
||||||
def flatten(lst):
|
def flatten(lst):
|
||||||
result = []
|
result = []
|
||||||
|
|||||||
Reference in New Issue
Block a user