mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 07:02:54 +00:00
fix: avoid updating items table if no change due to putaway
(cherry picked from commit b000e93744)
This commit is contained in:
committed by
Ankush Menat
parent
8953794cda
commit
90f2cfd102
@@ -9,8 +9,7 @@ from collections import defaultdict
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cint, floor, flt, nowdate
|
from frappe.utils import cint, cstr, floor, flt, nowdate
|
||||||
from six import string_types
|
|
||||||
|
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
from erpnext.stock.utils import get_stock_balance
|
from erpnext.stock.utils import get_stock_balance
|
||||||
@@ -75,7 +74,7 @@ def apply_putaway_rule(doctype, items, company, sync=None, purpose=None):
|
|||||||
purpose: Purpose of Stock Entry
|
purpose: Purpose of Stock Entry
|
||||||
sync (optional): Sync with client side only for client side calls
|
sync (optional): Sync with client side only for client side calls
|
||||||
"""
|
"""
|
||||||
if isinstance(items, string_types):
|
if isinstance(items, str):
|
||||||
items = json.loads(items)
|
items = json.loads(items)
|
||||||
|
|
||||||
items_not_accomodated, updated_table = [], []
|
items_not_accomodated, updated_table = [], []
|
||||||
@@ -143,11 +142,44 @@ def apply_putaway_rule(doctype, items, company, sync=None, purpose=None):
|
|||||||
if items_not_accomodated:
|
if items_not_accomodated:
|
||||||
show_unassigned_items_message(items_not_accomodated)
|
show_unassigned_items_message(items_not_accomodated)
|
||||||
|
|
||||||
items[:] = updated_table if updated_table else items # modify items table
|
if updated_table and _items_changed(items, updated_table, doctype):
|
||||||
|
items[:] = updated_table
|
||||||
|
frappe.msgprint(_("Applied putaway rules."), alert=True)
|
||||||
|
|
||||||
if sync and json.loads(sync): # sync with client side
|
if sync and json.loads(sync): # sync with client side
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
def _items_changed(old, new, doctype: str) -> bool:
|
||||||
|
""" Check if any items changed by application of putaway rules.
|
||||||
|
|
||||||
|
If not, changing item table can have side effects since `name` items also changes.
|
||||||
|
"""
|
||||||
|
if len(old) != len(new):
|
||||||
|
return True
|
||||||
|
|
||||||
|
old = [frappe._dict(item) if isinstance(item, dict) else item for item in old]
|
||||||
|
|
||||||
|
if doctype == "Stock Entry":
|
||||||
|
compare_keys = ("item_code", "t_warehouse", "transfer_qty", "serial_no")
|
||||||
|
sort_key = lambda item: (item.item_code, cstr(item.t_warehouse), # noqa
|
||||||
|
flt(item.transfer_qty), cstr(item.serial_no))
|
||||||
|
else:
|
||||||
|
# purchase receipt / invoice
|
||||||
|
compare_keys = ("item_code", "warehouse", "stock_qty", "received_qty", "serial_no")
|
||||||
|
sort_key = lambda item: (item.item_code, cstr(item.warehouse), # noqa
|
||||||
|
flt(item.stock_qty), flt(item.received_qty), cstr(item.serial_no))
|
||||||
|
|
||||||
|
old_sorted = sorted(old, key=sort_key)
|
||||||
|
new_sorted = sorted(new, key=sort_key)
|
||||||
|
|
||||||
|
# Once sorted by all relevant keys both tables should align if they are same.
|
||||||
|
for old_item, new_item in zip(old_sorted, new_sorted):
|
||||||
|
for key in compare_keys:
|
||||||
|
if old_item.get(key) != new_item.get(key):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_ordered_putaway_rules(item_code, company, source_warehouse=None):
|
def get_ordered_putaway_rules(item_code, company, source_warehouse=None):
|
||||||
"""Returns an ordered list of putaway rules to apply on an item."""
|
"""Returns an ordered list of putaway rules to apply on an item."""
|
||||||
filters = {
|
filters = {
|
||||||
|
|||||||
Reference in New Issue
Block a user