Merge pull request #32205 from s-aga-r/fix/issue/31557

fix: unknown column error while updating value of maintain-stock in item master
This commit is contained in:
Sagar Sharma 2022-09-14 08:14:21 +05:30 committed by GitHub
commit 444fda5d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -945,7 +945,12 @@ class Item(Document):
if doctype == "Product Bundle":
filters = {"new_item_code": self.name}
if doctype in (
if linked_doc := frappe.db.get_value(
doctype, filters, ["new_item_code as docname"], as_dict=True
):
return linked_doc.update({"doctype": doctype})
elif doctype in (
"Purchase Invoice Item",
"Sales Invoice Item",
):

View File

@ -786,6 +786,36 @@ class TestItem(FrappeTestCase):
item.save()
self.assertTrue(len(item.customer_code) > 140)
def test_update_is_stock_item(self):
# Step - 1: Create an Item with Maintain Stock enabled
item = make_item(properties={"is_stock_item": 1})
# Step - 2: Disable Maintain Stock
item.is_stock_item = 0
item.save()
item.reload()
self.assertEqual(item.is_stock_item, 0)
# Step - 3: Create Product Bundle
pb = frappe.new_doc("Product Bundle")
pb.new_item_code = item.name
pb.flags.ignore_mandatory = True
pb.save()
# Step - 4: Try to enable Maintain Stock, should throw a validation error
item.is_stock_item = 1
self.assertRaises(frappe.ValidationError, item.save)
item.reload()
# Step - 5: Delete Product Bundle
pb.delete()
# Step - 6: Again try to enable Maintain Stock
item.is_stock_item = 1
item.save()
item.reload()
self.assertEqual(item.is_stock_item, 1)
def set_item_variant_settings(fields):
doc = frappe.get_doc("Item Variant Settings")