Merge pull request #34189 from rohitwaghchaure/prevent-to-make-item-price-for-template
fix: user shouldn't able to make item price for item template
This commit is contained in:
commit
670304fe8e
@ -2,7 +2,18 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
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
|
||||
frm.add_fetch("price_list", "buying", "buying");
|
||||
frm.add_fetch("price_list", "selling", "selling");
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe import _, bold
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import Cast_
|
||||
@ -21,6 +21,7 @@ class ItemPrice(Document):
|
||||
self.update_price_list_details()
|
||||
self.update_item_details()
|
||||
self.check_duplicates()
|
||||
self.validate_item_template()
|
||||
|
||||
def validate_item(self):
|
||||
if not frappe.db.exists("Item", self.item_code):
|
||||
@ -49,6 +50,12 @@ class ItemPrice(Document):
|
||||
"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):
|
||||
|
||||
item_price = frappe.qb.DocType("Item Price")
|
||||
|
@ -16,6 +16,28 @@ class TestItemPrice(FrappeTestCase):
|
||||
frappe.db.sql("delete from `tabItem Price`")
|
||||
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):
|
||||
doc = frappe.copy_doc(test_records[0])
|
||||
self.assertRaises(ItemPriceDuplicateItem, doc.save)
|
||||
|
Loading…
x
Reference in New Issue
Block a user