diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index e39ef9d8e40..074d2737340 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -235,6 +235,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals searchfields = " or ".join([field + " like %(txt)s" for field in searchfields]) if filters and isinstance(filters, dict): +<<<<<<< HEAD if filters.get("customer") or filters.get("supplier"): party = filters.get("customer") or filters.get("supplier") item_rules_list = frappe.get_all( @@ -245,13 +246,36 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals for rule in item_rules_list: if rule["restrict_based_on"] == "Item": rule["restrict_based_on"] = "name" +======= + if filters.get('customer') or filters.get('supplier'): + party = filters.get('customer') or filters.get('supplier') + item_rules_list = frappe.get_all('Party Specific Item', + filters = {'party': party}, fields = ['restrict_based_on', 'based_on_value']) + + filters_dict = {} + for rule in item_rules_list: + if rule['restrict_based_on'] == 'Item': + rule['restrict_based_on'] = 'name' +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) filters_dict[rule.restrict_based_on] = [] for rule in item_rules_list: filters_dict[rule.restrict_based_on].append(rule.based_on_value) +<<<<<<< HEAD for filter in filters_dict: filters[scrub(filter)] = ["in", filters_dict[filter]] +======= + + for filter in filters_dict: + filters[scrub(filter)] = ['in', filters_dict[filter]] + + if filters.get('customer'): + del filters['customer'] + else: + del filters['supplier'] + +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) if filters.get("customer"): del filters["customer"] diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e81892bd14f..f18f9f56ac9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -311,9 +311,16 @@ execute:frappe.reload_doc("erpnext_integrations", "doctype", "TaxJar Settings") execute:frappe.reload_doc("erpnext_integrations", "doctype", "Product Tax Category") erpnext.patches.v13_0.custom_fields_for_taxjar_integration #08-11-2021 erpnext.patches.v13_0.set_operation_time_based_on_operating_cost +<<<<<<< HEAD erpnext.patches.v13_0.create_website_items #30-09-2021 erpnext.patches.v13_0.populate_e_commerce_settings erpnext.patches.v13_0.make_homepage_products_website_items +======= +erpnext.patches.v13_0.validate_options_for_data_field +erpnext.patches.v13_0.create_gst_payment_entry_fields +erpnext.patches.v14_0.delete_shopify_doctypes +erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) erpnext.patches.v13_0.update_dates_in_tax_withholding_category erpnext.patches.v13_0.fix_invoice_statuses erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item diff --git a/erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py b/erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py index bf82f443082..15c6acda626 100644 --- a/erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py +++ b/erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py @@ -5,7 +5,11 @@ import frappe def execute(): +<<<<<<< HEAD if frappe.db.table_exists("Supplier Item Group"): +======= + if frappe.db.table_exists('Supplier Item Group'): +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) frappe.reload_doc("selling", "doctype", "party_specific_item") sig = frappe.db.get_all("Supplier Item Group", fields=["name", "supplier", "item_group"]) for item in sig: diff --git a/erpnext/selling/doctype/party_specific_item/party_specific_item.py b/erpnext/selling/doctype/party_specific_item/party_specific_item.py index 0aef7d362e4..28000c6e540 100644 --- a/erpnext/selling/doctype/party_specific_item/party_specific_item.py +++ b/erpnext/selling/doctype/party_specific_item/party_specific_item.py @@ -8,6 +8,7 @@ from frappe.model.document import Document class PartySpecificItem(Document): def validate(self): +<<<<<<< HEAD exists = frappe.db.exists( { "doctype": "Party Specific Item", @@ -17,5 +18,14 @@ class PartySpecificItem(Document): "based_on": self.based_on_value, } ) +======= + exists = frappe.db.exists({ + 'doctype': 'Party Specific Item', + 'party_type': self.party_type, + 'party': self.party, + 'restrict_based_on': self.restrict_based_on, + 'based_on': self.based_on_value, + }) +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) if exists: frappe.throw(_("This item filter has already been applied for the {0}").format(self.party_type)) diff --git a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py index f98cbd7e9a3..b24f62977a7 100644 --- a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py +++ b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py @@ -1,6 +1,7 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt +<<<<<<< HEAD import frappe from frappe.tests.utils import FrappeTestCase @@ -19,12 +20,32 @@ def create_party_specific_item(**args): class TestPartySpecificItem(FrappeTestCase): +======= +import unittest + +import frappe + +from erpnext.controllers.queries import item_query + +test_dependencies = ['Item', 'Customer', 'Supplier'] + +def create_party_specific_item(**args): + psi = frappe.new_doc("Party Specific Item") + psi.party_type = args.get('party_type') + psi.party = args.get('party') + psi.restrict_based_on = args.get('restrict_based_on') + psi.based_on_value = args.get('based_on_value') + psi.insert() + +class TestPartySpecificItem(unittest.TestCase): +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) def setUp(self): self.customer = frappe.get_last_doc("Customer") self.supplier = frappe.get_last_doc("Supplier") self.item = frappe.get_last_doc("Item") def test_item_query_for_customer(self): +<<<<<<< HEAD create_party_specific_item( party_type="Customer", party=self.customer.name, @@ -35,10 +56,16 @@ class TestPartySpecificItem(FrappeTestCase): items = item_query( doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters=filters, as_dict=False ) +======= + create_party_specific_item(party_type='Customer', party=self.customer.name, restrict_based_on='Item', based_on_value=self.item.name) + filters = {'is_sales_item': 1, 'customer': self.customer.name} + items = item_query(doctype= 'Item', txt= '', searchfield= 'name', start= 0, page_len= 20,filters=filters, as_dict= False) +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) for item in items: self.assertEqual(item[0], self.item.name) def test_item_query_for_supplier(self): +<<<<<<< HEAD create_party_specific_item( party_type="Supplier", party=self.supplier.name, @@ -49,5 +76,10 @@ class TestPartySpecificItem(FrappeTestCase): items = item_query( doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters=filters, as_dict=False ) +======= + create_party_specific_item(party_type='Supplier', party=self.supplier.name, restrict_based_on='Item Group', based_on_value=self.item.item_group) + filters = {'supplier': self.supplier.name, 'is_purchase_item': 1} + items = item_query(doctype= 'Item', txt= '', searchfield= 'name', start= 0, page_len= 20,filters=filters, as_dict= False) +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) for item in items: self.assertEqual(item[2], self.item.item_group) diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index f4e5f8a37f7..00cd8ef4186 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -63,7 +63,11 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.frm.set_query("item_code", "items", function() { return { query: "erpnext.controllers.queries.item_query", +<<<<<<< HEAD filters: {'is_sales_item': 1, 'customer': cur_frm.doc.customer, 'has_variants': 0} +======= + filters: {'is_sales_item': 1, 'customer': cur_frm.doc.customer} +>>>>>>> aa82624f31 (Merge pull request #27281 from DeeMysterio/party-specific-items) } }); }