mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
Merge pull request #55519 from frappe/mergify/bp/version-16-hotfix/pr-55415
fix(stock): allow to create quality inspection after purchase/delivery (backport #55415)
This commit is contained in:
@@ -2112,7 +2112,7 @@ def repost_required_for_queue(doc: StockController) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def check_item_quality_inspection(doctype, items):
|
def check_item_quality_inspection(doctype: str, docstatus: str | int, items: str | list[dict]):
|
||||||
if isinstance(items, str):
|
if isinstance(items, str):
|
||||||
items = json.loads(items)
|
items = json.loads(items)
|
||||||
|
|
||||||
@@ -2124,14 +2124,31 @@ def check_item_quality_inspection(doctype, items):
|
|||||||
"Delivery Note": "inspection_required_before_delivery",
|
"Delivery Note": "inspection_required_before_delivery",
|
||||||
}
|
}
|
||||||
|
|
||||||
items_to_remove = []
|
inspection_fieldname = inspection_fieldname_map.get(doctype)
|
||||||
for item in items:
|
if inspection_fieldname is None:
|
||||||
if not frappe.db.get_value("Item", item.get("item_code"), inspection_fieldname_map.get(doctype)):
|
return []
|
||||||
items_to_remove.append(item)
|
|
||||||
items = [item for item in items if item not in items_to_remove]
|
|
||||||
|
|
||||||
|
allow_after_transaction = cint(docstatus) == 1 and frappe.get_single_value(
|
||||||
|
"Stock Settings", "allow_to_make_quality_inspection_after_purchase_or_delivery"
|
||||||
|
)
|
||||||
|
|
||||||
|
if allow_after_transaction:
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
item_codes = list({item.get("item_code") for item in items})
|
||||||
|
|
||||||
|
Item = frappe.qb.DocType("Item")
|
||||||
|
results = (
|
||||||
|
frappe.qb.from_(Item)
|
||||||
|
.select(Item.name)
|
||||||
|
.where((Item.name.isin(item_codes)) & (Item[inspection_fieldname] == 1))
|
||||||
|
.run(as_dict=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
inspection_required_items = {row.name for row in results}
|
||||||
|
|
||||||
|
return [item for item in items if item.get("item_code") in inspection_required_items]
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_quality_inspections(
|
def make_quality_inspections(
|
||||||
|
|||||||
@@ -2929,10 +2929,28 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
method: "erpnext.controllers.stock_controller.check_item_quality_inspection",
|
method: "erpnext.controllers.stock_controller.check_item_quality_inspection",
|
||||||
args: {
|
args: {
|
||||||
doctype: this.frm.doc.doctype,
|
doctype: this.frm.doc.doctype,
|
||||||
|
docstatus: this.frm.doc.docstatus,
|
||||||
items: this.frm.doc.items,
|
items: this.frm.doc.items,
|
||||||
},
|
},
|
||||||
freeze: true,
|
freeze: true,
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
|
if (r.message.length == 0) {
|
||||||
|
let type = inspection_type === "Incoming" ? "Purchase" : "Delivery";
|
||||||
|
let fieldname =
|
||||||
|
inspection_type === "Incoming"
|
||||||
|
? "Inspection Required before Purchase"
|
||||||
|
: "Inspection Required before Delivery";
|
||||||
|
|
||||||
|
frappe.msgprint({
|
||||||
|
title: __("Quality Inspection Not Configured"),
|
||||||
|
message: __(`Enable <b>{0}</b> on the Item master to proceed with {1} inspection.`, [
|
||||||
|
fieldname,
|
||||||
|
type,
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
r.message.forEach((item) => {
|
r.message.forEach((item) => {
|
||||||
if (me.has_inspection_required(item)) {
|
if (me.has_inspection_required(item)) {
|
||||||
let dialog_items = dialog.fields_dict.items;
|
let dialog_items = dialog.fields_dict.items;
|
||||||
|
|||||||
Reference in New Issue
Block a user