Merge pull request #27281 from DeeMysterio/party-specific-items

feat: link items to supplier / customer
(cherry picked from commit aa82624f31)

# Conflicts:
#	erpnext/controllers/queries.py
#	erpnext/hr/doctype/interview_type/interview_type.json
#	erpnext/patches.txt
#	erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py
#	erpnext/selling/doctype/party_specific_item/party_specific_item.py
#	erpnext/selling/doctype/party_specific_item/test_party_specific_item.py
#	erpnext/selling/sales_common.js
#	erpnext/stock/doctype/stock_reposting_settings/test_stock_reposting_settings.py
This commit is contained in:
DeeMysterio
2021-09-14 13:58:18 +05:30
committed by Mergify
parent f5160dc83d
commit 16bd6fc265
6 changed files with 81 additions and 0 deletions

View File

@@ -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"]

View File

@@ -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

View File

@@ -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:

View File

@@ -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))

View File

@@ -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)

View File

@@ -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)
}
});
}