forked from frappe/erpnext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request frappe#27281 from DeeMysterio/party-specific-items
feat: link items to supplier / customer
- Loading branch information
1 parent
9aa6f52
commit aa82624
Showing
14 changed files
with
189 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
erpnext/buying/doctype/supplier_item_group/supplier_item_group.json
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
erpnext/buying/doctype/supplier_item_group/supplier_item_group.py
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
erpnext/buying/doctype/supplier_item_group/test_supplier_item_group.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
erpnext/patches/v13_0/replace_supplier_item_group_with_party_specific_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2019, Frappe and Contributors | ||
# License: GNU General Public License v3. See license.txt | ||
|
||
import frappe | ||
|
||
|
||
def execute(): | ||
if frappe.db.table_exists('Supplier Item Group'): | ||
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: | ||
psi = frappe.new_doc("Party Specific Item") | ||
psi.party_type = "Supplier" | ||
psi.party = item.supplier | ||
psi.restrict_based_on = "Item Group" | ||
psi.based_on_value = item.item_group | ||
psi.insert() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...upplier_item_group/supplier_item_group.js → ...arty_specific_item/party_specific_item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
erpnext/selling/doctype/party_specific_item/party_specific_item.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"actions": [], | ||
"creation": "2021-08-27 19:28:07.559978", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"party_type", | ||
"party", | ||
"column_break_3", | ||
"restrict_based_on", | ||
"based_on_value" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "party_type", | ||
"fieldtype": "Select", | ||
"in_list_view": 1, | ||
"label": "Party Type", | ||
"options": "Customer\nSupplier", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "party", | ||
"fieldtype": "Dynamic Link", | ||
"in_list_view": 1, | ||
"label": "Party Name", | ||
"options": "party_type", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "restrict_based_on", | ||
"fieldtype": "Select", | ||
"in_list_view": 1, | ||
"label": "Restrict Items Based On", | ||
"options": "Item\nItem Group\nBrand", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "column_break_3", | ||
"fieldtype": "Column Break" | ||
}, | ||
{ | ||
"fieldname": "based_on_value", | ||
"fieldtype": "Dynamic Link", | ||
"in_list_view": 1, | ||
"label": "Based On Value", | ||
"options": "restrict_based_on", | ||
"reqd": 1 | ||
} | ||
], | ||
"index_web_pages_for_search": 1, | ||
"links": [], | ||
"modified": "2021-09-14 13:27:58.612334", | ||
"modified_by": "Administrator", | ||
"module": "Selling", | ||
"name": "Party Specific Item", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"title_field": "party", | ||
"track_changes": 1 | ||
} |
19 changes: 19 additions & 0 deletions
19
erpnext/selling/doctype/party_specific_item/party_specific_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe import _ | ||
from frappe.model.document import Document | ||
|
||
|
||
class PartySpecificItem(Document): | ||
def validate(self): | ||
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, | ||
}) | ||
if exists: | ||
frappe.throw(_("This item filter has already been applied for the {0}").format(self.party_type)) |
38 changes: 38 additions & 0 deletions
38
erpnext/selling/doctype/party_specific_item/test_party_specific_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
|
||
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): | ||
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): | ||
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) | ||
for item in items: | ||
self.assertEqual(item[0], self.item.name) | ||
|
||
def test_item_query_for_supplier(self): | ||
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) | ||
for item in items: | ||
self.assertEqual(item[2], self.item.item_group) |
Oops, something went wrong.