mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-21 02:16:28 +00:00
fix: user shouldn't able to make item price for item template
(cherry picked from commit 6417ae0ee8)
This commit is contained in:
committed by
Mergify
parent
b2582c56b7
commit
fb8e45d3d9
@@ -2,7 +2,18 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.ui.form.on("Item Price", {
|
frappe.ui.form.on("Item Price", {
|
||||||
onload: function (frm) {
|
setup(frm) {
|
||||||
|
frm.set_query("item_code", function() {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
"disabled": 0,
|
||||||
|
"has_variants": 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onload(frm) {
|
||||||
// Fetch price list details
|
// Fetch price list details
|
||||||
frm.add_fetch("price_list", "buying", "buying");
|
frm.add_fetch("price_list", "buying", "buying");
|
||||||
frm.add_fetch("price_list", "selling", "selling");
|
frm.add_fetch("price_list", "selling", "selling");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _, bold
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.query_builder import Criterion
|
from frappe.query_builder import Criterion
|
||||||
from frappe.query_builder.functions import Cast_
|
from frappe.query_builder.functions import Cast_
|
||||||
@@ -21,6 +21,7 @@ class ItemPrice(Document):
|
|||||||
self.update_price_list_details()
|
self.update_price_list_details()
|
||||||
self.update_item_details()
|
self.update_item_details()
|
||||||
self.check_duplicates()
|
self.check_duplicates()
|
||||||
|
self.validate_item_template()
|
||||||
|
|
||||||
def validate_item(self):
|
def validate_item(self):
|
||||||
if not frappe.db.exists("Item", self.item_code):
|
if not frappe.db.exists("Item", self.item_code):
|
||||||
@@ -49,6 +50,12 @@ class ItemPrice(Document):
|
|||||||
"Item", self.item_code, ["item_name", "description"]
|
"Item", self.item_code, ["item_name", "description"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_item_template(self):
|
||||||
|
if frappe.get_cached_value("Item", self.item_code, "has_variants"):
|
||||||
|
msg = f"Item Price cannot be created for the template item {bold(self.item_code)}"
|
||||||
|
|
||||||
|
frappe.throw(_(msg))
|
||||||
|
|
||||||
def check_duplicates(self):
|
def check_duplicates(self):
|
||||||
|
|
||||||
item_price = frappe.qb.DocType("Item Price")
|
item_price = frappe.qb.DocType("Item Price")
|
||||||
|
|||||||
@@ -16,6 +16,28 @@ class TestItemPrice(FrappeTestCase):
|
|||||||
frappe.db.sql("delete from `tabItem Price`")
|
frappe.db.sql("delete from `tabItem Price`")
|
||||||
make_test_records_for_doctype("Item Price", force=True)
|
make_test_records_for_doctype("Item Price", force=True)
|
||||||
|
|
||||||
|
def test_template_item_price(self):
|
||||||
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
|
||||||
|
item = make_item(
|
||||||
|
"Test Template Item 1",
|
||||||
|
{
|
||||||
|
"has_variants": 1,
|
||||||
|
"variant_based_on": "Manufacturer",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
doc = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Item Price",
|
||||||
|
"price_list": "_Test Price List",
|
||||||
|
"item_code": item.name,
|
||||||
|
"price_list_rate": 100,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertRaises(frappe.ValidationError, doc.save)
|
||||||
|
|
||||||
def test_duplicate_item(self):
|
def test_duplicate_item(self):
|
||||||
doc = frappe.copy_doc(test_records[0])
|
doc = frappe.copy_doc(test_records[0])
|
||||||
self.assertRaises(ItemPriceDuplicateItem, doc.save)
|
self.assertRaises(ItemPriceDuplicateItem, doc.save)
|
||||||
|
|||||||
Reference in New Issue
Block a user