mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-25 04:53:01 +00:00
fix(stock): correct secondary item valuation across stock entry purposes
Backport of five fixes merged to develop, adapted to this branch, where the field is still named `type` and the stock entry rate logic has not been split out of set_basic_rate. - A secondary row with no BOM link is costed out of the finished good, as legacy scrap was. Finished goods are rated last so a single validate pass sees the secondary rows' amounts. (#57732) - Repack no longer flags secondary rows as finished goods, so each side takes the share the BOM declares instead of the scrap absorbing the finished good's percentage. (#57735) - A BOM allocation of 0% means the row carries no cost, rather than falling through to the item's own valuation rate. (#57736) - Secondary Item Type no longer waives a quality inspection on purposes that do not produce secondary items. (#57737) - The BOM allocation applies to the consumption entry's cost when the raw material cost comes from one. (#57738) Replaces the individual backports, which could not be cherry-picked cleanly: every hunk needed rewriting against the pre-rename field and the un-refactored rate logic.
This commit is contained in:
@@ -70,9 +70,23 @@ QI_OUTGOING_PURPOSES = (
|
||||
)
|
||||
|
||||
|
||||
SECONDARY_ITEM_PURPOSES = ("Manufacture", "Repack", "Disassemble")
|
||||
|
||||
|
||||
def is_inspection_exempt_secondary_row(doc, row) -> bool:
|
||||
"""Whether the row is a secondary item on a document that produces secondary items."""
|
||||
if not (row.get("type") or row.get("is_legacy_scrap_item")):
|
||||
return False
|
||||
|
||||
if doc.doctype == "Stock Entry":
|
||||
return doc.purpose in SECONDARY_ITEM_PURPOSES
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def stock_entry_row_requires_inspection(purpose, row):
|
||||
"""Check if this Stock Entry row need a Quality Inspection."""
|
||||
if row.get("type") or row.get("is_legacy_scrap_item"):
|
||||
if purpose in SECONDARY_ITEM_PURPOSES and (row.get("type") or row.get("is_legacy_scrap_item")):
|
||||
return False
|
||||
if purpose == "Manufacture":
|
||||
return bool(row.is_finished_item)
|
||||
@@ -1604,7 +1618,7 @@ class StockController(AccountsController):
|
||||
elif self.doctype == "Stock Entry":
|
||||
qi_required = stock_entry_row_requires_inspection(self.purpose, row)
|
||||
|
||||
if row.get("type") or row.get("is_legacy_scrap_item"):
|
||||
if is_inspection_exempt_secondary_row(self, row):
|
||||
continue
|
||||
|
||||
if qi_required: # validate row only if inspection is required on item level
|
||||
|
||||
Reference in New Issue
Block a user