fix: always update item_name for stock entry (#31068)

If item_name is already set and for some reason becomes outdated then
it's not updated in backend.

Fix: always set item_name and stock_uom when fetching item details
This commit is contained in:
Ankush Menat 2022-05-19 14:25:47 +05:30 committed by GitHub
parent 1de6b14d15
commit 6d6616dbcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View File

@ -298,19 +298,17 @@ class StockEntry(StockController):
for_update=True,
)
for f in (
"uom",
"stock_uom",
"description",
"item_name",
"expense_account",
"cost_center",
"conversion_factor",
):
if f == "stock_uom" or not item.get(f):
item.set(f, item_details.get(f))
if f == "conversion_factor" and item.uom == item_details.get("stock_uom"):
item.set(f, item_details.get(f))
reset_fields = ("stock_uom", "item_name")
for field in reset_fields:
item.set(field, item_details.get(field))
update_fields = ("uom", "description", "expense_account", "cost_center", "conversion_factor")
for field in update_fields:
if not item.get(field):
item.set(field, item_details.get(field))
if field == "conversion_factor" and item.uom == item_details.get("stock_uom"):
item.set(field, item_details.get(field))
if not item.transfer_qty and item.qty:
item.transfer_qty = flt(

View File

@ -2,8 +2,6 @@
# License: GNU General Public License v3. See license.txt
import unittest
import frappe
from frappe.permissions import add_user_permission, remove_user_permission
from frappe.tests.utils import FrappeTestCase, change_settings
@ -12,6 +10,7 @@ from frappe.utils import flt, nowdate, nowtime
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.stock.doctype.item.test_item import (
create_item,
make_item,
make_item_variant,
set_item_variant_settings,
)
@ -1443,6 +1442,21 @@ class TestStockEntry(FrappeTestCase):
self.assertEqual(mapped_se.items[0].basic_rate, 100)
self.assertEqual(mapped_se.items[0].basic_amount, 200)
def test_stock_entry_item_details(self):
item = make_item()
se = make_stock_entry(
item_code=item.name, qty=1, to_warehouse="_Test Warehouse - _TC", do_not_submit=True
)
self.assertEqual(se.items[0].item_name, item.item_name)
se.items[0].item_name = "wat"
se.items[0].stock_uom = "Kg"
se.save()
self.assertEqual(se.items[0].item_name, item.item_name)
self.assertEqual(se.items[0].stock_uom, item.stock_uom)
def make_serialized_item(**args):
args = frappe._dict(args)